Fix
Port forwarding stopped working
The router forwards the port to the server's old address, or the forward rule is gone. Check the DNAT rule and the server's address; give it a fixed one.
Likely causes
- The server got a new address from DHCP; the forward still points at the old one.
- The DNAT rule was lost (a reset or a firmware update): the router refuses the port itself.
- The firewall blocks the forwarded port even though the DNAT rule exists.
Diagnose
Run these in order. The output is what each printed on a lab's real Linux machines.
-
customer:~# curl -sS -m 2 http://203.0.113.2/ - From outside: the connection times out. The router forwards to an address nobody has now.
curl: (28) Connection timed out after 2005 milliseconds
-
workshopRouter:~# iptables -t nat -S PREROUTING - The forward still points at
192.168.50.20.-P PREROUTING ACCEPT -A PREROUTING -j NETLAB-PREROUTING -A PREROUTING -d 203.0.113.2/32 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.50.20 -A PREROUTING -s 198.51.100.60/32 -d 203.0.113.2/32 -p tcp -m tcp --dport 8080 -j DNAT --to-destination 192.168.50.30:80
-
bookings:~# ip -br addr show dev workshop - The server's address is
192.168.50.21, not the192.168.50.20the forward was made for.eth0@if7230 UP 192.168.50.21/24
Fix
-
workshopRouter:~# iptables -v -t nat -D PREROUTING -d 203.0.113.2 -p tcp --dport 80 -j DNAT --to-destination 192.168.50.20 - Delete the forward that points at the old address.
DNAT tcp opt -- in * out * 0.0.0.0/0 -> 203.0.113.2 tcp dpt:80 to:192.168.50.20
-
workshopRouter:~# iptables -v -t nat -A PREROUTING -d 203.0.113.2 -p tcp --dport 80 -j DNAT --to-destination 192.168.50.21 - Add it again with the new address. Then give the server a fixed address or a DHCP reservation, so it can't move again.
DNAT tcp opt -- in * out * 0.0.0.0/0 -> 203.0.113.2 tcp dpt:80 to:192.168.50.21
-
customer:~# curl -sS -m 3 http://203.0.113.2/ - The forward works again.
Spoke and Chain bookings: next free slot Tuesday 10:30
-
iptables -t nat -A PREROUTING -d 203.0.113.2 -p tcp --dport 80 -j DNAT --to-destination 192.168.50.20 - When the rule itself is gone: add the DNAT back on the router.
Break it and fix it yourself
Each lab is a small network of real Linux machines in your browser, where this fault happens.
- Port forwarding: let the internet reach one machine behind NAT : its challenge "The page vanished with the old router" set the fault for you to find and fix.
Open Port forwarding: let the internet reach one machine behind NAT