现在的位置: 首页 > 综合 > 正文

tftp配置

2017年12月20日 ⁄ 综合 ⁄ 共 6229字 ⁄ 字号 评论关闭

重点:

1. /etc/xinetd.d/tftp

service tftp
{
     disable = no
     socket_type      = dgram
     protocol             = udp
     wait                     = yes
     user              = root
     server           = /usr/sbin/in.tftpd
     server_args      = -s /tftpboot -c(-c表示允许上传)
     per_source       = 11
     cps          = 100 2
}

 

2、修改/etc/inetd.conf

tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot

 

3.配置一下 /etc/default/tftpd-hpa,就可以了
#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /home/ttk/tftpboot"

 

4. sudo chmod 777 /var/lib/tftpboot

 

5. 1) $ /etc/init.d/xinetd restart

    2) $  in.tftpd -l /var/lib/tftpboot

 

 

以下转载:

http://hi.baidu.com/wangy0919/blog/item/3808eaa1388bd389471064c2.html

 

ubuntu中有三个tftp服务器:atftpd,tftpd,还有一个hpa的。我自己试了一下tftpd和inetd的这一种,其他的在网上也看到一些资料,但是没有尝试,姑且记录在后面。

首先说说我正在使用的这一种:
1. 首先安装tftp和tftpd,前者是客户端,后者是服务器。因为tftp是要inetd来控制的,而debian类的系统,默认是没有安装inetd的,安装一下。(我第一次失败了就是因为没有安装正确的inetd)
sudo apt-get install tftp tftpd
sudo apt-get install netkit-inetd

2、在/目录下建一个tftpboot, 把属性改成777。

cd /
sudo mkdir tftpboot
sudo chmod 777 tftpboot

3、修改/etc/inetd.conf

tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
#:INTERNAL: Internal services
#e cho            stream tcp      nowait root     internal
#e cho            dgram    udp      wait     root     internal
#chargen         stream tcp      nowait root     internal
#chargen         dgram    udp      wait     root     internal
#discard         stream tcp      nowait root     internal
#discard         dgram    udp      wait     root     internal
#daytime         stream tcp      nowait root     internal
#daytime         dgram    udp      wait     root     internal
#time            stream tcp      nowait root     internal
#time            dgram    udp      wait     root     internal
#tftp            dgram    udp      wait     nobody /usr/sbin/tcpd/usr/sbin/in.tftpd/tftpboot

4、重新加载inetd进程
sudo /etc/init.d/inetd reload

这样就可以了。还有两种方法,没试过,但是应该可以:
一. 使用xinetd而不是,修改xinetd.conf如下所示:
service tftp
         {
             disable     =no
             socket_type     =dgram
             protocol     =dup
             wait         =yes
             user         =root
             server         =/usr/sbin/in.tftpd
             server_args     =-s /tftpboot
         }

二.安装tftpd-hpa和tftpd-hpa
配置一下 /etc/default/tftpd-hpa,就可以了
#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /home/ttk/tftpboot"

 

 

步骤:
         1:$sudo aptitude install tftpd    获得tftpd的包,并且安装
         2: 安装完毕后参考了《X-Hyper255B:Xscale PXA255 Evaluation Board》中关于TFTP的内容,creating tftp file:
         creat /etc/xinetd.d/tftp file and configure as follows
         if this file exists already, you don't have to create again.
         /etc/xinetd.d/tftp
         service tftp
         {
             disable     =no
             socket_type     =dgram
             protocol     =dup
             wait         =yes
             user         =root
             server         =/usr/sbin/in.tftpd
             server_args     =-s /tftpboot
         }
         caution:if server_args is set to tftpboot,only the file in
/tftpboot directory of th host PC can be transferred when downloading
from Bootloader.
         restart the PC after modifying.

 

1. sudo apt-get install tftp-hpa tftpd-hpa

2. cd /
       sudo mkdir /tftpboot
        sudo chmod 777 /tftpboot

3. sudo in.tftpd -l /tftpboot
     这样tftp服务器就启动了,下面可以做一个测试

4. cd /tftpboot
     touch test
     建立一个文件

5. cd /home/usrname
     登录另一个目录

6. tftp 192.168.0.59
     换成自己的ip

    > get /tftpboot/test

如果能够得到文件,那么就成功了。

PS:不要忘了 sudo apt-get install xinetd
                          
           sudo apt-get install   netkit-inetd

关于不能上传(put)的解决

打开目录 /etc/xinetd.d/
新建文件tftp
tftp内容:

service tftp
{
     disable = no
     socket_type      = dgram
     protocol             = udp
     wait                     = yes
     user              = root
     server           = /usr/sbin/in.tftpd
     server_args      = -s /tftpboot -c
     per_source       = 11
     cps          = 100 2
}

重新启动服务:

sudo /etc/init.d/xinetd restart

sudo in.tftpd -l /tftpboot

安装过程中出现的问题及原因
现象一:
tftp> get test.log
Transfer timed out.
原因:
tftpd服务没有启动

现象二:
tftp> get test.log
Error code 2: Only absolute filenames allowed
原因:
在/etc/xinetd.d/tftpd中设置的server_args为/etc/default/tftpd-hpa
cat /etc/default/tftpd-hpa
#Defaults for tftpd-hpa
RUN_DAEMON="no"
OPTIONS="-s /home/tftpd -c -p -U 077 -u tftpd"
设置的时候只要将server_args=改为你自己设定的服务器文件夹就行了

 

现象三:
tftp> put ex070416.log
Error code 1: File not found
原因:
指定的文件不存在;或tftpd启动参数中没有指定-c选项,允许上传文件

 

1、安装程序
    sudo apt-get install xinetd
    sudo apt-get install   netkit-inetd
    sudo apt-get install tftp-hpa tftpd-hpa
2、建立tftp根目录
    cd /
    sudo mkdir /tftpboot
    sudo chmod 777 /tftpboot
3、修改/etc/inetd.conf
    sudo vim /etc/inetd.conf
    然后将inetd.conf内容修改为下面内容:
    tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot
4、重新加载inetd进程
    sudo /etc/init.d/inetd reload
5、启动tftp服务器
    sudo in.tftpd -l /tftpboot
6、测试是否成功
    cd /tftpboot
    touch test   //建立一个文件夹
   
    cd /home/usrname //登录另一个目录
   
    tftp 192.168.0.200 //换成自己的IP
    >get /tftpboot/test
    如果能得到文件,那么就成功了。

7、在服务器端设置
#vi /etc/xinetd.d/tftp
service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /test -c //test设置成你自己的tftpboot的目录
per_source = 11
cps = 100 2
flags = IPv4
}
#service xinetd restart 从启xinetd服务,因为TFTP服务受控与xinetd, xinetd是管服务的服务,它是不开端口的。

 

安装客户端:

  sudo apt-get install tftp-hpa

安装服务端:

     sudo apt-get install tftpd-hpa

安装inet :

     sudo apt-get install xinetd
sudo apt-get install netkit-inetd

在/目录下建一个tftpboot, 把属性改成777:

  cd /
sudo mkdir tftpboot
sudo chmod 777 tftpboot

在/etc/inetd.conf里添加 :

  #tftpd dgram udp wait root /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /tftpboot

重新加载inetd进程

  sudo /etc/init.d/inetd reload

打开目录 /etc/xinetd.d/
新建文件tftp
tftp内容:

service tftp
{
     disable = no
     socket_type      = dgram
     protocol             = udp
     wait                     = yes
     user              = root
     server           = /usr/sbin/in.tftpd
     server_args      = -s /tftpboot -c(-c表示允许上传)
     per_source       = 11
     cps          = 100 2
}

重新启动服务:

sudo /etc/init.d/xinetd restart

sudo in.tftpd -l /tftpboot

测试一下,在/tftpboot文件夹下新建立一个文件

  touch abc

进入另外一个文件夹

  tftp *.*.*.*(自己IP)
tftp> get abc

附录:

inetd (Internet 超级服务器 )
     inetd是监视一些网络请求的守护进程,其根据网络请求来调用相应的服务进程来处理连接请求。它可以为多种服务管理连接,当 inetd
接到连接时,它能够确定连接所需的程序,启动相应的进程,并把 socket 交给它 (服务 socket 会作为程序的标准输入、
输出和错误输出描述符)。 使用 inetd 来运行那些负载不重的服务有助于降低系统负载,因为它不需要为每个服务都启动独立的服务程序。
      一般说来, inetd 主要用于启动其它服务程序,但它也有能力直接处理某些简单的服务, 例如 chargen、 auth, 以及 daytime。

     inetd 是通过rc系统启动的。 inetd_enable 选项默认设为 NO,但可以在安装系统时, 由用户根据需要通过 sysinstall 来打开。

     inetd.conf则是inetd的配置文件。
inetd.conf文件告诉inetd监听哪些网络端口,为每个端口启动哪个服务。在任何的网络环境中使用Linux系统,第一件要做的事就是了解一下
服务器到底要提供哪些服务。不需要的那些服务应该被禁止掉,最好卸载掉,这样黑客就少了一些攻击系统的机会。查看
“/etc/inetd.conf”文件,了解一下inetd提供哪些服务。用加上注释的方法(在一行的开头加上#号),禁止任何不需要的服务,再给
inetd进程发一个SIGHUP信号。

抱歉!评论已关闭.