1. 軟件安裝
- TFTP客戶端: tftp-hpa
- TFTP服務端: tftpd-hpa
- 網(wǎng)絡守護進程服務程序: xinetd
[zqq@ubuntu ~]# sudo apt install tftp-hpa
[zqq@ubuntu ~]# sudo apt install tftpd-hpa
[zqq@ubuntu ~]# sudo apt install xinetd
2. 配置TFTP服務器
- 修改
/etc/default/tftpd-hpa
配置文件:
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot " //將 /tftpboot 改成自己建立的tftp共享文件夾路徑
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s" //這里是選項
- 新建|修改
/etc/xinetd.d/tftp
配置文件:
// 如果有這個文件, 修改一下就可以了
service tftp
{
disable = no // tftp 服務器開關 no:on yes:off
socket_type = dgram
protocol = udp
wait = yes
user = root //修改為你登錄系統(tǒng)的用戶名
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot -c // /tftpboot 為你存放TFTP的文件目錄; -c參數(shù)允許上傳(>可以創(chuàng)建文件)
per_source = 11
cps = 100 2
}
3. 重啟TFTP服務
[zqq@ubuntu ~]# sudo service tftpd-hpa restart //重啟服務器
[zqq@ubuntu ~]# sudo /etc/init.d/xinetd reload
[zqq@ubuntu ~]# sudo /etc/init.d/xinetd restart //重啟xinetd怔昨,tftp的一個腳本
4. 測試
據(jù)說需要關閉防火墻, 由于沒有開啟, 不知道會出現(xiàn)什么情況:
# Ubuntu, 需要安裝 ufw
sudo ufw disable
# 其他 Linux
/etc/init.d/iptables stop
復制一個文件到tftp服務器目錄千扶,然后在主機啟動tftp軟件,進行簡單測試:
[zqq@ubuntu ~]# tftp 192.168.1.2
# 下載文件
tftp>get <download file>
# 上傳文件
tftp>put <upload file>
# 退出
tftp>q
5. TFTP 基本使用
進入TFTP操作:
connect:連接到遠程tftp服務器
mode:文件傳輸模式
put:上傳文件
get:下載文件
quit:退出
verbose:顯示詳細的處理信息
tarce:顯示包路徑
status:顯示當前狀態(tài)信息
binary:二進制傳輸模式
ascii:ascii 傳送模式
rexmt:設置包傳輸?shù)某瑫r時間
timeout:設置重傳的超時時間
help:幫助信息
? :幫助信息
在 Busybox 中使用如下(其他桌面系統(tǒng)命令參數(shù)不一樣,我的Ubuntu16.04就只適用get/put那種):
tftp [option] ... host [port]
[option]
-g 表示下載文件 (get)
-p 表示上傳文件 (put)
-l 表示本地文件名 (local file)
-r 表示遠程主機的文件名 (remote file)
以下是 tftp 快速上傳下載命令使用:
# 1. 不更名上傳下載(-gr/-gl | -pl/-pr)斋日,要從遠程主機192.168.1.2上下載 tftp_test,則應輸入以
下命令:
[root@ ~]# tftp -gr tftp_test 192.168.1.2
# 2. 從 192.168.1.2 下載文件 A.txt, 并更名為 B.txt (不更名就同名)
[root@ ~]# tftp -g -l B.txt -r A.txt 192.168.1.2
# 3. 上傳文件 C.txt 到 192.168.1.2, 并更名為D.txt(不更名則C.txt)
[root@ ~]# tftp -p -r D.txt -l C.txt 192.168.1.2
6. 如果老是出現(xiàn)“AVC Denial, click icon to view”的錯誤崭捍,并不能傳輸文件渴丸,需要作如下修改
修改 /etc/sysconfig/selinux
, 將 SELINUX 設定為 disable,使用命令 setenforce 0
讓 selinux 配置文件生效日戈。
*關于上傳失敗的原因
出錯: Error code 1: File not found
(可下載不能上傳)
因為TFTP默認只允許下載文件,要上傳文件,必須是服務器中已存在同名的文件,且該文件的權限允許被覆蓋! -- HMK-Linux (tftp成功啟動询张,get或put命令測試出現(xiàn)Error code 1: File not found)
所以在上傳文件時, 需要先在 TFTP 目錄下創(chuàng)建同名文件, 并且賦予可寫的權限; 并且, 在配置 /etc/xinetd.d/tftp
文件時, server_args = -s /tftpboot -c
的 -c
必須要有(-c參數(shù)允許上傳).
[reference]
[1] LoTGu. Ubuntu14.04環(huán)境下配置TFTP服務器. (2017-03-20 15:03) https://www.cnblogs.com/AP0904225/p/6589085.html
[2] linuxde.net. tftp命令[M]. http://man.linuxde.net/tftp
[3] believe209. tftp命令使用說明[M]. (2015年12月01日 15:03:12) http://blog.csdn.net/wangzhen209/article/details/50129275
[4] HMK-Linux. tftp成功啟動,get或put命令測試出現(xiàn)Error code 1: File not found. (2011-12-05 17:09) http://forum.ubuntu.org.cn/viewtopic.php?t=324925