1.安装命令
$sudo apt-get install xinetd tftpd tftp
2.建立配置文件
$sudo gedit /etc/xinetd.d/tftp
输入以下内容并保存:
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
3.建立TFTP服务器目录
$sudo mkdir /tftpboot
$sudo chmod 777 /tftpboot -R
4.重启TFTP服务
$sudo service xinetd restart
TFTP下载命令格式为:get 文件名
TFTP上传命令格式为:put 文件名
5.TFTP下载测试
将目录“/tftpboot”里的test文件下载到用户目录里面。
wang@ubuntu:~$ ls
Desktop Downloads Music Public Videos
Documents examples.desktop Pictures Templates
wang@ubuntu:~$ tftp 127.0.0.1
tftp> get test
Received 21 bytes in 0.1 seconds
tftp> quit
wang@ubuntu:~$ ls
Desktop Downloads Music Public test
Documents examples.desktop Pictures Templates Videos
6.TFTP上传测试
TFTP服务默认只能下载不能上传,如果要上传的话,必须在目录“/tftpboot”里面新建名称相同的文件。在用户目录下新建hao123文件,文件内容写hao123,使用put上传命令,提示错误信息“Error code 2: Access violation”。
wang@ubuntu:~$ gedit hao123
wang@ubuntu:~$ ls
Desktop Downloads hao123 Pictures Templates Videos
Documents examples.desktop Music Public test
wang@ubuntu:~$ tftp 192.168.2.11
tftp> put hao123
Error code 2: Access violation
回到“/tftpboot”目录,在里面新建文件hao123,新建后需要修改文件权限,再次回到用户目录“~/”,这次可以完成文件hao123的上传。
tftp> quit
wang@ubuntu:~$ cd /tftpboot
wang@ubuntu:/tftpboot$ touch hao123
wang@ubuntu:/tftpboot$ ls
hao123 test test2 test2~
wang@ubuntu:/tftpboot$ chmod 777 hao123
wang@ubuntu:/tftpboot$ cd /home/wang
wang@ubuntu:~$ ls
Desktop Downloads hao123 Pictures Templates Videos
Documents examples.desktop Music Public test
wang@ubuntu:~$ tftp 192.168.2.11
tftp> put hao123
Sent 8 bytes in 0.1 seconds