rss logo

GNU/Linux - How to install and configure a TFTP server

Tux logo

TFTP (Trivial File Transfer Protocol) is a simple File Transfer Protocol that allows a client to get or put a file to a remote host.

It is an old protocol, but it is still used in many network applications.

Personally, I use it to update the firmware of my network equipment. (e.g. Cisco switches).

Here's how to set up a TFTP server on Debian.

Network Diagram

  • OS: Debian 12 (bookworm)
  • Tftp server: atftpd
  • Network Protocol: UDP 69
  • Tftp directory: /srv/tftp
Diagram illustrating the setup of a TFTP server on Debian, showing a laptop connected to a local area network (LAN) with IP addresses and a TFTP folder containing necessary files.
Debian tftp server architecture

Installation

  • Update package sources list:
root@server:~# apt update
  • Install the atftpd package:
root@server:~# apt install atftpd
  • Create a /srv/tftp folder. We will use this as the root tftp share:
root@server:~# ls /srv/tftp || mkdir -p /srv/tftp

Configuration

Network Configuration

  • Edit the file /etc/network/interfaces (replace ens224 by your own network interface):
allow-hotplug ens224
iface ens224 inet static
        address 192.168.1.10
        netmask 255.255.255.0
        gateway 192.168.1.254
	dns-nameservers 192.168.1.254
  • Restart the system or network service so that changes are taken into account:
root@host:~# systemctl restart networking

TFTP service configuration

  • Edit /etc/default/atftpd and check that you have the same settings:
USE_INETD=true
# OPTIONS below are used only with init script
OPTIONS="--tftpd-timeout 300 --retry-timeout 5 --mcast-port 1758 --mcast-addr 239.239.239.0-255 --mcast-ttl 1 --maxthread 100 --verbose=5 /srv/tftp"
  • Restart the atftpd service:
root@server:~# systemctl restart atftpd.service
  • Set read and write permissions so that the files in /srv/tftp are readable and writable:
root@server:~# chmod -R ugo+rw /srv/tftp/

Checking from a client

To check that our server is working properly, we can use a TFTP client.

  • If you are using a Debian machine (which is a good choice!), install the TFTP client:
root@client:~# apt update && apt install tftp
  • Connect to the TFTP server:
user@client:~$ tftp 192.168.1.10
  • Show status:
tftp> status
Connected to 192.168.1.10.
ode: netascii Verbose: off Tracing: off
Rexmt-interval: 5 seconds, Max-timeout: 25 seconds
  • Download a file:
tftp> get c1000-universalk9-mz.152-7.E4.bin
  • Send a file:
tftp> put c1000-universalk9-mz.152-7.E4.bin
  • Exit session:
tftp> quit

DHCP server

In some situations, setting up a DHCP server may be necessary. Here is how to do it.

  • Install the dhcpd service:
root@client:~# apt update && apt install isc-dhcp-server
  • Edit the /etc/dhcp/dhcpd.conf file, here with an address pool from 192.168.10.10 to 192.168.10.20:
option domain-name "example.org";
default-lease-time 600;
max-lease-time 7200;
ddns-update-style none;

subnet 192.168.10.0 netmask 255.255.255.0 {
  range 192.168.10.10 192.168.10.20;
}
  • Edit the /etc/default/isc-dhcp-server file and specify the network interface on which the dhcp service will run:
INTERFACESv4="ens224"
#INTERFACESv6=""
  • Restart the dhcpd service:
root@client:~# systemctl restart isc-dhcp-server.service
  • Show the dhcpd leases:
root@client:~# grep dhcpd /var/log/syslog