Mac 上自帶TFTP Server 軟件的使用
1、TFTP協議
簡單文件傳輸協議Trivial File Transfer Protocol (TFTP)是一個基於UDP協議的簡單的、低開銷的文件傳輸協議,允許客戶端get或者put文件到遠程主機上。由於它開銷極效,所以TFTP被用於引導計算機,例如沒有大容量存儲器的路由器。這就是為什麽很多路由器都用tftp作為升級的方式。這個協議很有意思,如果感興趣,請參考如下兩個網址:
中文wiki 或者 英文wiki
RFC 1350 THE TFTP PROTOCOL (REVISION 2)
2、Mac下配置和啟動TFTP
1)配置
Mac默認自帶TFTP。配置文件位置:/System/Library/LaunchDaemons/tftp.plist。
修改配置文件,去掉如下兩行:
<key>Disabled</key>
<true/>
添加如下配置(可選),就是添加-l選項:
<array> <string>/usr/libexec/tftpd</string> <string>-i</string> <string>-l</string> <string>/private/tftpboot</string> </array>
簡要說明:
I、-i選項,開啟不安全模式。-l選項,使用syslog記錄所有請求的日誌。關於說明請參考:man tftpd(打開終端,輸入這條命令就能看到了)。
II、/private/tftpboot是默認路徑,需要改變其讀寫權限(非常重要),執行命令:
chmod -R 777 /private/tftpboot
2)啟動
sudo launchctl load -F /System/Library/LaunchDaemons/tftp.plist
sudo launchctl start com.apple.tftpd
執行上邊兩條,如果沒有報錯,那麽說明啟動成功。如果想看日誌可以使用如下命令:
tail -f /var/log/system.log
得到的日誌應該如下:
Mar 7 14:04:02 ***.local sudo[589]: *** : TTY=ttys000 ; PWD=/Users/*** ; USER=root ; COMMAND=/bin/launchctl load -F /System/Library/LaunchDaemons/tftp.plist
Mar 7 14:04:09 ***.local sudo[591]: *** : TTY=ttys000 ; PWD=/Users/*** ; USER=root ; COMMAND=/bin/launchctl start com.apple.tftpd Mar 7 14:04:09 ***.local tftpd[593]: recvfrom: Resource temporarily unavailable Mar 7 14:04:09 *** com.apple.xpc.launchd[1] (com.apple.tftpd[593]): Service exited with abnormal code: 1
這個位置貌似有一條報錯,但是不影響使用,如果有高手請指教如何處理。
3)關閉
sudo launchctl unload -F /System/Library/LaunchDaemons/tftp.plist
sudo launchctl stop com.apple.tftpd
3、TFTP協議的使用
在啟動TFTP服務器後,我們就可以使用TFTP來連接這臺服務器,並獲取或者提交文件了。下邊用命令行來演示:
***:~ ***$ tftp tftp> connect localhost tftp> status Connected to localhost. Mode: netascii Verbose: off Tracing: off Rexmt-interval: 5 seconds, Max-timeout: 25 seconds tftp> verbose Verbose mode on. tftp> get 1.txt getting from localhost:1.txt to 1.txt [netascii] Received 9 bytes in 0.0 seconds [inf bits/sec] tftp> quit
簡單說明:我們通過tftp從tftp服務器上獲取1.txt(/private/tftpboot/1.txt)文件。
connect host-name [port] 連接服務器。其他命令請參考: man tftp。
4、使用TFTP給TP-Link固件升級
如果上述步驟都已順利完成,那麽用MAC的TFTP給TP-Link升級都很簡單了,只需要到TP-Link官網搜索你的路由器的對應的固件下載,然後將bin文件放到/private/tftpboot目錄下,並進入路由器192.168.1.1,然後固件升級,點幾下按鈕就搞定了。請大家盡情發乎吧。
原文鏈接:http://www.it165.net/os/html/201503/11922.html
Mac 上自帶TFTP Server 軟件的使用