NETWORK INCIDENTS

ip addr and ip route Explained for Beginners: Your Address and Your Way Out

Network+ 5.3 Route selection: routing table, default routesNetwork+ 5.5 Command-line tools: ip

Before you can fix a network problem, a device has to answer two questions: what's my address, and where do I send my traffic? On Linux, ip addr and ip route answer them. Here's how to read both.

Two small home networks joined by a router: a PC and a NAS on one side, a web server and a printer on the other. Open a shell on the PC and read its address and its routing table, ask ip route get which way an address would go, then look at the router, which has an address on each network.

The lab

The same lab as the ping episode: two home networks joined by a router. The PC and the NAS on one side, a web server and a printer on the other. The router is 10.0.10.1 on the PC's side, and 10.0.20.1 on the other.

Your addresses

on pc
ip -br addr show up
lo               UNKNOWN        127.0.0.1/8 ::1/128
eth1@if1154      UP             10.0.10.20/24 fe80::a8c1:abff:fe78:ea05/64
What this shows

On the PC, ip addr with dash b r gives the brief version, and show up skips anything that's switched off. One line per interface. lo is the loopback: the computer talking to itself, always 127.0.0.1. eth1 is the network card: it's up, and its address is 10.0.10.20 slash 24. The fe80 address after it is an IPv6 address every interface gives itself; you can ignore it here.

on pc
ip addr show eth1
1155: eth1@if1154: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether aa:c1:ab:78:ea:05 brd ff:ff:ff:ff:ff:ff link-netnsid 1
    inet 10.0.10.20/24 scope global eth1
       valid_lft forever preferred_lft forever
    inet6 fe80::a8c1:abff:fe78:ea05/64 scope link
       valid_lft forever preferred_lft forever
What this shows

Without dash b r, you get everything about one interface. link ether is its MAC address, the hardware address the local network uses. And inet is the IPv4 address, 10.0.10.20, slash 24. The slash 24 describes which addresses count as the PC's own network. That's worth a video of its own, so for now, just notice it's there.

Where traffic goes

on pc
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

ip route shows where traffic goes, and here it's just two lines. The second one first: 10.0.10.0 slash 24 is on eth1, directly. Anything on the PC's own network, it sends straight there. And default via 10.0.10.1: everything else goes to the router, the default gateway. That's the whole decision for most computers: is it on my network? If not, send it to the gateway.

on pc
ip route get 10.0.20.80
10.0.20.80 via 10.0.10.1 dev eth1 src 10.0.10.20 uid 0
    cache
What this shows

ip route get asks which way one particular address would go. The web server, 10.0.20.80, isn't on the PC's network, so it goes via 10.0.10.1, the router, out of eth1.

on pc
ip route get 10.0.10.30
10.0.10.30 dev eth1 src 10.0.10.20 uid 0
    cache
What this shows

And the NAS, 10.0.10.30: no via this time. It's on the same network, so the PC sends to it directly.

The router

on router
ip -br addr show up
lo               UNKNOWN        127.0.0.1/8 ::1/128
eth1@if1148      UP             10.0.10.1/24 fe80::a8c1:abff:febe:2a92/64
eth2@if1150      UP             10.0.20.1/24 fe80::a8c1:abff:fe01:50e3/64
What this shows

So what makes the router different? Same command, on the router. It has two network cards, and an address on each network: 10.0.10.1 on one, 10.0.20.1 on the other.

on router
ip route
10.0.10.0/24 dev eth1 proto kernel scope link src 10.0.10.1
10.0.20.0/24 dev eth2 proto kernel scope link src 10.0.20.1
What this shows

And its routing table knows both networks directly, one on each card. With forwarding switched on, that's all a router is: a computer with a foot in each network, passing traffic between them.

Recap

So: ip addr tells you what your address is, and which network it's on. ip route tells you what you can reach directly, and who you send everything else to. When a device can't reach something, check both: the wrong address or the wrong gateway breaks everything beyond its own network.

On Windows and Mac

On Windows, ipconfig shows each adapter's addresses, subnet mask and default gateway, and route print shows the routing table. On a Mac, in Terminal, ifconfig shows the addresses, and netstat dash r n shows the routing table. Different names, the same two questions. The Learn page on networkincidents.ca has the details.

Windowsipconfigaddresses, subnet mask and default gateway
Windowsroute printthe routing table
Macifconfig · netstat -rnin Terminal: addresses, then the routing table
Where am I, and how do I get out?

Where am I, and how do I get out? Ask ip addr, then ip route.

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.