WSL2 (Ubuntu) install TFTP server

installation

sudo apt-get install xinetd
sudo apt-get install tftp tftp-hpa tftpd-hpa

Configuration

The configuration /etc/xinetd.d/tftpfile (create it if you don’t have one) is as follows:

service tftp {
        socket_type     = dgram
        protocol        = udp
        wait            = yes
        user            = root
        server          = /usr/sbin/in.tftpd
        server_args     = -s /var/tftpboot -c
        disable         = no
        per_source      = 11
        cps             = 100 2
        flags           = IPv4
        port            = 69
}

Where /var/tftpbootis the server directory.
Modify the /etc/default/tftpd-hpafile as follows:

TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/var/tftpboot"
TFTP_ADDRESS="0.0.0.0:69"
TFTP_OPTIONS="-l -c -s"

Create a server directory /var/tftpboot:

sudo mkdir /var/tftpboot

Modify the directory permissions as follows:

chmod 777 /var/tftpboot

Turn off the Windows firewall, the firewall of WSL2 is shared with Windows, and there is no need to operate Linux.

Start service

sudo service xinetd start  #也可使用`restart`
sudo service tftpd-hpa start

Use to netstat -a | grep tftpcheck whether the service is turned on:
Insert picture description here

test

/var/tftpbootCreate a file in the server directory testwith the content hello.
Use the command to tftp 127.0.0.1enter the tftp operation interface, use get test, and then use to qexit, check whether there are files in the current directory and check whether the testcontents are the same. The same indicates that the setup is successful.
Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46161993/article/details/111475042