tftp (普通檔案傳輸協定或一般檔案傳輸協定) 大家一定記得在2003年8月12日全球爆發沖擊波(worm.blaster)病毒,這種病毒會監聽端口69,模拟出一個tftp伺服器,并啟動一個攻擊傳播線程,不斷地随機生成攻擊位址,進行入侵。另外tftp被認為是一種不安全的協定而将其關閉,同時也是防火牆打擊的對象,這也是有道理的。不過tftp還是有用武之地的,下面講的檔案傳輸和備份router配置檔案都時實際應用,它也隻時一種手段而已。
一、用tftp實作檔案傳輸
環境:伺服器a :rhas11
客戶機b: rhas101
首先用rpm –qa | grep tftp看一下tftp有沒安裝,沒有的話安裝一下。
a:在伺服器端設定
#vi /etc/xinetd.d/tftp
service tftp
{
disable = no
socket_type = dgram
protocol = udp
wait = yes
user = root
server = /usr/sbin/in.tftpd
server_args = -s /test
per_source = 11
cps = 100 2
flags = ipv4
}
或用chkconfig tftp on 也可以打開xinetd代理的tftp服
#mkdir /test
#service xinetd restart 從啟xinetd服務,因為tftp服務受控與xinetd, xinetd是管服務的服務,它是不開端口的。
驗證一下tftp是否起來了:
[root@rhas11 tftp]# netstat -nlp
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:32768 0.0.0.0:* listen 3122/rpc.statd
tcp 0 0 127.0.0.1:32781 0.0.0.0:* listen 4035/xinetd
tcp 0 0 0.0.0.0:111 0.0.0.0:* listen 3103/portmap
tcp 0 0 0.0.0.0:80 0.0.0.0:* listen 3324/httpd
tcp 0 0 0.0.0.0:22 0.0.0.0:* listen 3255/sshd
tcp 0 0 127.0.0.1:631 0.0.0.0:* listen 3213/cupsd
tcp 0 0 127.0.0.1:25 0.0.0.0:* listen 3295/sendmail: acce
tcp 0 0 127.0.0.1:6010 0.0.0.0:* listen 3415/0
tcp 0 0 0.0.0.0:443 0.0.0.0:* listen 3324/httpd
udp 0 0 0.0.0.0:32768 0.0.0.0:* 3122/rpc.statd
udp 0 0 0.0.0.0:69 0.0.0.0:* 4035/xinetd
udp 0 0 0.0.0.0:69 0.0.0.0:* 4012/in.tftpd
udp 0 0 0.0.0.0:111 0.0.0.0:* 3103/portmap
udp 0 0 0.0.0.0:754 0.0.0.0:* 3122/rpc.statd
udp 0 0 0.0.0.0:631 0.0.0.0:* 3213/cupsd
a:伺服器端 建立一檔案file
#cd /test
[root@rhas11 test]# ls -l
總用量 4
-rw-r--r-- 1 root root 19 5月 15 18:26 file
b用戶端:
下載下傳:
[root@rhas101 tmp]# tftp 172.31.0.11
tftp> get 1
received 72 bytes in 0.0 seconds
tftp>
上傳目前目錄下檔案”aaa”
[root@rhas101 client]# ls -l
-rw-r--r-- 1 root root 15 5月 20 21:49 aaa
[root@rhas101 client]# tftp 172.31.0.11
tftp> put aaa
error code 1: file not found
奇怪目前目錄卻是有aaa檔案???讓我想一下
哦,原來伺服器/test目錄下沒有檔案aaa,那就touch一個吧
[root@rhas11 test]# touch aaa
-rw-r--r-- 1 root root 0 5月 15 18:46 aaa
好了再試一試
error code 2: access denied
細心的讀者一定想到這是權限問題
再到伺服器上設定
(===========================================================================
小插曲:#chown -r nobody.nobody /test
user = nobody
server_args = -u nobody -s /test
chmod 777 -r /test
===========================================================================
)
#service xinetd restart
[root@rhas11 test]# chmod 007 aaa 其實隻要有可寫的權限就行了
-------rwx 1 root root 0 5月 15 18:46 aaa
sent 16 bytes in 0.0 seconds
二、 特殊應用:上傳和下載下傳路由器(或交換機)配置檔案
配使用linux的tftp功能配置cisco route
在區域網路環境中,如果有cisco 路由器和linux伺服器。也許你需要利用linux的
tftp服務去下載下傳cisco router配置檔案 startup-config,在伺服器上編輯後再上載
到路由器,在實作中有一些特别注意的地方。
所用軟、硬體:redhat linux as 3.0 ,cisco 2611 路由器
beijing#copy run tftp
address or name of remote host []? 172.31.0.11
destination filename [beijing-confg]? beijing-route
!!
1968 bytes copied in 0.581 secs (3387 bytes/sec)
别忘了在tftp server 上建立beijing-route權限為777
beijing#copy tftp flash
source filename []? beijing-route
destination filename [beijing-route]?
accessing tftp://172.31.0.11/beijing-route...
erase flash: before copying? [confirm]
erasing the flash filesystem will remove all files! continue? [confirm]
erasing device... eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee ...erased
erase of flash: complete
loading beijing-route from 172.31.0.11 (via fastethernet0/0): !
[ok - 1968 bytes]
verifying checksum... ok (0x5248)
1968 bytes copied in 0.285 secs (6905 bytes/sec)
beijing#
用tftp傳輸大檔案時的帶寬顯示情寬