ubuntu tftp服務器配置

第一步:安裝tftp tftpd 軟件包

說明:這裏需要網絡配置,

以root身份進入/etc/network/interface 編輯ip,netmask,broadcast等,並保存。

以root身份進入/etc/resolv.conf編輯search:202.102.224.68,namesearch 202.102.227.68;

無root權限,可以使用超級權限用戶:命令前加sudo.

網絡配置完畢可以重啓網絡:

方法一:/etc/init.d/networking restart

方法二:(sudo) ifdown eth0

              (sudo) ifup eth0

到此網絡配置完畢,可以ping一下服務器,如果出現destion host unreachable ,查看自己的ip網段是否符合要求。

具體的可以查看ubuntu網絡配置方法

成功安裝tftp服務器還沒找到無網絡安裝方法,抱歉。

安裝tftp:

新ubuntu系統需要更新一下自己的數據源,sudo apt-get update

若出現:無法解析或打開軟件包的列表或是狀態文件

解決方法:sudo rm /var/lib/apt/lists/* -vf   //刪除存在的更新源
                 sudo apt-get update  //重新生成

到此係統的數據源更新完畢。

使用apt-get安裝tftp

root@ubuntu:/home/zhangbin# apt-get install tftp tftpd  xinetd 前者是客戶端,後者是服務程序。

Reading package lists... Done

Building dependency tree       

Reading state information... Done

The following extra packages will be installed: 

所以一共是安裝了三個軟件包。

tftd 服務程序

tftp  客戶端程序

openbsd-inetd  inetd服務器的debian移植版本。

 ===========================================

關於penbsd的inetd軟件包的說明如下:

OpenBSD 互聯網超級服務器

inetd 服務器是一個專門管理入網連接網絡後臺程序.它的配置文件定義了當收到入 網連接時運行什麼程序.任何服務端口都可以用TCP或UDP協議配置.

這是一個有 Debian 專用特色的 OpenBSD 後臺移植版.該軟件包支持 IPv6,內建的 libwrap 訪問控制,綁定到特定地址,UNIX 域套接字和套接字緩衝調解.

 

=================================================

第二步:   配置

root@ubuntu:~# vi /etc/inetd.conf

 在/etc/xinetd.d/下建立一個配置文件tftp
sudo vi tftp
在文件中輸入以下內容:
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 = 1002
flags = IPv4}
保存退出

==================================================

第三步 : 新建/tftpboot文件夾

cd /  ;                           // 跳到root的根目錄下

mkdir tftpboot;             // 創建tftpboot目錄

touch  test.txt              // 創建test.txt 文件

vi  test.txt                   // 編輯test.txt 文件,隨意輸入一些字母,一會傳輸時有字節顯示,

                                  //若test.txt中時空文檔,在傳輸時時不顯示傳輸字節      數的

文件夾的權限如下:

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 ../

  
一些操作細節中的知識點和遇到的問題的解決辦法

(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://blog.csdn.net/wfing/archive/2010/07/12/5729091.aspx

原文鏈接:http://os.51cto.com/art/201001/176508.htm

在向大家詳細介紹tftp之前,首先讓大家瞭解下Ubuntu tftp,然後全面介紹Ubuntu tftp,希望對大家有用。Ubuntu 團隊對它的使用者公開的承諾:Ubuntu 永遠免費 , 並且對於 "企業版本" 沒有任何額外的費用, 在同樣的自由團隊上,將最好的工作成果帶給每一個人。

配置Ubuntu tftp服務的步驟:

1、安裝相關軟件包:Ubuntu tftp(服務端),tftp(客戶端),xinetd
sudo apt-get install tftpd tftp xinetd

2、建立配置文件
在/etc/xinetd.d/下建立一個配置文件tftp
sudo vi tftp
在文件中輸入以下內容:
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}
保存退出

3、建立Ubuntu tftp服務文件目錄(上傳文件與下載文件的位置),並且更改其權限
sudo mkdir /tftpboot
sudo chmod 777 /tftpboot -R

4、重新啓動服務
sudo /etc/init.d/xinetd restart
至此Ubuntu tftp服務已經安裝完成了,下面可以對其進行一下測試。(假設在當前目錄下有一個測試文件test.txt)
$tftp 127.0.0.1                      
tftp> put test.txt
Sent 1018 bytes in 0.0 seconds
tftp> get test.txt
Received 1018 bytes in 0.1 seconds
tftp> quit

通過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> get zImage
Received 1692890 bytes in 0.2 seconds

可是上傳文件不成功,

提示錯誤:

tftp> put dic.txt
Error code 2: Access violation

求助於google, 得下面一段說明,問題解決。

The tftp man page says:

Because there is no user-login or validation within the TFTP
protocol, the remote site will probably have some sort of
file-access restrictions in place. The exact methods are
specific to each site and therefore dif ficult to document here.

So apparently the site you're trying to get the file from has some
kind of access restrictions in place. Take a look at the tftpd man
page on the remote host. The linux tftpd manual says, in part, "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."

上面主要意思就是: tftp服務器缺少必要的身份驗證,

所以默認只允許下載文件,要上傳文件,必須是服務器中已存在同名的文件,

且該文件權限允許被覆蓋。


所以首先在服務中創建一個與要上傳的文件同名的文件,並更改權限。

$ touch dic.txt

$ chmod 777 dic.txt

重新上傳,成功。
tftp> put dic.txt
Sent 13770 bytes in 0.0 seconds

在網上看到有人配/etc/default/tftp,/etc/inetd.conf這些文件,實際上沒這麼複雜,用tftp和tftpd,加上xinetd監控,只需要配/etc/xinetd./tftp即可。

 

===========

也有牛人說

http://yuanfarn.blogspot.com/search/label/Linux

 

 

在 Ubuntu 上安裝 tftpd 伺服器是一件非常簡單的事,首先執行以下這個指令安裝需要的套件:

sudo apt-get install tftp tftpd openbsd-inetd

然後再執行以下的指令啟動 openbsd-inetd:

sudo /etc/init.d/openbsd-inetd start

基本上,這樣就可以使用 tftpd 了。不過,由於 Ubuntu 的 openbsd-inetd 預設將 tftpd 的路徑指定為/srv/tftp,我覺得有點不大方便,因此通常習慣再去修改/etc/inetd.conf,將/srv/tftp 修改成/tmp/tftproot,這樣一來,我也不用再去理會 /srv 這個目錄的權限,只要將要藉由 tftp 傳送的檔案直接複製到 /tmp/tftproot 目錄就行了,更方便許多呢!

 

===============================================================

參考了http://bbs.chinaunix.net/thread-655364-1-1.html

 

參考了這篇文章

tftp程序,對ubuntu用戶來講,配置這個不是很友好。

安裝程序
代碼:
sudo apt-get install tftp tftpd

前者是客戶端,後者是服務程序。

只這樣是不行的,因爲tftp是要inetd來控制的,而ubuntu或debian類的系統,默認是沒有安裝inetd的,安裝一下:
代碼:
sudo apt-get install netkit-inetd



在/目錄下建一個tftpboot, 把屬性改成777。
代碼:
cd /
sudo mkdir tftpboot
sudo chmod 777 tftpboot



修改/etc/inetd.conf
代碼:
tftp    dgram   udp     wait    nobody  /usr/sbin/tcpd /usr/sbin/in.tftpd /tftpboot


重新加載inetd進程
代碼:
sudo /etc/init.d/inetd reload


測試一下,在/tftpboot文件夾下新建立一個文件
代碼:
touch aaa


進入另外一個文件夾
代碼:
tftp 10.0.0.1
tftp> get aaa

=====================================================

http://hi.baidu.com/%B0%D9%B8%F6%C8%AB%CA%E9/blog/item/0cb018ffec018e49d6887deb.html

 

新人學習Linux,近日在Fedora下學習使用Tftp,服務器、客戶端配置完畢後,使用tftp上傳、下載文件,

提示訪問非法: Error code 2: Access violation 。

網上查了一些資料,大概明白問題在於文件的訪問權限。幾經周折,問題解決,將此過程細錄如下,

以作成長之鑑證,也爲後來學習者提供解決方法。以下爲詳細過程:

Tftp按照成熟解決方案配置,不再贅述;

問題:在tftpboot下建立文件1.txt, tftp 127.0.0.1訪問本地tftp服務器,出現

Error code 2: Access violation。

解決:進入/tftpboot文件夾,使用命令 chmod 666 1.txt,將1.txt權限改爲root、group、others均可讀寫。

至此,問題解決。

 

chmod命令

體會:chmod命令(在root用戶下,共root、group、others)

指令名稱 : chmod 
使用權限 : 所有使用者 
使用方式 : chmod [-cfvR] [--help] [--version] mode file...

chmod XYZ file

X:代表root對file的訪問權限。X爲3位2進制數據分別代表對文件的read、write、executed 權限。

0代表禁止,1代表允許,如7即允許root對file有rwx權限,6代表有rx權限,4代表r權限,以此類推;

Y:代表group對file的訪問權限。數據定義參考X的數據定義;

Z:代表others對file的訪問權限。數據定義參考X的數據定義;



轉載出處:http://blog.csdn.net/cgzhello1/article/details/7850858


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章