Setting up a TFTP server on Linux

Hello everybody,
I've got a TPLink TL-MR6400 V5 and would want to try flashing it.
This rooter has a tftp client, so I followed https://openwrt.org/docs/guide-user/troubleshooting/tftpserver#setting_up_a_tftp_server_on_linux
First, I wanted to try my tftp server locally, but it doesn't work. I'm using dnsmasq.
I followed all steps in the link above but there's a time out with tftp server.
Here some steps:

pascal@pascal-Latitude-5580:/srv/tftp$ sudo netstat -lunp | grep 69
udp        0      0 0.0.0.0:69              0.0.0.0:*                           4118463/dnsmasq     
udp6       0      0 :::69                   :::*                                4118463/dnsmasq

So it seems that server is running.

pascal@pascal-Latitude-5580:/srv/tftp$ ls -l
total 4
-rw-r--r-- 1 nobody nogroup 9 juil. 27 12:54 essais.bin

There's a small test file in the tftp root folder

pascal@pascal-Latitude-5580:~/Téléchargements/essais_tftp$ tftp 127.0.0.1
tftp> get essais.bin
Transfer timed out.

tftp>

Trying on 127.0.0.1

pascal@pascal-Latitude-5580:~/Téléchargements/essais_tftp$ tftp localhost
tftp> get essais.bin
Transfer timed out.

tftp>

Trying on "localhost"
So I tried to add a rule in the firewall, and enable it:

pascal@pascal-Latitude-5580:~/Téléchargements/essais_tftp$ sudo ufw status
[sudo] Mot de passe de pascal : 
État : actif

Vers                       Action      De
----                       ------      --
69/udp                     ALLOW       Anywhere                  
69/udp (v6)                ALLOW       Anywhere (v6)   

But it's the same thing.
Can you help me please ?
Thanks a lot in advance,
Pascal

I use this Bash script on Fedora Linux, and it works fine.
You might want to try changing the values of IFNAME, BOOT_IMG, and options like --listen-address and --dhcp-range depending on your setup.

#!/bin/bash
sudo systemctl stop firewalld.service
IFNAME=enp4s0

nmcli connection delete tftp-profile 
nmcli connection add type ethernet ifname $IFNAME con-name tftp-profile ipv4.method manual ipv4.address 192.168.0.66/24 #ipv4.gateway 192.168.1.10
nmcli connection up tftp-profile

BOOT_IMG=openwrt-23.05.5-ramips-mt76x8-tplink_tl-wr902ac-v3-squashfs-tftp-recovery.bin
/usr/sbin/dnsmasq \
--no-daemon \
--listen-address 192.168.0.66 \
--bind-interfaces \
-p0 \
--dhcp-authoritative \
--dhcp-range=192.168.0.100,192.168.0.200 \
--bootp-dynamic \
--dhcp-boot=$BOOT_IMG \
--log-dhcp \
--enable-tftp \
--tftp-root=$(pwd) \
--log-facility=-

sudo systemctl start firewalld.service
sudo systemctl restart NetworkManager

#when test it
#tftp 192.168.1.10
#get openwrt-23.05.5-ath79-mikrotik-mikrotik_routerboard-mapl-2nd-initramfs-kernel.bin

Hello,
thanks a lot for your reply.
Just before, I tried atftp
before running the daemon, I killed all dnsmasq instances:

sudo killall -I -r dnsmasq

Then, I started atftp daemon:

sudo atftpd --daemon --no-fork --logfile - /srv/tftp
Jul 27 16:33:21 pascal-Latitude-5580 atftpd[41667.130401055061824]: Advanced Trivial FTP server started (0.8.0)
Jul 27 16:33:21 pascal-Latitude-5580 atftpd[41667.130401055061824]: atftpd: can't bind port :69/udp

I understand that something is already using port 69, therefore maybe why dnsmasq doesn't work. So,

sudo lsof -i:69
COMMAND PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
systemd   1 root   92u  IPv6 32618071      0t0  UDP *:tftp

what is that, and why it is using port 69 ?
Thanks a lot in advance.

That's crazy,
in fact port 69 is used by atftpd itself. Indeed,
just after I did

systemctl stop atftpd.service

then

systemctl stop atftpd.socket

and

sudo lsof -i:69

so nothing use port 69 anymore.
So why atftpd complains about it can't bind port 69 ?

that's not really an openwrt question ... :wink:

1 Like

Indeed :smiley:
But my request can be useful for somebody that has the same problem than me when he comes to flash Openwrt firmware :smiley:
I think I found a workaround, I'll come later here to describe it

Imitating network services manually is useless, often dangerous venture.

Why don't you simply use the built in TFTP server in dnsmasq?

Hello,
dnsmasq is the first thing I tried.
But then I tried tftpd-hpa server and it works as a charm: on localhost and from a remote computer.
I don't know the reasons why dnsmasq and atftpd don't work.
I'm on Xubuntu 24.02

2 Likes

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.