ubuntu配置tftp服务

ubuntu配置TFTP服务:
 

  TFTP是用来下载远程文件的最简单的网络协议,基于UDP协议。xinetd是新一代的网络守护进程服务程序,经常用于管理多种轻量型internet服务。

  sudo apt-get install tftp-hpa
  sudo apt-get install tftpd-hpa(tftp-server)
  sudo apt-get install xinetd

  修改/etc/xinetd.d/tftp文件:

           # default: off

                 # description: The tftp server serves files using the trivial file transfer \

                 #       protocol.  The tftp protocol is often used to boot diskless \

               #       workstations, download configuration files to network-aware printers, \

              #       and to start the installation process for some operating systems.

             service tftp

           {

                  socket_type             = dgram

                  protocol                = udp

                 wait                    = yes

                 user                    = root

               server                  = /usr/sbin/in.tftpd

               server_args             = -s /tftpboot -c

              disable                 = no

             per_source              = 11

            cps                     = 100 2

             flags                   = IPv4

         }                   server_args=-s /var/lib/tftpboot  改为  server_args=-s /tftpboot/ -c

  配置tftpd-hpa:sudo vim /etc/default/tftpd-hpa 
         TFTP_USERNAME="tftp"
        TFTP_DIRECTORY="/tftproot"
         TFTP_ADDRESS="0.0.0.0:69"
        TFTP_OPTIONS=" -l -c -s"

  mkdir tftpboot  创建tftpboot(根目录下),然后在该目录下写一个测试文件(tftpd的参数里面direction写的是自己想要用于传输的文件位置,比如我的就是根目录下的/tftpboot)

  chmod 777 /tftpboot  


 
  service xinetd restart   重启xinetd

  查看tftp服务是否开启:netstat -a | grep tftp    显示结果:udp    0   0 *:tftp     *:*  表示服务已经开启,tftp配置成功

 
  进入另外一个目录,或者cd ~(主目录)

  sudo in.tftpd -l /tftpboot  启动tftp服务器

  sudo service tftpd-hpa restart

  tftp 本机的IP地址,然后在tftp命令行输入get或put命令  

   tftp localhost
  tftp>get 文件名  在服务器上下载文件
  tftp>put 文件名  上传文件到服务器上
  tftp>q             退出

 

 

出现的一些问题及原因(解决方法):

1、Transfer time out.    

  tftpd服务没有启动,如果还没有解决,可以试试换成桥接模式

2、Error code 0:Permission denied

  可能是由SELinux造成的,关掉它:
   
    修改文件/etc/sysconfig/selinux,设定SELINUX=disabled,然后重启电脑即可

  或者  执行命令system-config-securitylevel打开“安全级别配置”对话框,将SELinux(S)选项中“强制”改为“允许”

3、Error code 1:File not found

    指定的文件夹不存在;或tftpd启动参数中没有指定-c选项,允许上传文件

4、Error code 2:Only absolute filenames allowed

  /etc/xinetd.d/tftpd文件的设置没设好,只需要将server_args=  改为你自己设定   的服务器文件夹就行了

5、Error code 2:Access violation

    上传的文件要有相应的可读写(覆盖)的权限才能上传,要对文件的权限进行修改  chmod 777 a(文件名)

 

 


启动tftp服务器:

service tftpd-hpa stop      停止tftp服务器

service tftpd-hpa start     开启tftp服务器

service tftpd-hpa stutus    查看tftp运行状态

service tftpd-hpa restart   重启tftp服务器

 

(注意:文件传输后文件的权限会发生变化)

 

进入TFTP操作:

connect:连接到远程tftp服务器

mode:文件传输模式

put:上传文件

get:下载文件

quit:退出

verbose:显示详细的处理信息

tarce:显示包路径

status:显示当前状态信息

binary:二进制传输模式

ascii:ascii 传送模式

rexmt:设置包传输的超时时间

timeout:设置重传的超时时间

help:帮助信息

? :帮助信息

 

-g 表示下载文件 (get)

-p 表示上传文件 (put)

-l 表示本地文件名 (local file)

-r 表示远程主机的文件名 (remote file)

例如,要从远程主机192.168.1.2上下载 embedexpert,则应输入以下命令:

tftp -g -r embedexpert 192.168.1.2

 
 

 

 

原文地址:https://www.cnblogs.com/sakura029/p/5485420.html