| |
tftp服务经常被嵌入式开发用来从主机和目标板之间传输,和烧录文件,此文介绍了基本的建立tftp服务的方法和实践:
文章使用了两种不同的linux host,debain(5)和ubuntu (10.10),分别成功实现和目标板的tftp的连接
ubuntu 下方法
apt-get install tftpd-hpa tftp-hpa
tftp-hpa是客户端,tftpd-hpa是服务器端
因为tftp是要inetd来控制的,而ubuntu或debian类的系统,默认是没有安装inetd的,所以一般要再安装一下:
debian下方法
apt-get install tftpd tftp xinetd
有关于xinetd,如果你希望在ubuntu下也用的话,安装的时候,因为xinetd有两个版本,所以会提示你须选择:
我们这里选择了下面这个:
apt-get install inetutils-inetd
还有一个是apt-get install netkit-inetd
有些方法是用rpm包安装没有实践过:
redhat下方法
在redhat9的CD3里可以找到tftp-server-0.32-4.i386.rpm文件
[root@gliethttp root]# rpm -ivh tftp-server-0.32-4.i386.rpm
2 在linux host机器上建立tftp的服务器根目录,一般可以命名为:tftpboot,
为了以后调试方便,tftp,nfs,samba等工作目录一般都放在自己的工作目录下,我的是 /home/wine/
root@ubuntu:/home/wine# mkdir tftpboot
root@ubuntu:/home/wine# chmod 777 tftpboot/
ubuntu 下方法 修改文件
vim /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
#TFTP_DIRECTORY="/var/lib/tftpboot" 改为 -->
TFTP_DIRECTORY="/home/wine/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
#TFTP_OPTIONS="--secure" 改为-->
TFTP_OPTIONS="-l -c -s"
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.
debian下方法
31 检查一下配置文件的权限:
stat /etc/inetd.conf
File: `/etc/inetd.conf'
Size: 1139 Blocks: 8 IO Block: 4096 regular file
Device: 801h/2049d Inode: 167025 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-10-25 22:03:34.803054929 -0700
Modify: 2012-10-25 22:02:58.983057568 -0700
Change: 2012-10-25 22:02:59.035057567 -0700
32 权限ok话,做如下修改:
加入:tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /home/wine/tftpboot 到文件/etc/inetd.conf里面
注意我的是 /home/wine/下工作目录
redhat下方法
修改如下文件,当然如果没有你可能需要重新建一个
[root@gliethttp root]# vim /etc/xinetd.d/tftp
将server_args配置项为你自己的tftpboot根目录
将disable 配置为no
service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}
ubuntu 下方法
service tftpd-hpa restart
debian下方法
sudo /etc/init.d/inetd reload
sudo /etc/init.d/xinetd restart
其他可能需要的服务:
1 cd /etc/init.d/
./inetutils-inetd restart
2 sudo in.tftpd -l /tftpboot
51 我的主机本机host地址:192.168.0.1
$ cd /home/wine/tftpboot/
$ echo "hello tftp service">>a.txt #生成一个测试文件,在tftp root 文件夹下
$cd /home/wine
$echo "hello tftp service,put to tftp serive">>send.text #在tftp root文件夹外做一个文件准备传进去
root@ubuntu:/home/wine# tftp 192.168.0.1
tftp 192.168.0.1
tftp> get a.txt
tftp> q
root@ubuntu:/home/wine# ls
ls
a.txt send.text tftpboot
可以看到a.txt已经传输过来了,然后我们要检查一下他的内容,因为错误传输,也会生出一个同名空文件
root@ubuntu:/home/wine# vim a.txt
vim a.txt
没问题的话,再往里面传一个
root@ubuntu:/home/wine# tftp 192.168.0.1
tftp 192.168.0.1
tftp> put send.txt
tftp: send.txt: No such file or directory
tftp> put send.text
tftp> q
root@ubuntu:/home/wine# cd tftpboot/
cd tftpboot/
root@ubuntu:/home/wine/tftpboot# ls
ls
a.txt send.text test vmlinux.in
52 tftp tftpserver.test.net
6.1 serverip
set serverip 192.168.0.1
6.2 bootcmd
bootcmd=tftp vmlinux.bin; go [系统启动RAM地址] #这里假设要烧kernel
使用tftp下载linux kernel到目标板:
1 生成kernel编译
2 cp 生成的kernel文件vmlinux,到tftp的root文件夹:/home/wine/tftpboot
3 上电启动打印:
and the test passed in uboot log:
TFTP from server 192.168.0.1; our IP address is 你的板子的ip地址
Filename 'vmlinux.bin'.
Load address: 【你的地址启动】
Loading: #################################################################
#################################################################
#################################################################
ref:
http://lesca.me/archives/set-up-tftp-server-on-ubuntu.html
http://www.cnblogs.com/shenhaocn/archive/2011/03/13/1983042.html
http://hi.baidu.com/yjicllignqbkovq/item/b257179368e6c1d97b7f0123
http://my.opera.com/volans/blog/show.dml/680197
http://doc.chinaunix.net/linux/201208/2311353.shtml
the settings for ineted.conf file
http://www.faqs.org/docs/securing/chap5sec36.html
1 iptables
如果关不掉,直接卸载:sudo apt-get remove iptables
2 服务器地址错误,或者连接硬件问题
3