Sunday, October 12, 2014

Installing TFTP server atftpd in Linux

I need a TFTP server to keep configurations files. I need the server to be simple to setup and be able to send or receive any file without any restrictions. It would be for a lab environment so a strict security is not necessary. I'm using Linux Mint.
In Linux I could find three different TFTP servers: 
Already tried tftpd see my other post Installing TFTP server in Linux. A minor problem is that you cannot transfer a file to the TFTP server.

Installing atftpd
sudo apt-get install atftpd

Create folder
In my example I want to use  folder /tftpboot for the atftp 
sudo mkdir /tftpboot  
sudo chmod -R 777 /tftpboot  
sudo chown -R nobody /tftpboot  

Edit configuration file
Default config file /etc/default/atftpd contains this :
OPTIONS="--tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 --mcast-addr --mcast-ttl 1 --maxthread 100 --verbose=5 /srv/tftp"

Make changes to run as a server directly, not through inetd ( default)
Replace : 

Increase logging level by setting to --verbose=7 to capture all messages

Replace location of folder

Added location for log file --logfile /var/log/atftpd.log

Final atftp config file :
 $ cat /etc/default/atftpd   
 OPTIONS="--tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 --mcast-addr --mcast-ttl 1 --maxthread 100 --verbose=7 /tftpboot --logfile /var/log/atftpd.log"   

Touch /var/log/atftpd.log and set permissions accordingly
sudo touch /var/log/atftpd.log
sudo chmod 644 /var/log/atftpd.log

Start the server
sudo invoke-rc.d atftpd start
Starting Advanced TFTP server: atftpd.

Verify running of TFTP server
netstat -lnp | grep ":69 "
udp        0      0    *  

Install Client
sudo apt-get install atftp

Testing TFTP sever
Testing the TFTP server can be done in different ways.
One method is to test it from the same machine where TFTP server was installed, thus referring to localhost. 
An  from another physical machine. 

Create a file on the Client 
touch test-file.txt

Start TFTP sever
atftp localhost
tftp> put test-file.txt

Check if file was transferred to the designated folder
ls -al /tftpboot/
-rw-r--r--  1 nobody nogroup        0 Oct  12 00:33 test-file.txt

Further testing on different file sizes
After some complains I decide to check it by transfering different file sizes.I create few dummy files of different file sizes using the dd linux command
dd if=/dev/zero of=testfile-[MBytes].test bs=[bytes] count=1   

for example I created three dummy files 30MB, 40MB, 50MB
dd if=/dev/zero of=testfile-30MB.test bs=31457280 count=1  
dd if=/dev/zero of=testfile-40MB.test bs=41943040 count=1  
dd if=/dev/zero of=testfile-50MB.test bs=52428800 count=1  

After creation they should appear like below
.. 31457280 Mar 6 21:24 testfile-30MB.test  
...41943040 Mar 6 21:24 testfile-40MB.test  
.. 52428800 Mar 6 21:24 testfile-50MB.test  

Transferring the 30MByte file , was successful but the 40MByte was not.
 $ atftp  
 tftp> put testfile-30MB.test  
 tftp> put testfile-40MB.test  
 tftp: error received from server <Disk full or allocation exceeded>  
 tftp: aborting  

Further investigation shows that max file size is 32MB
 tftp> put testfile-31MB.test  
 tftp> put testfile-32MB.test  
 tftp: error received from server <Disk full or allocation exceeded>  
 tftp: aborting  

It appears that problem is on the file size and not the protocol itself.
There are some explanations in forums and suggestions  (1) ( 2

Real life example
Sending the running config from my cisco switch
DLS1#copy running-config tftp://
Address or name of remote host []?
Destination filename [dls1-confg]?
3941 bytes copied in 1.040 secs (3789 bytes/sec)

Checking if transfered on the TFTP server
$ls -al /tftpboot/
-rw-r--r-- 1 nobody nogroup  3941 Οκτ 12 12:46 dls1-confg


Anonymous said...

I'm getting a no space left on device error when copying ios image to my linux tftp server. Not sure what to do since there's plenty of room.

bill westrup said...

I get a "timeout retrying" when attempting to put a file to the tftp server.

How do you change the location fo the tftp directory?...this step seems unclear.

Stelios Agapiou said...

Concerning the first question with the "no space left" , I got similar "Disk full or allocation exceeded" and this is due to the allowed max file size. I update the post with detailed testing - check the updates.

Hi Bill,
if you are trying from another computer to access the atftp server, then first step is to confirm that is reachable. Try to ping it first.
Concerning the location of the atftp directory, my example uses /tftpboot and is in root folder. Haven't try it yet but where /tftpboot try to replace it with your directory using the whole path.