首页 » Tutorials » 在Ubuntu上建立tftp服务器 ( Set up tftp server on Ubuntu )

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

作者: lesca 分类: Tutorials, Ubuntu, Web 发布时间: 2011-02-26 17:02 ė浏览 4,092 次 6Comments Off on 在Ubuntu上建立tftp服务器 ( Set up tftp server on Ubuntu )

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

  1. 安装ftpd以及相关软件包
  2. $ sudo apt-get install xinetd tftpd tftp
  3. 创建文件/etc/xinetd.d/tftp并且按如下所示配置
  4. service tftp
    {
    protocol		= udp
    port			= 69
    socket_type	= dgram
    wait			= yes
    user		= nobody
    server		= /usr/sbin/in.tftpd
    server_args	= /tftpboot
    disable		= no
    }
    
  5. 在系统根目录下创建tftproot目录,并修改权限
  6. $ sudo mkdir /tftpboot
    $ sudo chmod -R 777 /tftpboot
    $ sudo chown -R nobody /tftpboot
    
  7. 启动tftp服务
  8. $ sudo /etc/init.d/xinetd stop
    $ sudo /etc/init.d/xinetd start
    
  9. 测试:传输一个文件
  10. 本测试将先与本机连接,然后再传送一个已有的文件(例如hello.txt),通过观察文件的修改时间来确定是否传送成功。

    $ touch /tftpboot/hello.txt
    $ chmod 0777 /tftpboot/hello.txt 
    $ ls -l /tftpboot/
    total 0
    -rwxrwxrwx 1 lesca lesca 0 2011-02-26 16: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  #时间发生了变化,传送成功
    

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 the lack 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)配置防火墙,阻止外网访问

本文出自 Lesca技术宅,转载时请注明出处及相应链接。

本文永久链接: https://lesca.me/archives/set-up-tftp-server-on-ubuntu.html

Ɣ回顶部