How to Setup TFTP Server using Ubuntu 16.5 TLS

What is TFTP?

TFTP (Trivial File Transfer Protocol)  was primarily designed to read or write files by using a remote server.  The most common use of TFTP is Pixie boot.
You can read more about TFTP here.

How to set up TFTP Server?

First, install Ubuntu server 16.5 TLS.

Login, use sudo su – to switch to a superuser account in *nix environment known as root. Placing [-] at the end of the command line will tell bash (Bourne Again Shell)to append the history to the previous session.  At this point, you have to be very careful since the system will do exactly what you type and will assume that you know better than damage your server. 

First, we are going to update the system.

apt-get update (This will update list of available packages)
apt-get upgrade (This will update all installed packages on the system)

Now install tftp.

apt-get install tftp-hpa tftpd-hpa

next edit the configuration file located in etc using your favorite editor, my recommendation is nano for beginners.

nano /etc/default/tftpd-hpa

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"

Basic security and directory organization

TFTP_DIRECTORY I recommend it be changed to something else for example /data/tftp, but for this exercise, I will leave it default. As the name suggests this is where boot images are stored.
TFTP_OPTIONS is used to tell the TFTP server what is allowed if you need to put files on out TFTP server remotely then add –create. Keep in mind if you allow clients to write to the server you should have an incoming directory with r/w flags set
Now create some directories for your files, I will make one for my switch firmware backups called switches.

$ cd /var/lib/tftpboot
$ mkdir switches
$ chowm tftp:tftp switches

chown unix command changes file or directory ownership to the specific group and or user.
If you want your files to be read-only then use mod 755, if you want the world to be able to read/write/execute (execute flag on the directory is necessary for the user to access the directory) so your mask will be 777 allowing all. You can apply different masks using chmod to each file in the directory

$ chmod 755 switches

Restart the tftp service

$ service tftpd-hpa restart

Now use your favorite tftp client to connect to the new tftp server.
If you want this server to be part of the PXE Boot environment then you need to set up your DHCP server to point to this server and choose the boot file.

DHCP OPTION 60 -> IP for tftp server
DHCP OPTION 67 ->is full path to boot file like /switches/bootfile

Enjoy.