通过这个实验,我明白了tftp一些基本的概念问题. 知道如何正确的进行上传和下载.这个实验说明了,root下,在tftpboot下,具有666的文件,才能被覆盖掉. 深刻体会了chmod 的用法. 也明白了读说明书的重要性.反应了我对英文说明书,还是读的能力不够. Ubuntu 的 openbsd-inetd 預設將 tftpd 的路徑指定為 ============================= 准备条件设置方法: 参考realarm的说明书。 。。。 ================================== ubuntu10。04虚拟机的情况是: root@ubuntu:/home/zhangbin# uname -a Linux ubuntu 2.6.32-26-generic #47-Ubuntu SMP Wed Nov 17 15:59:05 UTC 2010 i686 GNU/Linux ================================== 第一步:安装tftp tftpd 软件包root@ubuntu:/home/zhangbin# apt-get install tftp tftpd 前者是客户端,后者是服务程序。 Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: openbsd-inetd 附带有这个软件包安装 The following NEW packages will be installed: openbsd-inetd tftp tftpd 0 upgraded, 3 newly installed, 0 to remove and 121 not upgraded. Need to get 71.1kB of archives. After this operation, 311kB of additional disk space will be used. Do you want to continue [Y/n]? y Get:1 http://Ubuntu./ubuntu/ lucid/universe tftp 0.17-17ubuntu1 [17.6kB] Get:2 http://Ubuntu./ubuntu/ lucid/main openbsd-inetd 0.20080125-4ubuntu2 [37.0kB] Get:3 http://Ubuntu./ubuntu/ lucid/universe tftpd 0.17-17ubuntu1 [16.5kB] Fetched 71.1kB in 0s (135kB/s) Selecting previously deselected package tftp. (Reading database ... 143343 files and directories currently installed.) Unpacking tftp (from .../tftp_0.17-17ubuntu1_i386.deb) ... Selecting previously deselected package openbsd-inetd. Unpacking openbsd-inetd (from .../openbsd-inetd_0.20080125-4ubuntu2_i386.deb) ... Selecting previously deselected package tftpd. Unpacking tftpd (from .../tftpd_0.17-17ubuntu1_i386.deb) ... Processing triggers for man-db ... Processing triggers for ureadahead ... ureadahead will be reprofiled on next reboot Setting up tftp (0.17-17ubuntu1) ... Setting up openbsd-inetd (0.20080125-4ubuntu2) ... * Stopping internet superserver inetd [ OK ] * Not starting internet superserver: no services enabled Setting up tftpd (0.17-17ubuntu1) ... 所以一共是安装了三个软件包。 tftd 服务程序 tftp 客户端程序 openbsd-inetd inetd服务器的debian移植版本。 =========================================== 关于penbsd的inetd软件包的说明如下: OpenBSD 互联网超级服务器 inetd 服务器是一个专门管理入网连接的网络后台程序.它的配置文件定义了当收到入 网连接时运行什么程序.任何服务端口都可以用TCP或UDP协议配置. 这是一个有 Debian 专用特色的 OpenBSD 后台移植版.该软件包支持 IPv6,内建的 libwrap 访问控制,绑定到特定地址,UNIX 域套接字和套接字缓冲调解. ================================================= 第二步: 配置root@ubuntu:~# vi /etc/inetd.conf ================================================== 第三步 : 新建/tftpboot文件夹文件夹的权限如下: root@ubuntu:~# ls -l total 4 drwxrwxrwx 2 root root 4096 2011-02-27 18:37 tftpboot root@ubuntu:~# ll tftpboot total 8 drwxrwxrwx 2 root root 4096 2011-02-27 18:37 ./ drwx------ 19 root root 4096 2011-02-27 18:38 ../ 据说要改写这个命令。 tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot 我并没有使用这个命令,而是重新加载inetd进程: sudo /etc/init.d/inetd reload 重启inetd服务的几种方法:openbsd-inetd是个可执行文件。 root@ubuntu:/etc/init.d# openbsd-inetd restart openbsd-inetd: command not found root@ubuntu:/etc/init.d# ./openbsd-inetd restart * Restarting internet superserver inetd [ OK ] root@ubuntu:/etc/init.d# 这样是可行的: root@ubuntu:~/tftpboot# sudo /etc/init.d/openbsd-inetd restart * Restarting internet superserver inetd [ OK ] root@ubuntu:~/tftpboot# ========================= 这个命令,不知道做什么的。 root@ubuntu:/etc/init.d# in.tftpd -l /tftpboot in.tftpd自己也是个命令. 一些操作细节中的知识点和遇到的问题的解决办法(1)=================================== 关于tftpd查询了下帮助手册: TFTPD(8) BSD System Manager's Manual TFTPD(8) NAME tftpd — DARPA Trivial File Transfer Protocol server tftp 普通文件传送协议(Trivial File Transfer Protocol) SYNOPSIS tftpd [-n] [-s] [directory ...] DESCRIPTION Tftpd is a server which supports the DARPA Trivial File Transfer Proto‐ col. The TFTP server operates at the port indicated in the ‘tftp’ ser‐ vice description; see services(5). The server is normally started by inetd(8). The use of tftp(1) does not require an account or password on the remote system. Due to the lack of authentication information, tftpd will allow only publicly readable files to be accessed. Files may be written only if they already exist and are publicly writable. Note that this extends the concept of “public” to include all users on all hosts that can be reached through the network; this may not be appropriate on all systems, and its implications should be considered before enabling tftp service. The server should have the user ID with the lowest possible privilege. Access to files may be controlled by invoking tftpd with a list of direc‐ tories by including pathnames as server program arguments in /etc/inetd.conf. In this case access is restricted to files whose names are prefixed by the one of the given directories. If no directories are supplied the default is /tftpboot. To give out access to the whole filesystem, should this be desired for some reason, supply / as an argu‐ ment. Unfortunately, on multi-homed systems, it is impossible for tftpd to determine the address on which a packet was received. As a result, tftpd uses two different mechanisms to guess the best source address to use for replies. If the socket that inetd(8) passed to tftpd is bound to a par‐ ticular address, tftpd uses that address for replies. Otherwise, tftpd uses ``UDP connect'' to let the kernel choose the reply address based on the destination of the replies and the routing tables. This means that most setups will work transparently, while in cases where the reply address must be fixed, the virtual hosting feature of inetd(8) can be used to ensure that replies go out from the correct address. These con‐ siderations are important, because most tftp clients will reject reply packets that appear to come from an unexpected address. The options are: -n Suppresses negative acknowledgement of requests for nonexistent relative filenames. -s All absolute filenames are treated as if they were preceded by the first directory argument, or /tftpboot if there is none. SEE ALSO tftp(1), inetd(8) HISTORY The tftpd command appeared in 4.2BSD. Linux NetKit (0.17) July 29, 2000 Linux NetKit (0.17) (2)========================================== 安装inetd的目的是为了控制tftp的运行。只这样是不行的,因为tftp是要inetd来控制的,而ubuntu或debian类的系统,默认是没有安装inetd的,安装一下: root@ubuntu:/etc/init.d# apt-get install netkit-inetd Reading package lists... Done Building dependency tree Reading state information... Done Package netkit-inetd is a virtual package provided by: inetutils-inetd 2:1.6-3 openbsd-inetd 0.20080125-4ubuntu2 You should explicitly select one to install. E: Package netkit-inetd has no installation candidate 这个包,ubuntu是通过自己的包来提供的. (3)============================================================================= tftp传输文件需要给文件设置权限,这个报错的一个原因是位置错了,参看(5)出现了Error code 2: Access violation的错误. root@ubuntu:~# cd t* root@ubuntu:~/tftpboot# ls root@ubuntu:~/tftpboot# touch test root@ubuntu:~/tftpboot# ls test root@ubuntu:~/tftpboot# tftp 127.0.0.1 tftp> get test Error code 2: Access violation tftp> tftpboot是给了 777的权限的. tftpboot下的test文件,也给了666的权限. (4)========================== 通过natstat和grep命令查看tftpd是否运行root@ubuntu:~/tftpboot# netstat -a | grep tftp udp 0 0 *:tftp *:* 看上去tftp是在运行的. (5)============================== 原因是,我/tftpboot文件,应是在/下,我把它放在了/root下。 改为/tftpboot就行了。 ================================================ (6)文件存取访问要注意的问题【1】tftp的使用,,在任何一个目录下,使用tftp的客户端,访问某个ip的机子上的tftp服务器,访问这个ip的tftpboot目录下的文件。 因此,我在/home/zhangbin下,获取/tftpboot下的hello.txt文件。使用的是get命令。获取成功。 下载文件成功. root@ubuntu:/home/zhangbin# vi /tftp/hello.txt root@ubuntu:/home/zhangbin# vi /tftpboot/hello.txt root@ubuntu:/home/zhangbin# tftp 127.0.0.1 tftp> get hello.txt Received 34 bytes in 0.0 seconds tftp> q 退出 tftpd的命令 root@ubuntu:/home/zhangbin# ls 7.wma ear.mpg hello.txt new.txt tftp.txt code examples.desktop HetNet.wmv oldboy.flv tutorial01 DawnLightPlayer ffmpegjt.c jgs.mp3 oldboy.mp4 tutorial02 Desktop ffmpeg截图.c main.cc out.txt tutorial03 DLP-SVN frame1.ppm manffplay.txt pan.rmvb tutorial08 Documents frame2.ppm man-kill.txt Pictures Videos dodge.mpg frame3.ppm man-ps.txt Public wavplay Downloads frame4.ppm man-xargs.txt rjsq.wav whatsInside.wav ear frame5.ppm Music Templates x264 root@ubuntu:/home/zhangbin# cat hello.txt hello hello hello hellp ehll =============================== 【2】上传文件失败,文件权限报错的解决办法(解决办法见 下面的 3)) 想吧new.txt上传到tftp服务器中。 Error code 2: Access violation 错误。 /////////////////////////////////////// 1)看了下文件权限: new.txt应该是666的。 -rw-rw-rw- 1 root root 30278 2011-01-30 06:16 new.txt 还是报错:
root@ubuntu:/home/zhangbin# tftp 127.0.0.1 tftp> put new.txt Error code 2: Access violation tftp> q 改成666,还是报错 root@ubuntu:/home/zhangbin# chmod 666 new.txt root@ubuntu:/home/zhangbin# tftp 127.0.0.1 tftp> put new.txt Error code 2: Access violation tftp> ============
重新来
新建立了一个0字节的文件,abc.txt,还是失败.
root@ubuntu:/home/zhangbin# vi abc.txt
root@ubuntu:/home/zhangbin# cat abc.txt
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put abc.txt
Error code 2: Access violation
tftp> q
更改权限666,也不行.
root@ubuntu:/home/zhangbin# chmod 666 abc.txt
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put abc.txt
Error code 2: Access violation
tftp>
更改权限777,还是不行.
root@ubuntu:/home/zhangbin# chmod 777 abc.txt
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put abc.txt
Error code 2: Access violation
tftp> q
=============================
2)从tftpboot找问题,
目录d 权限755
drwxr-xr-x 2 root root 4096 2011-02-27 19:11 tftpboot
更改d权限777
root@ubuntu:/# chmod 777 tftpboot
上传new.txt,还是不行.
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put new.txt
Error code 2: Access violation
tftp>
重启tftpd服务
root@ubuntu:/home/zhangbin# /etc/init.d/openbsd-inetd restart
* Restarting internet superserver inetd [ OK ]
不行
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put new.txt
Error code 2: Access violation
说明了不是tftpboot权限,也不是要上传的文件的权限的问题
=========================
3)参考了文章之后,明白了一点,就是tftp服务器,默认规则是可以下载,但是上传文件的话,
必须在tftpboot中,有一个相同名字的文件,而且具备相应的可读写(覆盖)的权限.这样才能上传文件.
实验一下:
在tftpboot中,创建new.txt,忘记改写权限.
上传失败.
root@ubuntu:/home/zhangbin# vi /tftpboot/new.txt
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put new.txt
Error code 2: Access violation
tftp> q
root@ubuntu:/home/zhangbin# ls /tftpboot/
hello.txt new.txt test test.txt
改写了权限之后,上传就成功了.
root@ubuntu:/home/zhangbin# chmod 777 /tftpboot/new.txt
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put new.txt
Sent 30319 bytes in 0.0 seconds
tftp>
========================================
4)文件必须是644的权限。
root下,新建一个文件,001.txt,打算上传到tftp中.
root@ubuntu:/home/zhangbin# vi 001.txt
创建之后的权限是644,就是root可以读写,group和others只能读.
root@ubuntu:/home/zhangbin# ls -l
total 552872
-rw-r--r-- 1 root root 8 2011-02-27 20:12 001.txt
再在/tftpboot中,创建一个同名的
root@ubuntu:/home/zhangbin# vi /tftpboot/001.txt
权限默认是644,感觉,用root执行上传,可以覆盖.
root@ubuntu:/home/zhangbin# ls -l /tftpboot/
total 36
-rw-r--r-- 1 root root 0 2011-02-27 20:14 001.txt
试试
居然不行
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put 001.txt
Error code 2: Access violation
tftp>
tftpboot下的文件,改成666
root@ubuntu:/home/zhangbin# chmod 666 /tftpboot/001.txt
root@ubuntu:/home/zhangbin# ls -l /tftpboot/
total 36
-rw-rw-rw- 1 root root 0 2011-02-27 20:14 001.txt
可以了
root@ubuntu:/home/zhangbin# tftp 127.0.0.1
tftp> put 001.txt
Sent 10 bytes in 0.0 seconds
tftp>
这个实验说明了,root下,在tftpboot下,具有666的文件,才能被覆盖掉./////////////////////////////////////// 参考文章和用到的知识如下====================下面是我参考的一些文章=============================================
这个问题,参考了这位大牛的文章
原文链接:http://os.51cto.com/art/201001/176508.htm 在向大家详细介绍tftp之前,首先让大家了解下Ubuntu tftp,然后全面介绍Ubuntu tftp,希望对大家有用。Ubuntu 团队对它的使用者公开的承诺:Ubuntu 永远免费 , 并且对于 "企业版本" 没有任何额外的费用, 在同样的自由团队上,将最好的工作成果带给每一个人。 配置Ubuntu tftp服务的步骤: 1、安装相关软件包:Ubuntu tftp(服务端),tftp(客户端),xinetd 2、建立配置文件 3、建立Ubuntu tftp服务文件目录(上传文件与下载文件的位置),并且更改其权限 4、重新启动服务 通过get命令,可以把当前目录下的test.txt文件,通过Ubuntu tftp上传到它的服务文件目录。这时,在/tftpboot下面会出现test.txt文件。通过put命令,可以从/tftpboot下,下载 test.txt文件。这样就验证了Ubuntu tftp服务配置的正确性。当文件上传与下载结束后,可以通过quit命令退出。严格按照以上步骤配置Ubuntu tftp服务,一般都可以成功。如果出现无法get或者put的时候,可以查看一下防火墙是否关闭。 如果从tftp服务器下载失败, 要确保服务器的根目录有可执行的权限。 $ chmod -R 777 tftp
$ tftp 192.168.1.222 可是上传文件不成功, 提示错误: tftp> put dic.txt 求助于google, 得下面一段说明,问题解决。 The tftp man page says: Because there is no user-login or validation within the TFTP So apparently the site you're trying to get the file from has some 上面主要意思就是: tftp服务器缺少必要的身份验证, 所以默认只允许下载文件,要上传文件,必须是服务器中已存在同名的文件, 且该文件权限允许被覆盖。
$ touch dic.txt $ chmod 777 dic.txt 重新上传,成功。 在网上看到有人配/etc/default/tftp,/etc/inetd.conf这些文件,实际上没这么复杂,用tftp和tftpd,加上xinetd监控,只需要配/etc/xinetd./tftp即可。 =========== 也有牛人说 http://yuanfarn./search/label/Linux 在 Ubuntu 上安裝 tftpd 伺服器是一件非常簡單的事,首先執行以下這個指令安裝需要的套件:
然後再執行以下的指令啟動 openbsd-inetd:
基本上,這樣就可以使用 tftpd 了。不過,由於 Ubuntu 的 openbsd-inetd 預設將 tftpd 的路徑指定為 =============================================================== 参考了http://bbs./thread-655364-1-1.html 参考了这篇文章 tftp程序,对ubuntu用户来讲,配置这个不是很友好。 ===================================================== http://hi.baidu.com/%B0%D9%B8%F6%C8%AB%CA%E9/blog/item/0cb018ffec018e49d6887deb.html
|
|