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.
-
outsider:~# ssh -p 2222 admin@10.0.2.2 hostname - From outside:
Host is unreachable. The router forwards to an address nobody has now.ssh: connect to host 10.0.2.2 port 2222: Host is unreachable
-
nas:~# ip -br addr - The server's address is
10.0.1.20, not the10.0.1.10the forward was made for.… eth0@if60262 UP 10.0.1.20/24
-
outsider:~# curl -sS -m 4 http://10.0.2.2:8080/ - A different case: a forward the firewall blocks times out.
curl: (28) Connection timed out after 4004 milliseconds
Fix
-
nas:~# ip addr replace 10.0.1.10/24 dev homeNetwork - Give the server back the address the forward uses (a fixed address, or a DHCP reservation).
nas:~# ip -br addr show homeNetwork eth0@if60262 UP 10.0.1.20/24 10.0.1.10/24
-
outsider:~# ssh -p 2222 admin@10.0.2.2 hostname - The forward works again.
nas
-
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 10.0.1.10:22 - 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.
- A home router: NAT, one port forward, and the firewall : its challenge "The NAS vanished from outside" set the fault for you to find and fix.