Monday, December 10, 2012

TFTP


Trivial File Transfer Protocol (TFTP) is a file transfer protocol notable for its simplicity. It is generally used for automated transfer of configuration or boot files between machines in a local environment. Compared to FTP, TFTP is extremely limited, providing no authentication, and is rarely used interactively by a user.
Due to its simple design, TFTP could be implemented using a very small amount of memory.. It is therefore useful for booting computers such as routers which may not have any data storage dive. It is an element of the Preboot Execution Environment (PXE) network boot protocol, where it is implemented in the firmware ROM / NVRAM of the host's network card.

It is also used to transfer small amounts of data between hosts on a network, such as IP phone firmware or operating system images when a remote X Windows system terminal or any other thin client boots from a network host or server. The initial stages of some network based installation systems (such as Solaris Jumpstart, Red Hat Kickstart, Symantec Ghost and Windows NT's Remote Installation Services) use TFTP to load a basic kernal that performs the actual installation. It was used for saving router configurations on Cisco routers, but was later augmented by other protocols.


TFTP was first defined in 1980 by IEN 133. It is currently defined by RFC 1350. There have been some extensions to the TFTP protocol documented in later RFCs.. TFTP is based in part on the earlier protocol EFTP, which was part of the PUP protocol suite. TFTP support appeared first as part of 4.3 BSD.
Due to the lack of security, it is dangerous to use it over the Internet. Thus, TFTP is generally only used on private, local networks.

Note If a TFTP server is not available on your Linux distribution or installed system, you can obtain a binary version for most Linux distributions from http://www.rpmfind.net/linux/rpm2html/ by searching for the string tftpd.
Ubuntu and Debian users can install the TFTP server with the following command:

# apt-get install xinetd tftpd
 
Before configuring the TFTP daemon itself, make sure that the entries for the TFTP protocol are not commented out in the /etc/services file. This file is typically consulted by each network service in order to determine the network ports that it should use.
You must be the root user to edit this file. Use your favorite text editor to remove the comment character (#) from the beginning of each line that contains the string tftp. Active TFTP entries in /etc/services should look like the following:

tftp            69/tcp
tftp            69/udp
 
Depending on the desktop Linux distribution and version you are using, Linux systems typically use one of two mechanisms to activate and manage network servers such as TFTP servers. These are either the Internet Services Daemon (inetd) or, more commonly, the Extended Internet Services Daemon (xinetd). Both of these commands manage a variety of network services by monitoring various network ports and starting the appropriate daemon in response to a valid request. The more modern mechanism is xinetd, and it is generally viewed as being more secure than the older inetd.
To determine which of these mechanisms your system uses to manage Internet services, you can use the system’s ps (process status) command, as in the following example:

# ps -alxww | grep inet
140      0    578      1   0  0  1152  356  do_select  S  ?  0:00  xinetd  ...
  0    500  13361  13336  18  0  1360  508  pipe_read  S  ?  0:00  grep -i  inet
 
In this example, the system is using the xinetd server, and you should follow the instructions in Configuring a TFTP Server Run by xinetd. If the output from this command shows that your system is running the inetd server, proceed to Configuring a TFTP Server Run by inetd.

Configuring a TFTP Server Run by xinetd

The servers that can be managed by the xinetd daemon are each listed in a server-specific configuration file located in the directory /etc/xinetd.d. The file for the TFTP server is named tftp, and looks like the following:

# default: off
# description: The tftp server serves files using the Trivial File Transfer \
#    Protocol.  The tftp protocol is often used to boot diskless \
#    workstations, download configuration files to network-aware printers, \
#    and to start the installation process for some operating systems.
service tftp
{
    socket_type     = dgram
    protocol        = udp
    wait            = yes
    user            = root
    server          = /usr/sbin/in.tftpd
    server_args     = -s /tftpboot
    disable         = yes
}
 
To enable the TFTP server, edit this file as the root user, replacing the word yes on the disable line with the word no. Then save the file and exit the editor.
Next, restart the xinetd process to force it to reread its configuration files, as described in Restarting the Service

Restarting the Service

If your system is running a desktop Linux distribution such as Red Hat Linux, which starts and stops system processes by using run configuration (rc) scripts, you can simply restart the daemon by invoking these scripts in one of the following commands that is appropriate for your daemon:

# /etc/init.d/xinetd restart
# /etc/init.d/inetd restart
 
This command will stop and then restart all of the services managed by the daemon on your Linux system. In addition to the restart command, you can also issue stop and start commands this way.
Caution
If your Linux system is running Internet services on which other systems depend, restarting the daemon will cause a slight interruption in those services.
After executing this command, the TFTP server will be started on your system in response to incoming TFTP requests, and you can access any files you copied to /tftpboot.
Note  If you need another way to stop the process, the following method will work on any Linux distribution. Send the HUP signal to the running xinetd process. To do this, you must first determine the process ID of the process that is currently running on your system by using the ps process status command, as in the following example:

# ps -alxww | grep xinet
 140    0    578      1   0  0  1152     356  do_select  S  ?  0:00  xinetd 
   0  500  13361  13336  18  0  1360     508  pipe_read  S  ?  0:00  grep -i  xinet
 
Of course, substitute inetd if that is the service you are using.
The -alxww options to the ps command cause it to display all system processes in an extremely wide listing. The grep command then searches for the string xinet in the resulting listing. This example displays information about a running command whose name or arguments contain the string xinet. Of these, the first is the actual xinetd process, and the third field is its process ID (in this example, 578). The process ID is the information that you will need to restart the process.
After collecting this information, you can cause the xinetd process to reread its configuration file by executing a command like the following:
 
# kill -HUP 578

Testing the Service

To ensure the TFTP server is running place a small text file in /tftpboot:
 
# echo "Hello, embedded world" > /tftpboot/hello.txt"

Then execute the following commands:
 # tftp localhost
tftp> get hello.txt
Received 23 bytes in 0.1 seconds
tftp> quit