|
通過(guò)這個(gè)實(shí)驗(yàn),我明白了tftp一些基本的概念問(wèn)題. 知道如何正確的進(jìn)行上傳和下載.這個(gè)實(shí)驗(yàn)說(shuō)明了,root下,在tftpboot下,具有666的文件,才能被覆蓋掉. 深刻體會(huì)了chmod 的用法. 也明白了讀說(shuō)明書的重要性.反應(yīng)了我對(duì)英文說(shuō)明書,還是讀的能力不夠. Ubuntu 的 openbsd-inetd 預(yù)設(shè)將 tftpd 的路徑指定為 ============================= 準(zhǔn)備條件設(shè)置方法: 參考realarm的說(shuō)明書。 。。。 ================================== ubuntu10。04虛擬機(jī)的情況是: 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 前者是客戶端,后者是服務(wù)程序。 Reading package lists... Done Building dependency tree Reading state information... Done The following extra packages will be installed: openbsd-inetd 附帶有這個(gè)軟件包安裝 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) ... 所以一共是安裝了三個(gè)軟件包。 tftd 服務(wù)程序 tftp 客戶端程序 openbsd-inetd inetd服務(wù)器的debian移植版本。 =========================================== 關(guān)于penbsd的inetd軟件包的說(shuō)明如下: OpenBSD 互聯(lián)網(wǎng)超級(jí)服務(wù)器 inetd 服務(wù)器是一個(gè)專門管理入網(wǎng)連接的網(wǎng)絡(luò)后臺(tái)程序.它的配置文件定義了當(dāng)收到入 網(wǎng)連接時(shí)運(yùn)行什么程序.任何服務(wù)端口都可以用TCP或UDP協(xié)議配置. 這是一個(gè)有 Debian 專用特色的 OpenBSD 后臺(tái)移植版.該軟件包支持 IPv6,內(nèi)建的 libwrap 訪問(wèn)控制,綁定到特定地址,UNIX 域套接字和套接字緩沖調(diào)解. ================================================= 第二步: 配置root@ubuntu:~# vi /etc/inetd.conf ================================================== 第三步 : 新建/tftpboot文件夾文件夾的權(quán)限如下: 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 ../ 據(jù)說(shuō)要改寫這個(gè)命令。 tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot 我并沒(méi)有使用這個(gè)命令,而是重新加載inetd進(jìn)程: sudo /etc/init.d/inetd reload 重啟inetd服務(wù)的幾種方法:openbsd-inetd是個(gè)可執(zhí)行文件。 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# ========================= 這個(gè)命令,不知道做什么的。 root@ubuntu:/etc/init.d# in.tftpd -l /tftpboot in.tftpd自己也是個(gè)命令. 一些操作細(xì)節(jié)中的知識(shí)點(diǎn)和遇到的問(wèn)題的解決辦法(1)=================================== 關(guān)于tftpd查詢了下幫助手冊(cè): TFTPD(8) BSD System Manager's Manual TFTPD(8) NAME tftpd — DARPA Trivial File Transfer Protocol server tftp 普通文件傳送協(xié)議(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的運(yùn)行。只這樣是不行的,因?yàn)閠ftp是要inetd來(lái)控制的,而ubuntu或debian類的系統(tǒng),默認(rèn)是沒(méi)有安裝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 這個(gè)包,ubuntu是通過(guò)自己的包來(lái)提供的. (3)============================================================================= tftp傳輸文件需要給文件設(shè)置權(quán)限,這個(gè)報(bào)錯(cuò)的一個(gè)原因是位置錯(cuò)了,參看(5)出現(xiàn)了Error code 2: Access violation的錯(cuò)誤. 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的權(quán)限的. tftpboot下的test文件,也給了666的權(quán)限. (4)========================== 通過(guò)natstat和grep命令查看tftpd是否運(yùn)行root@ubuntu:~/tftpboot# netstat -a | grep tftp udp 0 0 *:tftp *:* 看上去tftp是在運(yùn)行的. (5)============================== 原因是,我/tftpboot文件,應(yīng)是在/下,我把它放在了/root下。 改為/tftpboot就行了。 ================================================ (6)文件存取訪問(wèn)要注意的問(wèn)題【1】tftp的使用,,在任何一個(gè)目錄下,使用tftp的客戶端,訪問(wèn)某個(gè)ip的機(jī)子上的tftp服務(wù)器,訪問(wèn)這個(gè)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】上傳文件失敗,文件權(quán)限報(bào)錯(cuò)的解決辦法(解決辦法見(jiàn) 下面的 3)) 想吧new.txt上傳到tftp服務(wù)器中。 Error code 2: Access violation 錯(cuò)誤。 /////////////////////////////////////// 1)看了下文件權(quán)限: new.txt應(yīng)該是666的。 -rw-rw-rw- 1 root root 30278 2011-01-30 06:16 new.txt 還是報(bào)錯(cuò):
root@ubuntu:/home/zhangbin# tftp 127.0.0.1 tftp> put new.txt Error code 2: Access violation tftp> q 改成666,還是報(bào)錯(cuò) 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> ============
重新來(lái)
新建立了一個(gè)0字節(jié)的文件,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
更改權(quán)限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>
更改權(quán)限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找問(wèn)題,
目錄d 權(quán)限755
drwxr-xr-x 2 root root 4096 2011-02-27 19:11 tftpboot
更改d權(quán)限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服務(wù)
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
說(shuō)明了不是tftpboot權(quán)限,也不是要上傳的文件的權(quán)限的問(wèn)題
=========================
3)參考了文章之后,明白了一點(diǎn),就是tftp服務(wù)器,默認(rèn)規(guī)則是可以下載,但是上傳文件的話,
必須在tftpboot中,有一個(gè)相同名字的文件,而且具備相應(yīng)的可讀寫(覆蓋)的權(quán)限.這樣才能上傳文件.
實(shí)驗(yàn)一下:
在tftpboot中,創(chuàng)建new.txt,忘記改寫權(quán)限.
上傳失敗.
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
改寫了權(quán)限之后,上傳就成功了.
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的權(quán)限。
root下,新建一個(gè)文件,001.txt,打算上傳到tftp中.
root@ubuntu:/home/zhangbin# vi 001.txt
創(chuàng)建之后的權(quán)限是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中,創(chuàng)建一個(gè)同名的
root@ubuntu:/home/zhangbin# vi /tftpboot/001.txt
權(quán)限默認(rèn)是644,感覺(jué),用root執(zhí)行上傳,可以覆蓋.
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>
這個(gè)實(shí)驗(yàn)說(shuō)明了,root下,在tftpboot下,具有666的文件,才能被覆蓋掉./////////////////////////////////////// 參考文章和用到的知識(shí)如下====================下面是我參考的一些文章=============================================
這個(gè)問(wèn)題,參考了這位大牛的文章
原文鏈接:http://os.51cto.com/art/201001/176508.htm 在向大家詳細(xì)介紹tftp之前,首先讓大家了解下Ubuntu tftp,然后全面介紹Ubuntu tftp,希望對(duì)大家有用。Ubuntu 團(tuán)隊(duì)對(duì)它的使用者公開的承諾:Ubuntu 永遠(yuǎn)免費(fèi) , 并且對(duì)于 "企業(yè)版本" 沒(méi)有任何額外的費(fèi)用, 在同樣的自由團(tuán)隊(duì)上,將最好的工作成果帶給每一個(gè)人。 配置Ubuntu tftp服務(wù)的步驟: 1、安裝相關(guān)軟件包:Ubuntu tftp(服務(wù)端),tftp(客戶端),xinetd 2、建立配置文件 3、建立Ubuntu tftp服務(wù)文件目錄(上傳文件與下載文件的位置),并且更改其權(quán)限 4、重新啟動(dòng)服務(wù) 通過(guò)get命令,可以把當(dāng)前目錄下的test.txt文件,通過(guò)Ubuntu tftp上傳到它的服務(wù)文件目錄。這時(shí),在/tftpboot下面會(huì)出現(xiàn)test.txt文件。通過(guò)put命令,可以從/tftpboot下,下載 test.txt文件。這樣就驗(yàn)證了Ubuntu tftp服務(wù)配置的正確性。當(dāng)文件上傳與下載結(jié)束后,可以通過(guò)quit命令退出。嚴(yán)格按照以上步驟配置Ubuntu tftp服務(wù),一般都可以成功。如果出現(xiàn)無(wú)法get或者put的時(shí)候,可以查看一下防火墻是否關(guān)閉。 如果從tftp服務(wù)器下載失敗, 要確保服務(wù)器的根目錄有可執(zhí)行的權(quán)限。 $ chmod -R 777 tftp
$ tftp 192.168.1.222 可是上傳文件不成功, 提示錯(cuò)誤: tftp> put dic.txt 求助于google, 得下面一段說(shuō)明,問(wèn)題解決。 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服務(wù)器缺少必要的身份驗(yàn)證, 所以默認(rèn)只允許下載文件,要上傳文件,必須是服務(wù)器中已存在同名的文件, 且該文件權(quán)限允許被覆蓋。
$ touch dic.txt $ chmod 777 dic.txt 重新上傳,成功。 在網(wǎng)上看到有人配/etc/default/tftp,/etc/inetd.conf這些文件,實(shí)際上沒(méi)這么復(fù)雜,用tftp和tftpd,加上xinetd監(jiān)控,只需要配/etc/xinetd./tftp即可。 =========== 也有牛人說(shuō) http://yuanfarn./search/label/Linux 在 Ubuntu 上安裝 tftpd 伺服器是一件非常簡(jiǎn)單的事,首先執(zhí)行以下這個(gè)指令安裝需要的套件:
然後再執(zhí)行以下的指令啟動(dòng) openbsd-inetd:
基本上,這樣就可以使用 tftpd 了。不過(guò),由於 Ubuntu 的 openbsd-inetd 預(yù)設(shè)將 tftpd 的路徑指定為 =============================================================== 參考了http://bbs./thread-655364-1-1.html 參考了這篇文章 tftp程序,對(duì)ubuntu用戶來(lái)講,配置這個(gè)不是很友好。 ===================================================== http://hi.baidu.com/%B0%D9%B8%F6%C8%AB%CA%E9/blog/item/0cb018ffec018e49d6887deb.html
|
|
|