Ubuntu TFTP service building and exception maintenance

Keywords: sudo network vim ftp

TFTP is a file transfer protocol similar to FTP, but it does not require user authentication and cannot list directories. The TFTP server always listens for requests from PXE clients on the network. When it detects that PXE client requests PXE service in the network, it will provide network data package containing boot menu.

1. installation

$ sudo apt install tftp-hpa tftpd-hpa openbsd-inetd

tftp is the client for testing and downloading;
tftpd is the server;
OpenBSD inetd is the automatic start service of tftp

2. Create tftp server root directory / tftpboot

$ sudo mkdir -p /tftpboot/
$ sudo chmod 0777 /tftpboot/

3. Modify the configuration file

$ sudo vim /etc/inetd.conf
tftp    dgram   udp    wait    root    /usr/sbin/in.tftpd /usr/sbin/in.tftpd -s /tftpboot
$ sudo vim /etc/default/tftpd-hpa
TFTP_USERNAME="tftp"
TFTP_DIRECTORY="/tftpboot"
TFTP_ADDRESS=":69"
#TFTP_OPTIONS="--secure"
TFTP_OPTIONS="-l -c -s"
RUN_DAEMON="yes"
OPTIONS="-l-s /tftpboot"

4. boot

$ sudo update-inetd --enable BOOT
$ sudo service tftpd-hpa start/restart 

5. test

$ sudo netstat -lu

The following is normal:

Proto Recv-Q Send-Q Local Address    Foreign Address         State
udp        0      0 *:tftp                  *:*

Download test:

$ vim /tftpboot/test.txt

Whatever you write:

test:This file is used to test the TFTP server

On the local or another host (to download the tftp client)

$ tftp server-ip
tftp-> get test.txt
tftp-> quit/exit

View content in local punch file

6. Abnormal maintenance
What happened:
Under the normal condition of configuration file, tftp service status is abnormal after restarting the server: / etc/init.d/tftpd-hpa status

● tftpd-hpa.service - LSB: HPA's tftp server
   Loaded: loaded (/etc/init.d/tftpd-hpa; bad; vendor preset: enabled)
   Active: failed (Result: exit-code) since Wed 2017-05-07 10:56:19 UTC; 1min 17s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 3971 ExecStart=/etc/init.d/tftpd-hpa start (code=exited, status=71)

Feb 07 10:56:19 HOST001 systemd[1]: Starting LSB: HPA's tftp server...
Feb 07 10:56:19 HOST001 tftpd-hpa[3971]:  * Starting HPA's tftpd in.tftpd
Feb 07 10:56:19 HOST001 systemd[1]: tftpd-hpa.service: Control process exited, code=exited status=71
Feb 07 10:56:19 HOST001 systemd[1]: Failed to start LSB: HPA's tftp server.
Feb 07 10:56:19 HOST001 systemd[1]: tftpd-hpa.service: Unit entered failed state.
Feb 07 10:56:19 HOST001 systemd[1]: tftpd-hpa.service: Failed with result 'exit-code'.

Restart also failed: / etc/init.d/tftpd-hpa restart

  [....] Starting tftpd-hpa (via systemctl): tftpd-hpa.serviceJob for tftpd-hpa.service failed because the control process exited with error code. See "systemctl status tftpd-hpa.service" and "journalctl -xe" for details.
 failed!

Solution: I spent a lot of time doing this. I checked the configuration file again and again. I tried to uninstall and reinstall it. The problem is still... However, it seems that the tftp service failed to start, but the file can still be downloaded. Then the following methods are used to solve the problem:

$ sudo /etc/init.d/openbsd-inetd stop 
[ ok ] Stopping openbsd-inetd (via systemctl): openbsd-inetd.service.

$ sudo /etc/init.d/tftpd-hpa start 
[ ok ] Starting tftpd-hpa (via systemctl): tftpd-hpa.service.

$ sudo /etc/init.d/tftpd-hpa restart 
[ ok ] Restarting tftpd-hpa (via systemctl): tftpd-hpa.service.

$ sudo /etc/init.d/openbsd-inetd start 
[ ok ] Starting openbsd-inetd (via systemctl): openbsd-inetd.service.

Posted by Vermillion on Thu, 09 Apr 2020 11:03:26 -0700