• FreshTomato with ZeroTier

    First, a quick breakdown for the tl;dr crowd:

    1. Flash your router with FreshTomato

    2. Partition & Format USB thumbdrive

    3. Under Administration>Scripts>Init mount thumbdrive to /opt and modprobe/start tun

    4. Install Entware

    5. Create ‘mount.autorun’ & ‘unmount.autostop’ scripts for starting/stopping Entware services

    6. Install ZeroTier on router and join network

    7. Create script to start on boot

    Quick Notes:

    1. DO NOT format your usb thumbdrive with FAT32, symlinks don’t work with FAT32 and you will get errors.

    2. DO NOT try to install everything from Tools>System Commands, you will get errors. Use SSH instead.

    Ok, let’s get started…

    Step 1. Install FreshTomato on Router

    It is assumed you already have FreshTomato installed on your device. If you don’t, please go to https://freshtomato.org/ and download and install. Instructions for this is beyond the scope of this guide. Do a quick search and you will find there are plenty of resources to help you with this part. At the time of this writing, and for this guide, FreshTomato Version 2022.6 is the most recent and is installed on a Netgear R6400v2. Most likely any router running FreshTomato v2022.6 or newer will work.

    You will need a USB thumbdrive. After installing Entware and ZeroTier approximately 119MB was used, so anything 1GB or bigger should be plenty. A 32GB MicroSD card was used with a USB2.0 adapter for the install in this guide. Faster is better, if your drive is old and slow you may get errors. USB3.0 is fine but keep in mind some people have reported interference from USB3.0 devices that may effect your wireless LAN.

    Step 2a. Setting up your router for USB access:

    On your FreshTomato admin panel (found at http://192.168.1.1 by default) navigate to “USB and NAS > USB Support” and make sure to check the following

    ☑️Core USB Support

    ☑️USB 3.0 Support

    ☑️USB 2.0 Support

    ☑️USB Storage Support

    File Systems Support: (select as needed)

    ☑️Ext2/Ext3/Ext4 (recommended)

    ☑️NTFS

    !! Be sure to click save at the bottom of the page before moving on.

    Now insert your USB thumbdrive into your router. Make sure there are no other USB devices plugged in to the router. You may need to reboot the router for it to recognize the USB device.

    Step 2b. Preparing your thumbdrive for Entware:

    It is assumed you already have SSH installed on your PC, open up a terminal (linux) or command prompt (windows) and issue the following command:

    ssh root@192.168.1.1

    You may get a warning about authenticity and if you want to continue, type ‘yes’ and hit enter.

    Enter your password at the prompt. Your password should be the same as the one you used to log in to the router.

    Now enter the command ‘fdisk -l

    Several entries may scroll by, what you are looking for is ‘Disk /dev/sda’

    You can see in the image above a Disk /dev/sda of 29 GB and then 2 partitions, this is the USB thumbdrive, your device may be of a different size. Make sure you do not have any other USB devices attached to your router. If you do not see an entry for /dev/sda then your router is not recognizing your device.

    Create Entware Partition

    We will now create a new partition table and partition(s).

    !WARNING! The following instructions will erase EVERYTHING on your thumbdrive.

    Enter ‘fdisk /dev/sda’ at the prompt, then entering ‘m’ will show your command actions.

    Enter the following in order, pressing enter after each entry:

    o [enter] (that is an o, not a zero) (this will create a new partition table)

    n [enter] (to create a new partition in the new table)

    p [enter] (for primary partition type)

    1 [enter] (for first partition)

    [enter] (press enter to accept default first sector)

    [enter] (press enter again to accept default unless you want to add additional partitions)

    When finished you can enter ‘p’ to print out your partition table.

    If you are happy with what you see, enter ‘w’ to write the partition table.

    After writing the partition table fdisk will exit, leaving you back at the command prompt.

    Format Entware Partition

    At the command prompt enter the following command and press enter:

    /usr/sbin/mkfs.ext4 -L ENTWARE -O^metadata_csum /dev/sda1

    This will format the partition as Ext4 and give it the label ‘ENTWARE’. While other filetypes may work it is recommended to use Ext4 for best results. In any case DO NOT use FAT32, it will cause errors due to inability to work with symlinks.

    Now we need to tell the router to mount the new partition at boot time.

    At the command prompt enter ‘/sbin/blkid’, this will give you the UUID of the Entware partition.

    Your UUID is unique and will be different than the one you see in the image above. Copy your UUID to the clipboard or text file.

    3. Add Init Scripts to FreshTomato

    Now go to your FreshTomoato admin console and navigate to ‘Administration>Scripts’, make sure the ‘Init’ tab is selected and add the following line in the textbox using your unique UUID.

    echo ‘UUID=01234567-89ab-cdef-0123-456789abcdef /opt ext4 rw,noatime 0 2’ >>/etc/fstab

    While we are here, lets enter the following line as well, it enables the tun module which is necessary for ZeroTier work properly:

    [ $(lsmod | grep “tun” | wc -l) -eq 0 ] && modprobe tun

    Click ‘Save’ at the bottom of the page and then reboot the router.

    Verify Entware Partition is mounted

    When the router boots back up navigate to ‘USB and NAS>USB Support’ page of the admin console and make sure that your device is listed under Attached Devices showing the Entware partition mounted under /opt

    4. Install Entware

    Start another SSH session and enter the following command:

    /usr/bin/wget -O- http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh

    Hopefully all goes well and you don’t get any errors, now reboot the router again.
    Verify Entware Installation
    After reboot, SSH into the router again and enter the command ‘opkg list’. You should see a list of possible packages scroll down your terminal, if not, something is wrong. Do not proceed until you have a working Entware installation.

    5. Starting Entware service automatically on boot

    SSH into the router and enter ‘opkg install nano’. This will install nano, which is a text editor that we will use to write some scripts. After it’s finished installing,
    enter ‘nano /opt/mount.autorun‘. Then enter the following text:

    #!/bin/sh
    
    /usr/bin/logger -t Entware "Starting Entware services..."
    
    if [ -x /opt/etc/init.d/rc.unslung ]; then
      if /opt/etc/init.d/rc.unslung start; then
        /usr/bin/logger -t Entware "Successfully finished starting Entware services."
      else
        /usr/bin/logger -t Entware "ERROR: Unable to start Entware services."
      fi
    fi
    
    exit 0
    

    Press ctrl+o then ctrl+x to save and exit the editor. Now enter the following to make it executable:

    /bin/chmod 0755 /opt/mount.autorun

    Now lets repeat the process for our shutdown script.

    Enter ‘nano /opt/unmount.autostop’ and insert the following text:

    #!/bin/sh
    
    if [ -x /opt/etc/init.d/rc.unslung ]; then
      /opt/etc/init.d/rc.unslung stop
    fi
    
    /bin/umount /opt || { /bin/umount -l /opt; sleep 10; }
    
    exit 0

    Press ctrl+o then ctrl+x to save and exit the editor. And make the script executable with:

    /bin/chmod 0755 /opt/unmount.autostop

    6. Install ZeroTier and Join Network

    You will need your unique network id for this. It is assumed you already have a ZeroTier account and have created a network. Reboot the router and log in again via SSH and enter the following commands pressing enter after each command. For the last command replace ‘123abc123abc’ with the network id of the network you wish to join:

    opkg update [enter]

    opkg install zerotier [enter]

    zerotier-one -d [enter]

    zerotier-cli join 123abc123abc [enter]

    You will need to go to my.zerotier.com and enable your new node on the network. You can check your ZeroTier status by SSH into your router and issuing the command ‘zerotier-cli info

    7. Start ZeroTier Automatically

    You will most likely want to ZeroTier to start automatically. To do this we first need to create a new script.
    SSH into your router and issue the command ‘nano /opt/etc/init.d/S90zerotier-one.sh’ then enter the following:

    #! /bin/sh
    
    case "$1" in
      start)
        if ( pidof zerotier-one )
        then echo "ZeroTier-One is already running."
        else
          echo "Starting ZeroTier-One" ;
          /opt/bin/zerotier-one -d ;
          echo "$(date) Started ZeroTier-One" >> /opt/var/log/zerotier-one.log ;
        fi
        ;;
      stop)
        if ( pidof zerotier-one )
        then
          echo "Stopping ZeroTier-One";
          killall zerotier-one
          echo "$(date) Stopped ZeroTier-One" >> /opt/var/log/zerotier-one.log
        else
          echo "ZeroTier-One was not running" ;
        fi
        ;;
      status)
        if ( pidof zerotier-one )
        then echo "ZeroTier-One is running."
        else echo "ZeroTier-One is NOT running"
        fi
        ;;
      *)
        echo "Usage: /etc/init.d/zerotier-one {start|stop|status}"
        exit 1
        ;;
    esac
    
    exit 0

    Save the file with ctrl+o then ctrl+x then make it executable with:

    chmod 755 /opt/etc/init.d/S90zerotier-one.sh

    And finally lets set up a cron job to run our script:

    cru a ZeroTierDaemon “* * * * * /opt/etc/init.d/S90zerotier-one.sh start”

    Reboot your router once again. After it’s finished booting up log in to your FreshTomato admin panel and navigate to ‘Advanced>Routing’. You should see an entry for ZeroTier in your routing table. See image below, your IP address and interface id may be different.

    Congratulations, You have successfully setup ZeroTier on your FreshTomato router!
    Thanks to the following:
    All of the devs at FreshTomato & TomatoUSB Including:
    Pedro
    Shibby
    Jonathan Zarate
    and many others
    Also like to thank:
    Entware @ github.com/Entware/Entware
    ZeroTier @ zerotier.com
    szpunk @ linksysinfo.org
    MissingTwins @ snbforums.com
    meoso @ gist.github.com/meoso

Design a site like this with WordPress.com
Get started