Linux配置tftp服务器用于局域网文件传输
1. 安装必备软件
首先安装三个必备软件
~$ sudo apt-get install xinetd
~$ sudo apt-get install tftp
~$ sudo apt-get install tftp-server
2. 修改配置文件
修改 /etc/xinetd.d/tftp
文件,主要是设置TFTP服务器的根目录,开启必要的服务等。修改之后的文件如下
service tftp
{
socket_type =dgram
protocol =udp
wait =yes
user =root
server =/usr/sbin/in.tftpd
server_args =-s /home/cv/tftpboot -c
disable =no
per_source =11
cps =1002
flags =IPv4
}
修改项 server_args= -s <path> -c
中的 path 改为你希望设置的 tftp-server 的根目录,参数-s
指定chroot,-c
表示可以在该路径下创建文件。
3. 启动tftp服务器并关闭防火墙
/etc/init.d/iptables stop # 关闭防火墙
sudo /sbin/service xinetd start
或
service xinetd restart
/etc/init.d/xinetd start
看到启动[OK]就可以了
4. 查看tftp服务是否开启
netstat -a | grep tftp
显示结果为udp 0 0 *:tftp :表明服务已经开启,就表明tftp配置成功了。
5. tftp命令的用法
命令格式为:
tftp [option]... host [port]
如果要下载或上传文件的话是一定要用这些[option]
的。
-g 表示下载文件(get)
-p 表示上传文件(put)
-l 表示本地文件名(local file)
-r 表示远程主机的文件名(remote file)
例如,要从远程主机192.168.1.2
上下载 test.txt
,则应输入以下命令
tftp -g -r test.txt 192.168.1.2
将磁盘中的文件上传到远程主机的命令
tftp -p -l file.txt 192.168.1.2