Ubuntu TFTP服務器搭建


開發環境

Ubuntu 16.04

安裝tftp服務

tftp服務端

$ sudo apt-get install tftpd-hpa

tftp 客戶端

建議安裝,方便本機測試
$ sudo apt-get install tftp-hpa

配置TFTP服務

$ sudo vim /etc/default/tftpd-hpa

配置如下


 
  1. # /etc/default/tftpd-hpa
  2. TFTP_USERNAME="hayson"
  3. TFTP_DIRECTORY="/work/tftp"
  4. TFTP_ADDRESS="0.0.0.0:69"
  5. TFTP_OPTIONS="-s"

參數解釋

  • TFTP_USERNAME 用戶名
    請使用於ubuntu登錄的用戶名
  • TFTP_DIRECTORY tftp文件目錄
    輸入絕對路徑即可,注意修改文件權限,最好chmod -R 777 /work/tftp
  • TFTP_OPTIONS tftp啓動參數
    不支持:-l:以standalone/listen模式啓動TFTP服務,而不是從inetd啓動
    不支持:-c:可創建新文件。默認情況下,TFTP只允許覆蓋原有文件,不能創建新文件
    -s:改變TFTP啓動的根目錄。舉栗子:就是可以直接tftp 0x40000000 test 而不是輸入tftp 0x400000000 /work/nfs/test

重啓TFTP服務

$ sudo service tftpd-hpa restart

確認tftp服務是否開啓

  • $ ps aux|grep tftp

     

    
     
    1. hayson@hayson-Server:/work/tftp$ ps aux|grep tftp
    2. root 32580 0.0 0.0 15180 152 ? Ss 10:37 0:00 /usr/sbin/in.tftpd --listen --user hayson --address 0.0.0.0:69 -s /work/tftp
    3. hayson 32737 0.0 0.0 21312 1028 pts/8 S+ 10:38 0:00 grep --color=auto tftp
  • 或者 $ netstat-a|grep tftp

     

    
     
    1. hayson@hayson-Server:/work/tftp$ netstat -a | grep tftp
    2. udp 0 0 *:tftp *:*

測試

在/work/nfs下新建一個test文件,隨便寫點字符

Ubuntu 測試

$ tftp localhost


 
  1. hayson@hayson-Server:/work$ tftp localhost
  2. tftp> get test
  3. tftp> q
  4. hayson@hayson-Server:/work$ cat test
  5. aaaaaaaa

開發板測試

配置開發板網絡


 
  1. $ setenv ethaddr 00:10:ab:20:81:71
  2. $ setenv ipaddr 172.16.134.15
  3. $ setenv netmask 255.255.255.0
  4. $ setenv gatewayip 172.16.134.1
  5. $ setenv serverip 172.16.34.85

測試結果如下:


 
  1. hisilicon # setenv ethaddr 00:10:ab:20:81:71
  2. Warning: gmac0 MAC addresses don't match:
  3. Address in SROM is 00:10:ab:20:81:71
  4. Address in environment is 3e:e2:6c:dd:6f:04
  5. hisilicon # setenv gatewayip 172.16.134.1
  6. hisilicon # setenv netmask 255.255.255.0
  7. hisilicon # setenv serverip 172.16.34.85
  8. hisilicon # ping 172.16.34.85
  9. ETH0: PHY(phyaddr=1, rgmii) link UP: DUPLEX=FULL : SPEED=1000M
  10. MAC: 00-10-AB-20-81-71
  11. Using gmac0 device
  12. host 172.16.34.85 is alive

tftp 測試

$ tftp 0x42000000 test
結果如下:


 
  1. hisilicon # tftp 0x42000000 test
  2. ETH0: PHY(phyaddr=1, rgmii) link UP: DUPLEX=FULL : SPEED=1000M
  3. MAC: 00-10-AB-20-81-71
  4. Using gmac0 device
  5. TFTP from server 172.16.34.85; our IP address is 172.16.134.15; sending through gateway 172.16.134.1
  6. Filename 'test'.
  7. Load address: 0x42000000
  8. Loading: T #
  9. 0 Bytes/s
  10. done
  11. Bytes transferred = 6 (6 hex)

錯誤記錄

-l -c 啓動參數不支持


 
  1. hayson@hayson-Server:/work/tftp$ sudo service tftpd-hpa start
  2. Job for tftpd-hpa.service failed because the control process exited with error code. See "systemctl status tftpd-hpa.service" and "journalctl -xe" for details.

啓動參數沒加-s


 
  1. hayson@hayson-Server:/work/tftp$ tftp 127.0.0.1
  2. tftp> get test
  3. Error code 2: Only absolute filenames allowed

查看出錯日誌

$ tail /var/log/syslog

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