2015年12月14日 星期一

安裝使用 tftp, tftpd



安裝(server side)
$sudo apt-get install cobbler


設定
$sudo vim /etc/default/tftpd-hpa


...
TFTP_USERNAME="nobody"
TFTP_DIRECTORY ="/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-s -c -l"


建立tftp資料夾

執行
$sudo service tftpd-hpa restart




 Embedded System: 安裝busybox tftp(client)

指令
$tftp 


BusyBox v1.19.4 (2014-12-4 20:13:15 CST) multi-call binary.

Usage: tftp [OPTIONS] HOST [PORT]

Transfer a file from/to tftp server

        -l FILE Local FILE
        -r FILE Remote FILE
        -g      Get file
        -p      Put file
        -b SIZE Transfer blocks of SIZE octets


傳輸檔案
$ tftp -p -l myfile.txt 192.168.1.77                              //default port: 69


myfile.txt     100% |***************************************| 2870    0:00:00 ETA



[Issue1: 如果無法傳輸檔案]
1.請確認 iptables 狀態
$ sudo iptables -L -n -v                   //確認port 69是否可接收封包

Chain INPUT (policy DROP 22822 packets, 2530K bytes)
 pats    bytes target        prot opt in     out     source               destination         
 310K   38M  ACCEPT     all  --    *      *       0.0.0.0/0            0.0.0.0/0            state RELATED,ESTABLISHED
 4321  226K  ACCEPT     tcp  --   *     *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22
    3       144  ACCEPT     tcp  --   *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:445
    0           0  ACCEPT     udp  --  *     *       0.0.0.0/0            0.0.0.0/0            udp dpt:445
   14      827  ACCEPT     udp  --  *     *       192.168.1.0/24       0.0.0.0/0            udp dpt:69 state NEW,ESTABLISHED


Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 156K packets, 87M bytes)
 pkts bytes target     prot opt in     out     source               destination         
...


2.如果port 69 未打開,就要執行下列指令
$ sudo iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 69 -m state --state NEW,ESTABLISHED -j ACCEPT

$ sudo iptables -A OUTPUT -p udp --sport 69 -m state --state ESTABLISHED -j ACCEPT

[Issue2: 如果無法上傳檔案至Server]
[root@GM]# tftp -p -l osd_style.bin 192.168.1.88
tftp: server error: (0) Permission denied

1.請將檔案名稱縮至8個.

2.在Server上 /tftpboot 目錄中建立檔案名稱一樣的檔案. (權限777)


OK, 再次傳輸檔案...
Done!

沒有留言:

張貼留言