Local Network Works, Everything Else Doesn't: A Wrong Default Gateway
A new device on the home network. It can talk to the PC next to it, but it can't reach anything beyond its own network. Let's find out why.
A NAS on a home network can reach the PC next to it, but nothing on another subnet. The NAS, a PC, a switch, a router and a web server on the other side, each in its own container.
The lab
Here is the lab. A NAS and a PC share the home LAN through a switch. The router connects that LAN to a second network, where a media server lives. To reach the server, both devices have to send their traffic through the router.
The symptom
curl -m 5 http://10.0.20.80
curl: (7) Failed to connect to 10.0.20.80:80 after 3054 ms: Could not connect to server
What this shows
Start with the complaint: the NAS can't reach the media server. curl tries the web page at 10.0.20.80 and gives up: failed to connect, could not connect to server.
ping -c 3 10.0.20.80
PING 10.0.20.80 (10.0.20.80) 56(84) bytes of data. From 10.0.10.30 icmp_seq=1 Destination Host Unreachable From 10.0.10.30 icmp_seq=2 Destination Host Unreachable From 10.0.10.30 icmp_seq=3 Destination Host Unreachable --- 10.0.20.80 ping statistics --- 3 packets transmitted, 0 received, +3 errors, 100% packet loss, time 2037ms pipe 3
What this shows
A ping to the same address fails as well. But look at who's answering. Each line says from 10.0.10.30, destination host unreachable. 10.0.10.30 is the NAS itself. The error isn't coming back from the network; the NAS is reporting that it couldn't send the packet on its way.
Narrowing it down
ping -c 3 10.0.10.20
PING 10.0.10.20 (10.0.10.20) 56(84) bytes of data. 64 bytes from 10.0.10.20: icmp_seq=1 ttl=64 time=0.072 ms 64 bytes from 10.0.10.20: icmp_seq=2 ttl=64 time=0.036 ms 64 bytes from 10.0.10.20: icmp_seq=3 ttl=64 time=0.032 ms --- 10.0.10.20 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2045ms rtt min/avg/max/mdev = 0.032/0.046/0.072/0.018 ms
What this shows
So what can the NAS reach? A ping to the PC on the same LAN, 10.0.10.20, gets three replies out of three. Local traffic works.
ping -c 3 10.0.20.80
PING 10.0.20.80 (10.0.20.80) 56(84) bytes of data. 64 bytes from 10.0.20.80: icmp_seq=1 ttl=63 time=0.068 ms 64 bytes from 10.0.20.80: icmp_seq=2 ttl=63 time=0.039 ms 64 bytes from 10.0.20.80: icmp_seq=3 ttl=63 time=0.040 ms --- 10.0.20.80 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2047ms rtt min/avg/max/mdev = 0.039/0.049/0.068/0.013 ms
What this shows
Now the same ping to the server, but from the PC. Three replies out of three. The router and the server are fine, and the path between the networks works. Whatever is wrong is specific to the NAS.
Finding the cause
ip route
default via 10.0.10.254 dev eth1 10.0.10.0/24 dev eth1 proto kernel scope link src 10.0.10.30
What this shows
ip route shows how the NAS decides where to send traffic. The second line says its own network, 10.0.10.0/24, is directly on eth1. The first line is the default route: everything else goes via 10.0.10.254.
ip route
default via 10.0.10.1 dev eth1 10.0.10.0/24 dev eth1 proto kernel scope link src 10.0.10.20
What this shows
The same command on the working PC. Its own network looks the same, but its default route goes via 10.0.10.1. The two devices disagree about where the gateway is.
ip neigh show
10.0.10.254 dev eth1 FAILED 10.0.10.1 dev eth1 lladdr aa:c1:ab:2e:b8:a3 REACHABLE 10.0.10.20 dev eth1 lladdr aa:c1:ab:62:47:e0 REACHABLE
What this shows
ip neigh shows the addresses the NAS has tried to find on its local network. 10.0.10.1 and the PC are reachable. 10.0.10.254 says failed: the NAS asked for it and nothing answered.
ping -c 3 10.0.10.1
PING 10.0.10.1 (10.0.10.1) 56(84) bytes of data. 64 bytes from 10.0.10.1: icmp_seq=1 ttl=64 time=0.045 ms 64 bytes from 10.0.10.1: icmp_seq=2 ttl=64 time=0.034 ms 64 bytes from 10.0.10.1: icmp_seq=3 ttl=64 time=0.032 ms --- 10.0.10.1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2047ms rtt min/avg/max/mdev = 0.032/0.037/0.045/0.005 ms
What this shows
And 10.0.10.1 answers a ping, three out of three. There is a router on this network. The NAS just isn't pointed at it.
The fix
ip route replace default via 10.0.10.1 dev eth1
(no output)
What this shows
ip route replace sets the default route to go via 10.0.10.1, out of eth1.
ip route
default via 10.0.10.1 dev eth1 10.0.10.0/24 dev eth1 proto kernel scope link src 10.0.10.30
What this shows
The routing table now shows default via 10.0.10.1, the same as the PC.
Verifying
ping -c 3 10.0.20.80
PING 10.0.20.80 (10.0.20.80) 56(84) bytes of data. 64 bytes from 10.0.20.80: icmp_seq=1 ttl=63 time=0.061 ms 64 bytes from 10.0.20.80: icmp_seq=2 ttl=63 time=0.048 ms 64 bytes from 10.0.20.80: icmp_seq=3 ttl=63 time=0.040 ms --- 10.0.20.80 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 2056ms rtt min/avg/max/mdev = 0.040/0.049/0.061/0.008 ms
What this shows
The ping to the media server gets three replies out of three.
curl -m 5 http://10.0.20.80
<!doctype html> <title>homelab media server</title> <h1>homelab media server</h1> <p>It works.</p>
What this shows
And the same curl that failed at the start now returns the page. It works.
Why local traffic still worked
So why did the PC next to it keep working the whole time? A device sends traffic for its own network straight to the destination. It only uses the default gateway for everything else. With the gateway pointing at an address where nothing exists, local traffic was never affected, and everything beyond the network failed at the first step. This change was made by hand, so it won't survive a restart. On a real device, fix the gateway wherever its network settings come from, the static configuration or the DHCP server.
When a device reaches its own network and nothing else, check the default gateway. ip route shows where it points, and ip neigh shows whether anything answers there.
Try it yourself
The whole lab runs on your own computer with Docker and containerlab: get it on GitHub, then ./lab.sh up and ./lab.sh break. Setup steps are on Run the labs.