ubuntu10.04/12.10下安装tftp

本文详细介绍如何在Ubuntu系统上安装、配置并测试TFTP服务器,包括安装tftpd-hpa和tftp-hpa软件包、配置服务器参数、启用xinetd服务管理等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1步,连接网络,下载tftpd-hpa(服务器),tftp-hpa(客户端)也可以通过ubuntu桌面版的新立得安装,搜索tftp

#sudo apt-get install tftpd-hpa tftp-hpa

//该命令安装tftpd-hpatftp-hpa

 

2步,配置tftpd-hpa配置文件该文件在/etc/default/中,用vim/vi打开,编辑如下:

(个人感觉vim比vi好用,如果没有可以#sudo apt-get install vim 安装)

#vim /etc/default/tftpd-hpa

 

# /etc/default/tftpd-hpa为配置文件需要修改自己的目录

TFTP_USERNAME="tftp"

TFTP_DIRECTORY="/home/kingdz/tftpboot"  //此为自己设定的目录

TFTP_ADDRESS="0.0.0.0:69"

TFTP_OPTIONS="-l -c -s"  //-c是创建,-s读取文件,-l监听 相当于: TFTP_OPTION="--listen --create --secure"

 

:wq退出并保存

 

-c为可创建新文件,若无此参数,put命令则可能出现错误提示,此时只能覆盖原有文件不能创建新文件;无论何种方式配置tftp-server -c参数决定是否能正常写入数据;这里指定 tftpd使用的目录为/home/kingdz/tftpboot,注意要修改目录属性:chmod 777 tftpboot -llisten监听模式

下面是官方的具体参数设置介绍,不翻译了,没空。

Connect with IPv6 only, if compiled in.

-l,--listen

Run the server in standalone (listen) mode, rather than run frominetd. In listen mode, the--timeout option is ignored, and the--address option can be used to specify a specific local address or port to listen to.

--foreground,-L

Similar to--listen but do not detach from the foreground process. Implies--listen.

--address[address][:port],-a[address][:port]

Specify a specificaddress andport to listen to when called with the--listen or--foreground option. The default is to listen to thetftp port specified in/etc/services on all local addresses.

Please note: Numeric IPv6 adresses must be enclosed in square brackets to avoid ambiguity with the optional port information.

--create,-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--permissive or--umask options are specified.

--secure,-s

Change root directory on startup. This means the remote host does not need to pass along the directory as part of the transfer, and may add security. When --secure 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.

--userusername,-uusername

Specify the username whichtftpd will run as; the default is "nobody". The user ID, group ID, and (if possible on the platform) the supplementary group IDs will be set to the ones specified in the system permission database for this username.

--umaskumask,-Uumask

Sets theumask for newly created files to the specified value. The default is zero (anyone can read or write) if the--permissive option is not specified, or inherited from the invoking process if--permissive is specified.

--permissive,-p

Perform no additional permissions checks above the normal system-provided access controls for the user specified via the--user option.

--timeouttimeout,-ttimeout

When run frominetd this specifies how long, in seconds, to wait for a second connection before terminating the server.inetd will then respawn the server when another request comes in. The default is 900 (15 minutes.)

--retransmittimeout,-Ttimeout

Determine the default timeout, in microseconds, before the first packet is retransmitted. This can be modified by the client if thetimeout or utimeout option is negotiated. The default is 1000000 (1 second.)

--mapfileremap-file,-mremap-file

Specify the use of filename remapping. Theremap-file is a file containing the remapping rules. See the section on filename remapping below. This option may not be compiled in, see the output ofin.tftpd -V to verify whether or not it is available.

--verbose,-v

Increase the logging verbosity oftftpd. This flag can be specified multiple times for even higher verbosity.

--verbosityvalue

Set the verbosity value tovalue.

--refusetftp-option,-rtftp-option

Indicate that a specific RFC 2347 TFTP option should never be accepted.

--blocksizemax-block-size,-Bmax-block-size

Specifies the maximum permitted block size. The permitted range for this parameter is from 512 to 65464. Some embedded clients request large block sizes and yet do not handle fragmented packets correctly; for these clients, it is recommended to set this value to the smallest MTU on your network minus 32 bytes (20 bytes for IP, 8 for UDP, and 4 for TFTP; less if you use IP options on your network.) For example, on a standard Ethernet (MTU 1500) a value of 1468 is reasonable.

--port-rangeport:port,-Rport:port

Force the server port number (the Transaction ID) to be in the specified range of port numbers.

--version,-V

Print the version number and configuration to standard output, then exit gracefully.

安装后重新启动TFTP服务:

#sudo service tftpd-hpa restart

输出:tftpd-hpa start/running, process 2277

查看udp端口

#netstat -a | grep tftp

输出:udp 0 0 *:tftp *:*

 

3步,建立文件夹

#mkdir /home/kingdz/tftpboot

#chmod 777 tftpboot

 

4步,安装xinetdxinetd是新一代的网络守护进程服务程序,又叫超级Internet服务器,常用来管理多种轻量级Internet服务。

sudoapt-get install xinetd安装,xinetd安装好后在/etc/xinit.d/添加tftp文件,文件内容如下:进入到xinit.d目录下:#cd /etc/xinit.d/

命令格式#vim tftp或者#vi tftp

service tftp

{

socket_type = dgram

protocol = udp   //传输UDP协议

wait = yes

user = root  //登录身份

server = /usr/sbin/in.tftpd

server_args = -s /tftpboot    //服务器端默认的目录,在tftpd-hpa中有

disable = no      //打开

per_source = 11  //允许单个源链接的最大数

cps = 100 2     //最大连接数100,超过后关闭2秒

flags = IPv4   //网络协议标识

}

设置好后需要重新启动服务
#sudo service xinetd restart

#sudo service tftpd-hpa restart

 

测试:

tftpboot中放入一个文件如tt

如 vim tt

:

#include stdio.h

void main(void)

{

printf("This is the first program of Me\n");

}

wq


在其他目录下创建文件ss执行命令:

sudo tftp localhost

tftp->get tt //如果不提示任何错误,说明成功

tftp->put ss //如果不提示任何错误,说明成功

tftp->q   //退出程序

检查刚才文档下是否有tttftpboot下是否有ss

 

卸载:

sudo apt-get remove tftpd-hpa tftp-hpa --purge

 

 参考文献

http://ubuntuforums.org/showthread.php?t=1781224

http://www.360doc.com/content/11/0526/15/3038654_119540135.shtml

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值