CentOS7下tftp服務安裝配置


1、軟件包安裝

root用戶或者普通用戶使用sudo權限執行如下命令:

yum install xinetd tftp tftp-server        # root 用戶執行
sudo yum install xinetd tftp tftp-server   # 普通用戶執行

2、tftp-Server服務配置

[root@localhost ~]# cat /etc/xinetd.d/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
    wait               = yes
    user               = root
    server             = /usr/sbin/in.tftpd
    server_args        = -s /var/lib/tftpboot -c # 注意這行,如果允許上傳,一定要加上參數 -c
    disable            = no   # 這行默認為yes,改成no,允許
    per_source         = 11
    cps                = 100 2
    flags              = IPv4
}

3、啟動tftp服務

[root@localhost ~]#systemctl restart xinetd.service 
[root@localhost ~]# netstat -a | grep tftp 
udp        0      0 0.0.0.0:tftp            0.0.0.0:*                          
udp6       0      0 [::]:tftp               [::]:* [root@localhost
~]# netstat -tunap | grep :69
udp        0      0 0.0.0.0:69              0.0.0.0:*                           30014/xinetd        
udp6       0      0 :::69                   :::*                                1/systemd 

4、測試上傳下載

C:\>d:

D:\>tftp 10.190.38.213 get test.log
傳輸成功: 1 秒 17 字節,17 字節/

D:\>tftp 10.190.38.213 put d:\readme
傳輸成功: 1 秒 474 字節,474 字節/秒

D:\>

5、常見問題處理

5.1 如果上傳時出現"連接請求失敗"的提示,請確保tftp服務的文件存放目錄權限設置正確

  • 解決辦法:chmod  0777  /var/lib/tftpboot

5.2 文件上傳時提示:Error code 1: File not found

在/etc/xinetd.d/tftp配置文件中,server_args后加上 -c 選項,方可上傳

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

5.3 如客戶端無法連接,或包timeout

請確認服務器iptables策略開放了UDP的 69 端口,並關閉了selinux服務。

 iptables策略開放:

# 編輯iptables配置文件
[root@localhost ~]# vim /etc/sysconfig/iptables

# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p udp -m state --state NEW -m tcp --dport 69 -j ACCEPT

或者執行如下命令:

iptables -A INPUT -p udp --dprot 69 -j ACCEPT


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM