1 Installation
If the network is available, you can install it directly via yum.
1
|
yum install tftp-server
|
You can also download the rpm package first and then install it, download at http://rpmfind.net/linux/rpm2html/search.php?query=tftp-server
Then install.
1
|
rpm -ihv tftp-server-0.49-8.el6.x86_64.rpm
|
After installation, you can find an additional in.tftpd
file in the /usr/sbin
directory.
1
2
|
$ ls /usr/sbin/in.tftpd
/usr/sbin/in.tftpd
|
2 Configuration
in.tftpd
is managed through the xinetd
service. /etc/xinetd.conf
stores the default configuration of all services managed by xinetd
, and also the default configuration of tftpd
.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# cat /etc/xinetd.conf
#
# This is the master xinetd configuration file. Settings in the
# default section will be inherited by all service configurations
# unless explicitly overridden in the service configuration. See
# xinetd.conf in the man pages for a more detailed explanation of
# these attributes.
defaults
{
# The next two items are intended to be a quick access place to
# temporarily enable or disable services.
#
# enabled =
# disabled =
# Define general logging characteristics.
log_type = SYSLOG daemon info
log_on_failure = HOST
log_on_success = PID HOST DURATION EXIT
# Define access restriction defaults
#
# no_access =
# only_from =
# max_load = 0
# Accept up to 50 connections per second, if more than 50, stop for 20 seconds before accepting new connections
cps = 50 10
# Maximum number of connections
instances = 50
# Maximum number of connections for a single client
per_source = 10
# Address and networking defaults
#
# bind =
# mdns = yes
v6only = no
# setup environmental attributes
#
# passenv =
groups = yes
umask = 002
# Generally, banners are not used. This sets up their global defaults
#
# banner =
# banner_fail =
# banner_success =
}
includedir /etc/xinetd.d
|
Add the tftp server
configuration to the /etc/xinetd.d/tftp
file. The configuration specified in this file will override the configuration in the /etc/xinetd.conf
file, and the default configuration will be used if no configuration is specified.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# cd /etc/xinetd.d/
# vim tftp
# 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
# Concurrency
wait = no
# Start tftpd user
user = root
# Start command
server = /usr/sbin/in.tftpd
# Start parameter, -s specifies the file directory of tftpd, -c means allow file upload
server_args = -s /var/lib/tftpboot -c
# Allow start
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
|
For more information about the configuration of xinetd, you can refer to the official documentation.
3 Start
Create a file directory and modify the file directory access rights
1
|
chmod 777 /var/lib/tftpboot
|
Set the boot self-start, and then start the service.
1
2
3
|
chkconfig tftp on
chkconfig xinetd on
service xinetd start
|
Check Status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# service xinetd status
xinetd (pid 28613) is running...
# ps -ef | grep in.tftpd | grep -v 'grep'
root 23264 1 0 May19 ? 00:00:03 in.tftpd -s /tftpboot -c
nobody 23405 28616 0 14:32 ? 00:00:00 in.tftpd -s /tftpboot -c
root 28616 28613 0 May19 ? 00:00:03 in.tftpd -s /tftpboot -c
# tftpd uses port 69 by default
$ netstat -tuplna | grep ':69 '
(No info could be read for "-p": geteuid()=249958 but you should be root.)
udp 0 0 0.0.0.0:69 0.0.0.0:* -
udp 0 0 0.0.0.0:69 0.0.0.0:* -
# Test port connection
$ nc -uvz 127.0.0.1 69
Connection to 127.0.0.1 69 port [udp/tftp] succeeded!
|
4 Testing
The tftp client uploads files via the put
command and downloads files via the get
command, but does not support list file server file and directory listings, nor does it support deleting files
All commands supported by tftp.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# Check whether the tftp client is installed, the system is generally installed by default
$ which tftp
/usr/bin/tftp
$ tftp -v 127.0.0.1
Connected to 127.0.0.1 (127.0.0.1), port 69
tftp> ?
tftp-hpa 0.49
Commands may be abbreviated. Commands are:
connect connect to remote tftp
mode set file transfer mode
put send file
get receive file
quit exit tftp
verbose toggle verbose mode
trace toggle packet tracing
literal toggle literal mode, ignore ':' in file name
status show current status
binary set mode to octet
ascii set mode to netascii
rexmt set per-packet transmission timeout
timeout set total retransmission timeout
? print help information
help print help information
tftp> quit
|
Test file upload and download.
1
2
3
4
|
$ tftp 127.0.0.1
tftp> put test.txt
tftp> get test.txt
tftp> quit
|
or
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# Upload
$ tftp -v 127.0.0.1 -c put test.txt
Connected to 127.0.0.1 (127.0.0.1), port 69
putting test.txt to 127.0.0.1:test.txt [netascii]
Sent 19 bytes in 0.0 seconds [8069 bit/s]
# tftpd file directory to view the uploaded files
$ ls /var/lib/tftpboot
test.txt
$ rm -f test.txt
$ ls
# downloaded
$ tftp -v 127.0.0.1 -c get test.txt
Connected to 127.0.0.1 (127.0.0.1), port 69
getting from 127.0.0.1:test.txt to test.txt [netascii]
Received 19 bytes in 0.0 seconds [17714 bit/s]
# View downloaded files
$ ls
test.txt
|
5 Principles
5.1 Protocol Overview
TFTP is known as Trivial File Transfer Protocol
in English and Simple File Transfer Protocol in Chinese. It provides uncomplicated and low overhead file transfer service. The port number is 69. based on UDP protocol.
5.2 TFTP Message Types
TFTP defines a total of five types of packets, the types are distinguished by the Opcode field in the first two bytes of the packet data, which are as follows
- read file request packet: Read request, abbreviated as RRQ, corresponding to Opcode field value of 1
- write request packet: Write requst, abbreviated as WRQ, corresponding to the Opcode field value of 2
- file data packet: Data, abbreviated as DATA, corresponding to Opcode field value of 3
- response packet: Acknowledgement, abbreviated as ACK, corresponding to Opcode field value of 4
- error information package: Error, abbreviated as ERROR, corresponding to the Opcode field value of 5
5.3 TFTP Port Number Assignment
When TFTP clients send read request and write request messages, the destination port is 69, while Data, Acknowledgement, and Error do not use port 69, they use random ports 1024~5000.
Different operating systems have different port numbers, Linux uses 32768~61000, Windows uses 1025~5000