环境:centos6.9
下载 xinetd tftp tftp-server,其中xinetd和tftp-server是用来tftp服务器的,tftp是客户端
yum install xinetd tftp tftp-server -y
在根目录下建立 tftpboot
cd /
mkdir tftpboot
配置tftp服务器
在配置之前先做备份cp /etc/xinetd.d/tftp /etc/xinetd.d/tftp_bak
vim /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 /tftpboot -c #注:这里-s指tftp服务器的根目录,-c指能创建文件
disable = no #注:应该选择no,之前出现错误
per_source = 11
cps = 100 2
flags = IPv4
}
是tftp服务目录权限为777
chmod -R 777 /tftpboot/
启动tftp服务器
service xinetd restart
检查影响tftp服务内容
检查69端口开启
netstat -nlp | grep 69
设置selinux为0,关闭状态
setenforce 0
cd /etc/sysconfig/
查看状态
getenforce
配置防火墙端口
/sbin/iptables -I INPUT -p tcp --dport 69 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 21 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT
保存防火墙端口设置
/etc/rc.d/init.d/iptables save
重启防火墙
service iptables restart
service iptables status
在本地测试tftp
tftp localhost
使用get命令 和put命令
get 1.txt (前提是tftpboot目录下新建一个1.txt文档)
put 2.txt (在本地新建一个1.txt文档,传输到tftpboot目录)
查看本地tftp服务器是否开启
netstat -a | grep tftp
远程使用busybox来连接tftp服务并测试下载
安装包
wget http://www.busybox.net/downloads/busybox-1.31.1.tar.bz2
解压 tar -xjf busybox-1.31.1.tar.bz2
进入文件夹:cd busybox-1.31.1
设置远程访问执行环境: export TERM=vt100
执行:make menuconfig
执行: make
如果一切顺利,则生成busybox文件
查看busybox编译生成文件:file busybox
拷贝到本地执行环境下 cp busybox /usr/local/bin/
进入执行目录 cd /usr/local/bin/
创建本地tftp目录软连接: ln -s busybox tftp
执行tftp tftp -gr a.bin 172.31.102.81
在本地得到 a.bin 的可执行文件。前提是在远端服务器的tftpboot里面有a.bin目录
参考文档:https://blog.csdn.net/wc950126/article/details/52996467
来源:CSDN
作者:hcu5555
链接:https://blog.csdn.net/hcu5555/article/details/103616154