Ubuntu中有三个常用tftp服务器:atftpd,tftpd,hpa;
安装hpa过程:
自建tftp目录:sudo mkdir /home/tftp
修改目录属性:sudo chmod 777 /home/tftp
tftpd-hpa 是一个功能增强的TFTP服务器。它提供了很多TFTP的增强功能,它已经被移植到大多数的现代UNIX系统。
安装
使用下面的命令来安置 tftpd-hpa 服务器:
$ sudo apt-get install tftpd-hpa
注:若server未安装xinetd则在Ubuntu10.04中会自动下载openbsd-inetd并安装,使用tftp过程中出错很多时候是因xinetd版本问题;
配置
tftp-hpa 的配置文件为 /etc/default/tftpd-hpa
#Defaults for tftpd-hpa
RUN_DAEMON="yes" #默认为"no",tftp不能启动;
OPTIONS="-l -c -s /home/tftp"
#/home/tftp为你设定目录,-c可创建新文件,在很多资料中执行的命令或配置tftp文件中都缺少-c这个参数,如:sudo in.tftpd -l -c -s
/home/tftp,put命令会出错提示;
注意要修改目录属性:chmod 777 /home/tftp
启动和停止
启动
# /etc/init.d/tftpd-hpa start
停止
# /etc/init.d/tftpd-hpa stop
校验:ps -A|grep tftp
删除服务:sudo apt-get remove tftpd-hpa tftp-hpa --purge
测试
在/home/tftproot下随便创建个文件,然后登录tftp,能get下来就OK了。
以下指令时链接本地tftp服务器并get一个已存在文件。
stv@super:~/workspace$ tftp 127.0.0.1
tftp> get test.txt
Received 12 bytes in 0.0 seconds
tftp> quit
选项参考
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.