在Ubuntu上建立tftp伺服器 ( Set up tftp server on Ubuntu )

來源:互聯網
上載者:User

tftp(Trival File Transfer Protocol)是一種輕量級的檔案傳輸通訊協定,TFTP報文封裝在UDP包之中(預設連接埠:69),並不可靠,因此不能 ls,也不能認證。
但是,在嵌入式開發中,它能夠為目標機提供高速下載服務。由於是在區域網路中,因此資料出錯的機率也是相當小。
在Ubuntu上安裝tftp伺服器並不複雜:

  1. 安裝ftpd以及相關軟體包

    $ sudo apt-get install xinetd tftpd tftp

  2. 建立檔案/etc/xinetd.d/tftp並且按如下所示配置

    service tftp { protocol = udp port = 69 socket_type = dgram wait = yes user = nobody server = /usr/sbin/in.tftpd server_args = /tftpboot disable = no }或者service tftp {socket_type = dgramprotocol = udp wait = yes user = root server = /usr/sbin/in.tftpd server_args = -s /tftpboot disable = no per_source = 11 cps = 100 2 flags = IPv4} 重點是:server_args = -s /tftpboot和 disable = no兩個選項,(註:ubuntu下-c參數不能使用,添加後伺服器無響應??why?)

  3. 在系統根目錄下建立tftproot目錄,並修改許可權

    $ sudo mkdir /tftpboot $ sudo chmod -R 777 /tftpboot $ sudo chown -R nobody /tftpboot 

  4. 啟動tftp服務

    $ sudo /etc/init.d/xinetd stop $ sudo /etc/init.d/xinetd start 

  5. 測試:傳輸一個檔案

    本測試將先與本機串連,然後再傳送一個已有的檔案(例如hello.txt),通過觀察檔案的修改時間來確定是否傳送成功。

    $ touch /tftpboot/hello.txt $ chmod 0777 /tftpboot/hello.txt $ ls -l /tftpboot/ total 0 -rwxrwxrwx 1 lesca lesca 0 2011-02-2616:43hello.txt # 串連本地tftp伺服器 $ tftp localhost tftp> put hello.txt tftp> quit $ ls -l /tftpboot/ total 8 -rwxrwxrwx 1 lesca lesca 0 2011-02-26 16:48 hello.txt 

    #時間發生了變化,傳送成功

註:localhost如果沒有在環境那個變數裡面設定 就使用127.0.0.1


The above is from
David Sudjiman – Installing and setting TFTPD in Ubuntu Translated and re-shared by Lesca.

附:檢查tftpd是否已經啟動

$ sudo netstat -lnput Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 929/sshd tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 1181/cupsd tcp 0 0 0.0.0.0:1723 0.0.0.0:* LISTEN 1110/pptpd tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN 1172/mysqld tcp6 0 0 :::80 :::* LISTEN 1253/apache2 tcp6 0 0 :::22 :::* LISTEN 929/sshd tcp6 0 0 ::1:631 :::* LISTEN 1181/cupsd tcp6 0 0 :::5500 :::* LISTEN 1825/vinagre udp 0 0 0.0.0.0:52537 0.0.0.0:* 960/avahi-daemon: r udp 0 0 0.0.0.0:68 0.0.0.0:* 1834/dhclient udp 0 0 0.0.0.0:69 0.0.0.0:* 3556/xinetd # It's Here!! udp 0 0 0.0.0.0:5353 0.0.0.0:* 960/avahi-daemon: r 

提示:安全性
根據 man 8 tftpd 的描述:

... The use of tftp(1) does not require an account or password on the remote system. Due to thelack of authentication information, tftpd will allow only publicly read‐ able 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....

因此,建議:
1.為tftpd降低UID許可權(本文已經將UID設定成nobody)
2.在不使用tftp服務的時候關閉它(disable = yes)
3.為該連接埠(UDP:69)配置防火牆,阻止外網訪問

注意: 1:如果出現permission denied 錯誤  則是操作者許可權不夠,
需要提升許可權
su  root
輸入密碼後就可以正常進行tftp傳輸操作了

2:如果出現Access violation錯誤 則是檔案許可權沒有解開,
將要操作的檔案操作許可權全解開就可以了
chmod 777 檔案名稱   或者666也可以

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.