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's an old protocol, but still used in many network applications.

Personnaly, I use it to update the firmware on my network equipment. (Cisco switches for examples).

Here"s how to set up a TFTP server under Debian.

Network Diagram

  • OS: Debian 12 (bookworm)
  • Tftp server: atftpd
  • Network Protocol: UDP 69
  • Tftp directory: /srv/tftp
GNU/Linux | Debian tftp server architecture
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 on a Debian machine (which is a good thing!), 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, it may be necessary to set up a DHCP server, we we'll show you how.

  • 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
Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Contact :

contact mail address