OpenWrt: Installing a TFTP Server on Ubuntu for OpenWrt Firmware Updates

openwrt_logoThe Trivial File Transfer Protocol (TFTP) is an extremely simple protocol most often used for network booting strategies, such as PXE and flashing OpenWrt images unto consumer routers.

I go over full instructions for flashing OpenWrt using Ubuntu and flashing a sysupgrade in another post, this article will focus specifically on setting up a tftp server daemon on Ubuntu that can be used to serve the binary image file.

Installation

First, install the tftp server and client packages:

# apt-get install tftpd-hpa tftp-hpa -y

If we needed to modify the configuration, we could edit ‘/etc/default/tftpd-hpa’, but we will use the defaults which make the /var/lib/tftpboot directory readable (but not writeable) to clients.

Finally, update the firewall to allow port 69 over UDP.

# ufw allow 69/udp

Quick Validation

Create a test file in the default tftp home directory.

> sudo chmod ug+w /var/lib/tftpboot
> sudo echo hello world >> /var/lib/tftpboot/hello.txt

Then use the tftp client to connect to the tftp server and download our test file.

> cd /tmp
> tftp localhost
get hello.txt
quit

Now verify that the file content was downloaded:

> cat hello.txt

You should see “hello world” as the result of the last cat command.

Validate OpenWrt Image

Now put the actual OpenWrt image file you want into the tftp home directory.  This image will vary based on your router, but let’s assume for this example that you have a LinkSys WRT1900ACS, which requires “openwrt-15.05.1-mvebu-armada-385-linksys-shelby-squashfs-factory.img” and that you have used your browser to download that into your ‘/home/id/Downloads’ directory.

Move that binary file into the tftp home directory:

> sudo mv /home/id/Downloads/openwrt-15.05.1-mvebu-armada-385-linksys-shelby-squashfs-factory.img /var/lib/tftpboot/.

Now test the download with the tftp client:

> cd /tmp
> tftp localhost
get openwrt-15.05.1-mvebu-armada-385-linksys-shelby-squashfs-factory.img
quit

The image file should now exist in /tmp

> ls -l *.img

 

REFERENCES

https://help.ubuntu.com/community/TFTP

http://askubuntu.com/questions/317231/tftpd-hpa-12-04-lts

https://community.spiceworks.com/how_to/100006-install-and-configure-tftp-under-ubuntu-14-04

http://www.routingloops.co.uk/linux/tftp-on-ubuntu-14-04-lts-server/

Note that if you do end up using a Windows machine to host the tftp server, tfpd32 is a nice option.  But be sure to change the Settings > TFTP > Advanced Options so that there is option negotiation is disabled and PXE compatibility is enabled.  And of course, enable port 69 on the Windows firewall.