linux tftpサーバのインストール

2875 ワード

概要
TFTP(Trivial File Transfer Protocol)は、TCP/IPプロトコルファミリーのクライアントとサーバとの間で単純なファイル転送を行うためのプロトコルであり、複雑ではなく、オーバーヘッドの少ないファイル転送サービスを提供する.ポート番号は69です.
yumインストール
まずyumソースにtftpパッケージがあるかどうかを確認します
[root@localhost test]# yum list |grep tftp
syslinux-tftpboot.noarch                4.05-15.el7                    base     
tftp.x86_64                             5.2-22.el7                     base     
tftp-server.x86_64                      5.2-22.el7 

yumインストールtftpインストールtftp-server
[root@localhost test]# yum install tftp-server

インストールに成功すると、/etc/xinetd.dでプロファイルtftpが生成されます.
[root@localhost xinetd.d]# ls /etc/xinetd.d
chargen-dgram   daytime-dgram   discard-dgram   echo-dgram   pure-ftpd      tftp        time-stream
chargen-stream  daytime-stream  discard-stream  echo-stream  tcpmux-server  time-dgram
[root@localhost xinetd.d]# vi /etc/xinetd.d/tftp

disable=yesをnoに変更
service tftp
{
	socket_type		= dgram
	protocol		= udp
	wait			= yes
	user			= root
	server			= /usr/sbin/in.tftpd
	server_args		= -s /var/lib/tftpboot
	disable			= no
	per_source		= 11
	cps			= 100 2
	flags			= IPv4
}

tftpサービスの開始
tftpサービスを開始するにはxinetdサービスを再起動するだけです
service xinetd restart

69ポートが動作しているかどうかを確認
[root@localhost xinetd.d]# netstat -nlp |grep 69
udp        0      0 0.0.0.0:69              0.0.0.0:*                           77308/xinetd        
unix  2      [ ACC ]     STREAM     LISTENING     18691    746/NetworkManager   /var/run/NetworkManager/private-dhcp
unix  2      [ ACC ]     STREAM     LISTENING     16974    740/gssproxy         /run/gssproxy.sock
unix  2      [ ACC ]     STREAM     LISTENING     16973    740/gssproxy         /var/lib/gssproxy/default.sock


ファイアウォールの設定(オプション)
/sbin/iptables -I INPUT -p tcp --dport 69 -j ACCEPT
/sbin/iptables -I INPUT -p udp --dport 69 -j ACCEPT
/etc/rc.d/init.d/iptables save
service iptables restart
service iptables status

テスト
[root@localhost test]# echo "1111" > /var/lib/tftpboot/name.txt
[root@localhost test]# tftp 192.168.8.174
tftp> help
tftp-hpa 5.2
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> get name.txt
tftp> q
[root@localhost test]# ls |grep name.txt 
name.txt