Installing TFTP on your server/workstation
Before beginning, you need to understand that in order to send/receive files with tftp, you need to have a tftp server running. In order to start a tftp server, you need to install tftp-server. The steps below walk you through getting tftp ready to send/receive files
Install tftp and tftp-server. This will also create /var/lib/tftpboot, the default directory that files will be dropped into while using tftp. Install tftp:
yum install tftp-server
In the screenshot below, notice how the /var/lib/tftpboot directory does not exist until after I have installed tftp-server.
Configure the TFTP Server
By default, the tftp service is set to disabled. Also, TFTP will automatically attempt to transfer files to the default tftp directory. In order to specify what directory you want tftp to copy files to, and to enable the service, we need to update the tftp config in /etc/xinet.d/tftp. Simply change the “disable” line to no, and change the “server_args” line to wherever you would like file to be downloaded to. I have set my tftp directory to /var/mytftp, as seen in my config below:
Start the tftp server
To start the tftp server, you actually just need to restart the xinetd service.
service xinetd restart
You can verify that it is running by using ps -ef and grepping for tftp. The bolded line verifies that /var/mytftp is where files can be transferred from/to via tftp.
[root@First ~]# ps -aef |grep tftp
root 4611 3435 0 15:35 pts/0 00:00:00 /usr/bin/tftp
root 4764 4758 0 15:53 ? 00:00:00 in.tftpd -s /var/mytftp
root 4774 3435 0 15:58 pts/0 00:00:00 grep tftp
Sample Successful TFTP Transfer
In my example, I will be getting a file from my tftp server from a remote system. The file I want to grab is called firstfile. First, I create the file, and place it in my tftp directory
[root@First ~]# echo "this is my first tftp file!" > /var/mytftp/firstfile
On my second machine, I will open a tftp session up to the tftp server and “get” the firstfile. Notice after I get the file, I run an
ls -lhrt, and see firstfile.
[root@Second ~]# tftp -v 192.168.1.9
Connected to 192.168.1.9 (192.168.1.9), port 69
tftp> get firstfile
getting from 192.168.1.9:firstfile to firstfile [netascii]
Received 27 bytes in 0.0 seconds [312619 bit/s]
Sample Failed TFTP transfer
Failed tftp transfers can happen for many reasons. Two of the most common are you have the wrong IP, or the wrong file name.
In the following example, I’ve got the wrong IP. You will still see your tftp session open, but in reality you are not connected. This is evident when you try to get/out a file and it just appears to “hang”, eventually causing you to ctrl+c out of it.
In this example, I’ve got the correct IP, but the wrong file name. Interestingly, even with the wrong file name, my tftp get attempt will still place a file in your current working directory as seen in the image below.