Ubuntu 安裝 TFTP Server

因為要節省 embadded system 的空間,所以改使用 tftp 去 download 二進制檔案。
相比 NFS 是比較小包,但是沒有列出檔案的功能,這點要稍微注意一下。

一、安裝 TFTP 服務(在 host 端)

xinted 跟 tftpd-hpa 擇一即可

1.下載 tftpd-hpa

$sudo apt-get install tftpd-hpa

2.設定分享的目錄, 以下是 /home/yuyan/Public/tftp

$sudo mkdir -p /home/yuyan/Public/tftp
$sudo chmod -R 777 /home/yuyan/Public/tftp

3. 配置 /etc/default/tftpd-hpa

$vim /etc/default/tftpd-hpa
# /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/home/yuyan/Public/tftp"
TFTP_ADDRESS=":69"
TFTP_OPTIONS="-l -c -s"

#-c: Allow new files to be created
#-s: Change  root  directory  on startup.
#-l:  Run the server in standalone (listen) mode, rather than run from inetd.

4. 重啟 tftpd-hpa

$sudo service tftpd-hpa restart

xinetd(has-been)

1.下載 xinetd

$sudo apt-get install xinetd tftp tftp-server

2.設定分享的目錄,以下是 /home/yuyan/Public/tftp

$sudo mkdir -p /home/yuyan/Public/tftp
$sudo chmod -R 777 /home/yuyan/Public/tftp

3. 配置 /etc/xinetd.d/tftp

$vim /etc/xinetd.d/tftp
service tftp
{
    disable = no
    socket_type = dgram
    protocol = udp
    wait = yes
    user = yuyan
    server = /usr/sbin/in.tftpd
    server_args = -s /home/yuyan/Public/tftp -c
    per_source = 11
    cps = 100 2
}

4. restart xinetd service

$sudo /etc/init.d/xinetd restart

二、用busybox tftp 測試 (guest 端)

tftp help

$ busybox tftp --help
BusyBox v1.26.2 (2020-05-13 07:49:33 UTC) 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 get example

$tftp -g -r hello 192.168.7.2 69

tftp put example

 tftp -p -l ./test 192.168.7.2 69

  目錄