1. 程式人生 > >Linux中TFTP使用詳解

Linux中TFTP使用詳解

FTP協議簡介
TFTP是用來下載遠端檔案的最簡單網路協議,它其於UDP協議而實現。

linux伺服器端tftp-server的配置


1、安裝tftp伺服器
需要安裝xinetd(守護tftp)、tftp和tftp-server 3個軟體
1)如果能上網,通過yum安裝:
sudo yum install xinetd
sudo yum install tftp
sudo yum install tftp-server


2、配置tftp伺服器
修改/etc/xinetd.d/tftp檔案,將其中的disable=yes改為disable=no。開啟TFTP服務
主要是設定TFTP伺服器的根目錄,開啟服務。修改後的檔案如下:


service tftp
{     socket_type            =dgram
       protocol                  =udp
       wait                        =yes
       user                        =root
       server                     =/usr/sbin/in.tftpd
     server_args             =-s /home/mike/tftpboot -c
 disable                    =no
       per_source             =11

       cps                         =100 2
       flags                       =IPv4
}
說明:修改項server_args= -s     <path>    -c,其中<path>處可以改為你的tftp-server的根目錄

引數-s指定chroot,-c指定了可以建立檔案


3、啟動tftp伺服器並關閉防火牆

RedHat7+

systemctl disable firewall;systemctl stop firewall

systemctl enable xinetd;systemctl start xinetd

Redhat7-
/etc/init.d/iptables stop        //關閉防火牆
sudo /sbin/service xinetd start
或service xinetd restart
/etc/init.d/xinetd start
看到啟動[OK]就可以了


4、檢視tftp服務是否開啟
netstat -a | grep tftp
顯示結果為
udp 0 0 *:tftp *:*
表明服務已經開啟,就表明tftp配置成功了。


5、tftp使用
複製一個檔案到tftp伺服器目錄,然後在主機啟動tftp軟體,進行簡單測試。

登陸
tftp 192.168.1.2
tftp>get <download file>
tftp>put <upload file>
tftp>q


6、tftp命令用法如下
tftp     your-ip-address
【進入TFTP操作】
connect:連線到遠端tftp伺服器
mode:檔案傳輸模式
put:上傳檔案
get:下載檔案
quit:退出
verbose:顯示詳細的處理資訊
tarce:顯示包路徑
status:顯示當前狀態資訊
binary:二進位制傳輸模式
ascii:ascii傳送模式
rexmt:設定包傳輸的超時時間
timeout:設定重傳的超時時間
help:幫助資訊
?:幫助資訊


7、如果出現“AVC Denial, click icon to view”的錯誤,並不能傳輸檔案
修改/etc/sysconfig/selinux,將SELINUX設定為disable
使用命令setenforce 0讓selinux配置檔案生效