2009年6月7日 星期日

參考自:http://wiki.jk2410.org/wiki/TFTP_Server_%E8%88%87_xinetd_%E7%9A%84%E5%AE%89%E8%A3%9D:_Debian/Ubuntu


安裝 tftpd-hpa 與 xinetd

在Ubuntu下,tftp是不能單獨運作的,需要xinetd這個網路管理的背景程式之支援。於是我們同時安裝這兩個套件。

$ sudo apt-get install tftpd-hpa xinetd

[編輯] xinetd.conf 設定

安裝完tftp與xinetd後,需要在xinetd的設定檔/etc/xinetd.conf中寫入相關設定。

$cat /etc/xinetd.conf
# Simple configuration file for xinetd
# Some defaults, and include /etc/xinetd.d/
defaults
{
# Please note that you need a log_type line to be able to use log_on_success
# and log_on_failure. The default is the following :
# log_type = SYSLOG daemon info
}
includedir /etc/xinetd.d

雖然我們可以將設定內容寫入此處,但還有更好的設定檔設定方法。xinetd.conf引入專門存放設定檔的資料夾includedir /etc/xinetd.d。因此更結構化的設定檔配置就是自己建立一個tftp設定檔於此資料夾內。

$sudo vim /etc/xinetd.d/tftp

存入

service tftp
{
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /var/lib/tftpboot
disable = no
per_source = 11
cps = 100 2
flags = IPv4
}

由於背景網路程式已經由inetd更換成xinetd,可將/etc/inetd.conf中關於tftp的部份註解以避免混淆。

#:BOOT: TFTP service is provided primarily for booting. Most sites
# run this only on machines acting as "boot servers."
#tftp dgram udp wait nobody /usr/sbin/tcpd /usr/sbin/in.tftpd /srv/tftp

完成以上設定後,還需要讓xinetd讀入新參數並重新啟動。

sudo /etc/init.d/xinetd reload
sudo /etc/init.d/xinetd restart


檢查一下tftp是否真的在運作

$ sudo netstat -anp | grep tftp
udp 0 0 0.0.0.0:69 0.0.0.0:* 5249/in.tftpd
unix 2 [ ] DGRAM 17654 5249/in.tftpd