needy-wire.dev

Redirecting port ranges with nftables, without iptables-translate

Most guides still show iptables. With nftables a whole range can be redirected with a single rule in a nat chain:

table inet example {
  chain prerouting {
    type nat hook prerouting priority dstnat;
    udp dport 20000-30000 counter redirect to :8000
  }
}

The counter keyword costs nothing and saves hours: nft list ruleset immediately tells you whether packets reach the rule at all.

Remember to persist it in /etc/nftables.conf and enable nftables.service, otherwise the next reboot quietly undoes everything.