TFTP (Trivial File Transfer Protocol) is a simple file transfer protocol that is often used to transfer configuration files and firmware images between networked devices. In this tutorial, I will guide you through the steps to install and set up TFTP on Ubuntu 22.04.
Step 1: Installing TFTP Server
To install the TFTP server on Ubuntu 22.04, open the terminal and run the following command:
sudo apt-get install tftpd-hpa
This command will install the TFTP server on your system.
Step 2: Configuring TFTP Server
After installing the TFTP server, you need to configure it by editing the configuration file. Open the configuration file in a text editor by running the following command:
sudo nano /etc/default/tftpd-hpa
This will open the configuration file in the Nano text editor. In this file, you will find a line that reads:
TFTP_OPTIONS="--secure"
Add the following line below it:
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/lib/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="--secure --create"
The TFTP_USERNAME variable sets the user that the TFTP server will run as. The TFTP_DIRECTORY variable sets the directory where the TFTP server will look for files to serve. The TFTP_ADDRESS variable sets the IP address and port that the TFTP server will listen on. The TFTP_OPTIONS variable sets various options for the TFTP server, such as the –secure option, which prevents files from being deleted or overwritten.
Save and close the file by pressing Ctrl+X
, then Y
, then Enter
.
Step 3: Creating the TFTP Root Directory
Create the directory that you specified in the TFTP_DIRECTORY variable by running the following command:
sudo mkdir /var/lib/tftpboot
Step 4: Setting Permissions
Set the permissions for the TFTP root directory by running the following commands:
sudo chown -R nobody:nogroup /var/lib/tftpboot
sudo chmod -R 777 /var/lib/tftpboot
These commands set the owner and group of the directory to nobody and nogroup, respectively, and give read, write, and execute permissions to everyone.
Step 5: Restarting the TFTP Server
Restart the TFTP server by running the following command:
sudo systemctl restart tftpd-hpa
Step 6: Testing the TFTP Server
Test the TFTP server by transferring a file from a client machine. You can use a TFTP client like tftp-hpa to test the server. Install the client on the client machine by running the following command:
sudo apt-get install tftp-hpa
Then, transfer a file from the client machine to the TFTP server by running the following command:
tftp <TFTP_SERVER_IP_ADDRESS>
tftp> put <LOCAL_FILE_PATH> <REMOTE_FILE_NAME>
Replace <TFTP_SERVER_IP_ADDRESS>
with the IP address of your TFTP server, <LOCAL_FILE_PATH>
with the path to a file on your local machine, and <REMOTE_FILE_NAME>
with the name you want to give the file on the TFTP server.
If the transfer is successful, you should see a message similar to the following:
Sent <FILE_SIZE> bytes in <TRANSFER_TIME> seconds
Congratulations! You have successfully installed and set up a TFTP server on Ubuntu 22.04.
Nicely done Cory. Instructions were perfect and helped me get the TFTPD up and running for an EDA tool install that required it.