This message comes at once and without a single packet on the wire: the kernel looks for a route to the destination and finds none. So the problem is on your own machine, not in the network behind it.
Symptom
sudo ip netns exec links ping -c1 -W1 172.16.0.123 ping: connect: Network is unreachable
In the course the namespace links has a cable to the host and an address. It reaches the host on its address 10.10.1.1, but not on its second address 172.16.0.123.
Diagnosis
Read the sender's routes – only destinations in these networks are reachable. In the course the namespace rot shows the same picture with a single line.
sudo ip -n rot route 10.0.0.0/24 dev veth-rot proto kernel scope link src 10.0.0.1
Causes
no default routeOnly the own network exists
With the address the kernel creates a route to its own network automatically. Everything else needs a route – usually the default route via a gateway.
interface downThe route disappeared with the interface
When an interface goes down, the kernel deletes its routes. After that ping shows the same message until interface and route are back.
Fix
sudo ip -n links route add default via 10.10.1.1 sudo ip -n links route default via 10.10.1.1 dev eth0 10.10.1.0/24 dev eth0 proto kernel scope link src 10.10.1.2 sudo ip netns exec links ping -c1 -W1 172.16.0.123 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.186/0.186/0.186/0.000 ms
Don't: Suspecting the firewall first. “Network is unreachable” means the packet never left – a firewall further on never saw it.
Linux networking hands-on, Day 2: namespaces, veth cables, the default route and the host as a router.
Go to day 2 →
FAQ
What is the difference to “Destination Host Unreachable”?
Network is unreachable is reported by your own kernel before a packet leaves. Destination Host Unreachable arrives as an ICMP reply from a router on the way.
Which path would a packet take?
ip route get DEST shows it; if a route is missing, this command reports “Network is unreachable” as well.