Starting with a TFTP Server: A Guide from Scratch

In the vast world of networks and system administration, having the necessary tools and knowledge to perform updates and remote configurations is essential. This is where the Trivial File Transfer Protocol (TFTP) comes into play, a simple and lightweight protocol used to transfer files between a client and a server on a network.

What is TFTP and what is it used for?

TFTP is an application layer protocol based on the client-server model. Unlike other file transfer protocols such as FTP or SCP, TFTP is much simpler and does not include features such as user authentication or encryption. This makes it ideal for situations where simplicity and speed are crucial, such as firmware updates on network devices.

One of the most common uses of TFTP is precisely in the field of networks, for uploading and downloading operating system images and configuration files on routers, switches, and other devices. When a network device needs to be updated or recovered, TFTP is often the chosen tool due to its simplicity and efficiency.

Choosing and Installing the Appropriate Software

There are several implementations of the TFTP server, but one of the most popular on Debian-based systems like Ubuntu is tftpd-hpa. This implementation stands out for its simplicity and its ability to get the job done without unnecessary complications.

To install tftpd-hpa on Ubuntu 22.04, open a terminal and run the following commands:

sudo apt update sudo apt install tftpd-hpa

This process will install the TFTP server and all the necessary packages on your system, leaving it ready to be configured.

Configuring tftpd-hpa for Success

Once we have the TFTP server installed, the next step is to configure it to suit our needs. The main configuration file of tftpd-hpa is located in /etc/default/tftpd-hpa.

When opening this file with a text editor such as nano:

sudo nano /etc/default/tftpd-hpa

You will find several configuration lines. This is where we specify the details of our TFTP server’s operation. An example configuration might be:

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

Understanding the Configuration Options

  • TFTP_USERNAME: Defines under which user the TFTP service will run. By default, this is usually tftp.
  • TFTP_DIRECTORY: Sets the root directory of the TFTP server. All files that you want to be accessible via TFTP must be in this directory.
  • TFTP_ADDRESS: Specifies the address and port on which the TFTP server will listen. :69 means that the server will accept connections on all network interfaces on TFTP’s standard port, 69.
  • TFTP_OPTIONS: Here we can add additional options. With –secure, we ensure that only files within the specified directory can be accessed, an important security measure to avoid unwanted access.

It is crucial to ensure that the directory specified in TFTP_DIRECTORY exists and has the proper permissions. We can create it and assign permissions with the following commands:

sudo mkdir /var/lib/tftpboot sudo chown tftp:tftp /var/lib/tftpboot sudo chmod 777 /var/lib/tftpboot

Starting Up the Server

After having configured everything to our liking, it is time to restart the service to apply the changes:

sudo systemctl restart tftpd-hpa

And to make sure everything is working as it should, we can check the status of the service:

sudo systemctl status tftpd-hpa

If everything has gone well, you should see a message indicating that the service is active and running.

Securing Access: Configuring the Firewall

If you are using a firewall on your system, it is necessary to configure it to allow TFTP traffic. In the case of ufw, one of the most used firewalls in Ubuntu, the command would be:

sudo ufw allow 69/udp

This will open port 69 on the UDP protocol, which is used by TFTP.

Testing the Server

With everything in place, now is the time to test our TFTP server. We can do this from another machine using a TFTP client. On Ubuntu, we can install tftp-hpa, an implementation of the TFTP client:

sudo apt install tftp-hpa

With the client installed, we connect to the TFTP server:


And once inside, we can use commands like get to download files or put to upload them.

Adjustments and Customizations

TFTP is a simple protocol, but that does not mean it cannot be adjusted and customized to meet our needs. From choosing the directory for the files to configuring the firewall, there are several ways to ensure that our TFTP server is running as best as possible.

The key is to understand the specific needs of your network and devices, and adjust the configuration accordingly. TFTP is a powerful tool in its simplicity, and with the right configuration, it can be an invaluable ally in network and system administration.

So whether you are an experienced system administrator or someone taking their first steps in the world of networks, setting up a TFTP server from scratch is a useful skill worth learning. With tftpd-hpa and Ubuntu 22.04, you have everything you need to get started. Go ahead and discover the power of TFTP for yourself!

Leave a Reply