TFTP工具(Trivial File Transfer Protocol)使用:
一、概述
分为服务端和客户端,想要通信,一个配成服务端另一个配成客户端。TFTP 默认使用 UDP 端口号 69 进行传输活动
要想使用TFTP需要的步骤:
① 本地安装客户端工具
② 服务器安装TFTP服务端工具
③ 服务端开启 TFTP服务并配置TFTP上传和下载的目录。
二、如何在服务器安装TFTP工具并运行?
参考链接。
- sudo apt update
- sudo apt install tftp-hpa # installs the TFTP server package
- vi /etc/default/tftpd-hpa # configure TFTP server(也可能是/usr/share/doc/tftp-hpa,通过find找找)修改该配置文件如下所示
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/srv/tftp" #use the “mkdir” command by specifying the path
TFTP_ADDRESS=":69"
TFTP_OPTIONS="--secure"
- sudo chmod -R 777 /srv/tftp
- sudo chown -R nobody:nogroup /srv/tftp
- sudo systemctl restart tftpd-hpa
- sudo systemctl status tftpd-hpa #check the status of the ftpt server
- sudo systemctl enable tftpd-hpa #to start the tftp-hpa at the boot time
- sudo tftp localhost # test this TFTP service in TFTP SERVER # 如果您的服务器上有防火墙或网络设置,您需要确保TFTP服务器的传输端口(通常是UDP的69端口)是允许通过的。这可以通过配置防火墙规则或网络设备来实现。
- 尝试通过iptables打开防火墙69号端口的UDP服务,但没啥用。
sudo iptables -A INPUT -p udp --dport 69 -j ACCEPT
sudo iptables -A OUTPUT -p udp --sport 69 -j ACCEPT
sudo iptables -L -n //查看设置是否生效
service iptables save //保存对防火墙的设置
配置防火墙的我试了没啥用,因为服务器是公家的。应该是没权限。
基于 “用户权限” 区分不同tftp server目录(暂时没用到)
若无需严格隔离,可通过目录权限控制:服务器共享一个根目录,在其下为每个用户创建子目录(如/tftpboot/userA、/tftpboot/userB),并限制权限(仅用户可读写自己的子目录)。实现方式:
# 创建共享根目录
sudo mkdir -p /tftpboot/{userA,userB}
# 设置权限(用户A仅能访问自己的子目录)
sudo chown userA:userA /tftpboot/userA
sudo chmod 700 /tftpboot/userA # 仅所有者可读写
三、客户端连接到指定服务器的语法:
3.1在uboot下:
//设置ip地址
u-boot=> setenv ipaddr 192.168.200.255
//设置网关地址
u-boot=> setenv gatewayip 192.168.0.1
上面这两步骤也可也通过执行 dhcp 自动完成,
如果dhcp不了说明没网卡,还需要执行下面的指令设置网卡
u-boot=> setenv ethact e1000#0 or setenv ethact DPMAC17@rgmii-id
//设置tftp服务端ip地址
u-boot=> setenv serverip 192.168.200.222
//保存设置
u-boot=> saveenv
//查看当前设置
u-boot=> pri serverip
//把指定的文件从tftp server 填充到指定内存区
u-boot=> tftp [loadAddress] [[hostIPaddr:]bootfilename]
//数据cache, 指令cache都要刷,否则绝对没写进去
u-boot=> dcache flush; icache flush;
tftp与tftpboot有什么区别?tftp只是将文件写入指定内存,tftpboot会多一步直接执行目标文件。
3.2 在文件系统:
tftp [主机名称或IP地址]
get <file name> 下载文件
put <file name> 上传文件
输入? 显示帮助参考
其他参考链接:
通过 iptables 设置防火墙,iptables的使用:iptables网络数据包工具使用指南,入门使用详解-腾讯云开发者社区-腾讯云 (tencent.com)