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: eadme 传输成功: 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