UBUNTU下TFTP服务器搭建

来源:互联网 发布:medusa软件 编辑:程序博客网 时间:2024/05/17 09:34
在作uboot及内核的移植实验时,考虑到效率,我们经常将内核映像通过网线使用tftp下载到板子的内存中,然后运行测试。uboot自带有tftp的相关支持,我们还需要在主机端搭建tftp服务器。
简单介绍下我们接下来要安装的三个包:
xinetd:xinetd是一个守护进程,用于处理对各种服务的请求,当xinetd监控的服务请求出现时,xinetd会使用/etc /xinetd.conf文件 读取/etc/xinetd.d目录中的配置文件,然后,根据所请求服务的xinetd.conf文件内容,启动相应的程序.
tftpd: 服务端
tftp:客户端


具体安装步骤如下:
1.下载安装软件包
sudo apt-get install tftp-hpa tftpd-hpa //分别下载tftp客户与服务器端
sudo apt-get install xinetd //该系统进程
2.准备一个tftp服务器目录:(这里我们将建立”/tftpboot”作为服务器目录,这里存放希望发送的文档)
(1). cd /
      sudo mkdir /tftpboot
      sudo chmod 777 /tftpboot (修改服务器目录的访问权限属性)


(2). cd /tftpboot
    touch test (建立一个空的测试文档)
3.修改服务器相关配置:
打开/etc/default/tftpd-hpa,默认配置如下:
#Defaults for tftpd-hpa
RUN_DAEMON="no"
OPTIONS="-l -s /var/lib/tftpboot"
修改后的设置应该如下:
#Defaults for tftpd-hpa
RUN_DAEMON="yes"
OPTIONS="-l -s /home/zdreamx/tftpboot"
其中/home/zdreamx/tftpboot是自己设定的目录,可以根据情况修改。


选项参考说明:(这部分帮组理解配置'OPTIONS'的,与修改无关可以不看)
OPTIONS
-l Run the server in standalone (listen) mode, rather than run from
inetd. In listen mode, the -t option is ignored, and the -a
option can be used to specify a specific local address or port
to listen to.


-a [address][:port]
Specify a specific address and port to listen to when called
with the -l option. The default is to listen to the tftp port
specified in /etc/services on all local addresses.
listen 的 ip address 和 Port
-c Allow new files to be created. By default, tftpd will only
allow upload of files that already exist. Files are created
with default permissions allowing anyone to read or write them,
unless the -p or -U options are specified.


-s (决定tftp根目录)Change root directory on startup. This means the remote host
does not need to pass along the directory as part of the trans-
fer, and may add security. When -s is specified, exactly one
directory should be specified on the command line. The use of
this option is recommended for security as well as compatibility
with some boot ROMs which cannot be easily made to include a
directory name in its request.
4.重新启动服务:
sudo /etc/init.d/xinetd restart
sudo in.tftpd -l /tftpboot //在有些版本的ubuntu上必须使用此句来显示的启动tftp服务器。
5.本机测试服务器搭建是否成功:
(1) 进入另外的目录下:
cd /home/usrname 


(2) 访问本机tftp服务器:
tftp 127.0.0.1 


(3)获取测试文件:
   > get test


正常情况下,执行完上面这一句后就可以在当前目录下看到获取的test文件。至此,搭建tftp服务器的过程就完成了。


6.安装过程中可能出现的问题及原因:


现象一:


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选项,允许上传文件
原创粉丝点击