TFTP (Trivial FTP) 為無認證、UDP 69 埠的簡易檔案傳輸協議,廣泛用於**網路設備韌體升級、無盤啟動 (PXE)、嵌入式裝置配置備份**。Fedora 下透過 xinetd 超級守護進程託管 tftp-server 為標準部署方式。
dnf install tftp tftp-server xinetd
# 或舊版:yum install tftp tftp-server
cp /etc/xinetd.d/tftp.rpmnew /etc/xinetd.d/tftp
vi /etc/xinetd.d/tftp
關鍵修改:
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root # 建議改為專用帳號 tftp
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot -c -u tftp
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
參數說明:
-s /var/lib/tftpboot:chroot 根目錄(安全關鍵,限制存取範圍)-c:允許建立新檔案(上傳)-u tftp:以 tftp 用戶身分運行(需預建帳號)per_source、cps:連線限流防濫用mkdir -p /var/lib/tftpboot
chown tftp:tftp /var/lib/tftpboot
chmod 755 /var/lib/tftpboot
# 放置韌體、PXE 開機檔案 (pxelinux.0, vmlinuz, initrd.img)
systemctl enable --now xinetd
systemctl restart xinetd
# 本機測試
tftp localhost
tftp> get pxelinux.0
tftp> quit
# 遠端測試
tftp
tftp> put local_config.cfg
-s 參數強制限制存取路徑tftp 用戶/群組-c 參數firewall-cmd --add-port=69/udp --permanent && firewall-cmd --reloadsemanage fcontext -a -t tftpdir_t '/var/lib/tftpboot(/.*)?' && restorecon -Rv /var/lib/tftpbootonly_from = 192.168.1.0/24 限制客戶端網段| 現象 | 原因 | 解決 |
|---|---|---|
| Timeout 無回應 | 防火牆阻擋 UDP 69 | 開放防火牆埠口 |
| Access violation | SELinux 拒絕、路徑超出 chroot | 檢查 SELinux 標籤、確認 -s 參數 |
| File not found | 檔案不存在或大小寫錯誤 | TFTP 區分大小寫,確認檔名 |
| Permission denied | 目錄權限、用戶身分 | chown tftp:tftp、chmod 755 |
TFTP 簡單輕量,但**無認證、無加密、無目錄列表**,僅限受信內網、特定用途使用,嚴禁暴露於公網。