network:ax4200:enable_tftp_booting

This is an old revision of the document!


Enable TFTP booting

The TUF AX4200 runs dnsmasq as its DHCP server. dnsmasq contains a built-in TFTP server and can hand out next-server/bootfile options, so the router itself can serve PXE/TFTP booting to LAN clients.

Stock firmware gives no way to add dnsmasq options or open the TFTP firewall port, and neither survives a reboot. So the setup is: a startup script that patches the running configuration on every boot. The boot mechanism behind it (asusware.arm app mechanism) is described in Install additional software.

All involved files from the router are kept as a mirror under network/ax4200/router-files/.

What is done on every boot

The script mnt/sda1/data/patch-and-restart-dnsmasq.sh runs at boot (via the S99patch-and-restart-dnsmasq init script; see the Install additional software page for how that works) and does three things:

  1. Feed extra dnsmasq options from the USB stick: it removes any existing conf-dir= line from /etc/dnsmasq.conf and appends

    conf-dir=/tmp/mnt/sda1/data/dnsmasq.d

    so dnsmasq additionally reads the drop-in config in mnt/sda1/data/dnsmasq.d/. This is where the TFTP/PXE options go (see below). Because /etc is on a tmpfs-like overlay, patching it from a script is the only way to make it happen at every boot.

  2. Open the TFTP firewall port on the LAN bridge (br0):

    iptables -A INPUT -i br0 -p udp --dport 69 -m state --state NEW,ESTABLISHED -j ACCEPT
    iptables -A OUTPUT -p udp --sport 69 -m state --state ESTABLISHED -j ACCEPT

    Without this, the stock firewall silently drops the TFTP requests from LAN clients.

  3. Restart dnsmasq so the patched config takes effect: killall -TERM dnsmasq, wait 10 seconds, then start it again with dnsmasq --log-async. (The firmware's watchdog respawns it; the script starts it explicitly to be sure.)

The script logs each step with logger -t S99-patch-and-restart-dnsmasq — check Administration → System Log after a reboot to confirm it ran.

dnsmasq drop-in: `mnt/sda1/data/dnsmasq.d/dnsmasq.conf`

The drop-in read via conf-dir= enables dnsmasq's built-in TFTP server and hands out boot files via DHCP:

# Enable dnsmasq's built-in TFTP server
enable-tftp
# Root directory served via TFTP
tftp-root=/tmp/mnt/sda1/data/tftpboot
# BIOS boot file
dhcp-boot=pxelinux.0
# EFI boot files (override for arch 7/9 clients)
dhcp-match=set:efi-x86_64,option:client-arch,7
dhcp-match=set:efi-x86_64_9,option:client-arch,9
dhcp-boot=tag:efi-x86_64,grubnetx64.efi.signed
dhcp-boot=tag:efi-x86_64_9,grubnetx64.efi.signed
# Use only port 69 for both directions of the TFTP transfer
tftp-single-port
  • Boot images (pxelinux, grubnetx64.efi.signed, kernels, initrds) live under mnt/sda1/data/tftpboot/.
  • tftp-single-port keeps both directions of the transfer on UDP port 69 — that is what makes the simple two-rule firewall opening above sufficient (a compliant multi-port TFTP server would need a dynamic port range opened as well). The tradeoff is documented in the file: not strictly RFC-compliant, but rescues firewall/broken-client situations.
  • The same drop-in also carries the non-TFTP DNS customisations (local zones, address= overrides, addn-hosts= files on the USB stick) — it is the general dnsmasq config for this router, not just for TFTP.

Files on the router (mirror in router-files/)

Router pathPurpose
mnt/sda1/data/patch-and-restart-dnsmasq.shThe real script: patch dnsmasq config, open firewall, restart dnsmasq
mnt/sda1/data/dnsmasq.d/dnsmasq.confdnsmasq drop-in: TFTP/PXE options and general DNS customisations
mnt/sda1/asusware.arm/etc/init.d/S99patch-and-restart-dnsmasqSymlink to the script above, so the firmware runs it at boot
mnt/sda1/asusware.arm/lib/ipkg/info/patch-and-restart-dnsmasq.controlEnabled: yes — without it the start script is skipped
usr/sbin/app_init_run.shFirmware script that runs the /opt/etc/init.d/S* scripts
usr/sbin/app_get_field.shFirmware script that reads the Enabled: field from the .control file

Notes

  • Keep the editable content on the USB stick (data/), not on /opt: the firmware copies init scripts to /opt/<name>.1 before running them, so direct edits inside the app directory have no effect until the next remount.
  • A killall dnsmasq briefly interrupts DHCP/DNS for the LAN; do this deliberately, not during heavy use.
  • To change what the clients boot, only the drop-ins in data/dnsmasq.d/ need editing, then restart dnsmasq (or reboot).
network/ax4200/enable_tftp_booting.1792946997.txt.gz · Last modified: by admin