在Ubuntu上建立tftp服务器 ( Set up tftp server on Ubuntu )

本文详细介绍了在Ubuntu系统中安装和配置TFTP服务器的方法,包括安装相关软件、配置服务、创建文件目录、设置权限以及启动服务等步骤。同时提供了测试传输文件的示例,以及关于安全性的一些建议。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

tftp(Trival File Transfer Protocol)是一种轻量级的文件传输协议,TFTP报文封装在UDP包之中(默认端口:69),并不可靠,因此不能 ls,也不能认证。
但是,在嵌入式开发中,它能够为目标机提供高速下载服务。由于是在局域网中,因此数据出错的概率也是相当小。
在Ubuntu上安装tftp服务器并不复杂:

  1. 安装ftpd以及相关软件包

    $ sudo apt-get install xinetd tftpd tftp

  2. 创建文件/etc/xinetd.d/tftp并且按如下所示配置

    service tftp 
    { 
    protocol = udp 
    port = 69 
    socket_type = dgram 
    wait = yes 
    user = nobody 
    server = /usr/sbin/in.tftpd 
    server_args = /tftpboot 
    disable = no 
    }
    或者
    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
    } 
    重点是:server_args = -s /tftpboot和 disable = no两个选项,(注:ubuntu下-c参数不能使用,添加后服务器无响应??why?)

  3. 在系统根目录下创建tftproot目录,并修改权限

    $ sudo mkdir /tftpboot 
    $ sudo chmod -R 777 /tftpboot 
    $ sudo chown -R nobody /tftpboot 


  4. 启动tftp服务

    $ sudo /etc/init.d/xinetd stop 
    $ sudo /etc/init.d/xinetd start 


  5. 测试:传输一个文件

    本测试将先与本机连接,然后再传送一个已有的文件(例如hello.txt),通过观察文件的修改时间来确定是否传送成功。

    $ touch /tftpboot/hello.txt 
    $ chmod 0777 /tftpboot/hello.txt 
    $ ls -l /tftpboot/ 
    total 0 
    -rwxrwxrwx 1 lesca lesca 0 2011-02-2616:43
    hello.txt 
    # 连接本地tftp服务器 
    $ tftp localhost 
    tftp> put hello.txt 
    tftp> quit 
    $ ls -l /tftpboot/ 
    total 8 
    -rwxrwxrwx 1 lesca lesca 0 2011-02-26 16:48 hello.txt 

    #时间发生了变化,传送成功

注:localhost如果没有在环境那个变量里面设定 就使用127.0.0.1


The above is from David Sudjiman – Installing and setting TFTPD in Ubuntu Translated and re-shared by Lesca.

附:检查tftpd是否已经启动

$ sudo netstat -lnput 
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 929/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1181/cupsd tcp 0 0 0.0.0.0:1723 0.0.0.0:* LISTEN 1110/pptpd tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1172/mysqld tcp6 0 0 :::80 :::* LISTEN 1253/apache2 tcp6 0 0 :::22 :::* LISTEN 929/sshd tcp6 0 0 ::1:631 :::* LISTEN 1181/cupsd tcp6 0 0 :::5500 :::* LISTEN 1825/vinagre udp 0 0 0.0.0.0:52537 0.0.0.0:* 960/avahi-daemon: r udp 0 0 0.0.0.0:68 0.0.0.0:* 1834/dhclient udp 0 0 0.0.0.0:69 0.0.0.0:* 3556/xinetd # It's Here!! udp 0 0 0.0.0.0:5353 0.0.0.0:* 960/avahi-daemon: r 




提示:安全性
根据 man 8 tftpd 的描述:

... The use of tftp(1) does not require an account or password on the remote system. Due to thelack of authentication information, tftpd will allow only publicly read‐ able files to be accessed. Files may be written only if they already exist and are publicly writable.Note that this extends the concept of “public” to include all users on all hosts that can be reached through the network; this may not be appropriate on all systems, and its implications should be considered before enabling tftp service.The server should have the user ID with the lowest possible privilege....

因此,建议:
1.为tftpd降低UID权限(本文已经将UID设置成nobody)
2.在不使用tftp服务的时候关闭它(disable = yes)
3.为该端口(UDP:69)配置防火墙,阻止外网访问


注意: 1:如果出现permission denied 错误  则是操作者权限不够,
需要提升权限
su  root
输入密码后就可以正常进行tftp传输操作了

2:如果出现Access violation错误 则是文件权限没有解开,
将要操作的文件操作权限全解开就可以了
chmod 777 文件名   或者666也可以

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值