Networking / Beginners

Trivial File Transfer Protocol (TFTP)

TFTP (RFC 1350) is a simple and lightweight file transfer protocol, somewhat similar to a slimmed down version of the FTP, without any complexity. TFTP does not need login, does not support changing directories, nor does it show the list of files and directories on the server. When using TFTP, you should know the exact file name you want to receive.

Many network devices use TFTP to download their OS image, or even load/save their configuration on TFTP.

Running TFTP service requires the inetd server to be run. You should first enable TFTP by removing comment from TFTP related line in /etc/inetd.conf. The line should simply look like this:

tftp dgram udp wait root /usr/libexec/tftpd
tftpd -l -s /tftpboot

The last parameter on the above line runs tftpd(8) with syslog logging enabled (hence -l parameter) and also sets the root directory to /tftpboot. You may change this to your desired directory. Please note that /tftpboot does not exist on a clean FreeBSD installation and hence should be created.

After configuring the tftpd parameters, you should start/restart the inetd process.

You can test functionality of your TFTP server using a TFTP client across the network.

FreeBSD also comes with a TFTP client called tftp(1). To test the functionality of your tftpd(8) server using tftp(1) client, you should set up appropriate directories and put some files in your /tftproot directory. Using tftp(1) on the same client you should be able to get (download) the file from TFTP server. Please note that you should remember the filename, since TFTP does not have the ability to see the list of the files on the server.

# tftp localhost

    tftp> verbose
    Verbose mode on.
    tftp> get make.conf
    getting from localhost:make.conf to make.conf [netascii]
    Received 853 bytes in 7.0 seconds [975 bits/sec]
    tftp> quit

The above example shows a basic TFTP file transfer scenario using FreeBSD's built-in TFTP client. The TFTP client connects to the server on localhost. In this example, I turned on verbose output by entering the verbose command. This will tell the client to show the transfer progress, and more details about the errors, if any. Using the get command, you can download a file from TFTP server. And once the transfer is done, you can leave the client using the quit command.

TFTP can also be used to upload files to a specific server (for example, a network device backing up its configuration or OS image on a TFTP server). However this can be a little tricky as compared to downloading files.

The TFTP server does not basically allow a client to create a file on the server, by default. However, if the file already exists on the server, it will be overwritten. Otherwise, it fails.

If you want to let your clients create files on the server by uploading files to your TFTP servers that do not exist already, you should modify the /etc/inetd.conf file. Then add the -w parameter to the tftpd parameters. This will let the clients upload files to your tftp root directory that does not already exist.

If you do not want your existing files to be overwritten by TFTP clients, you should make your files read-only, using the chown(8) command (for example, permission 0440 on your files).
[Previous] [Contents] [Next]