ip addr & ip route
Your address and your route
Lesson 18 of 20 · 10 min · Module 6: Networking from the shell
Every networked computer has interfaces, addresses, and a route to the rest of the world. The ip command shows all three.
Start this lesson →Free. No installation: you write and run the code in your browser, and it is checked automatically.
By the end, you’ll be able to…
- List interfaces and addresses
- Recognise loopback and local addresses
- Find the default gateway
The idea
ip addr (or ip a) lists network interfaces and their addresses. lo is the loopback interface (127.0.0.1, the machine talking to itself). ip route shows where traffic goes. The default via line names the gateway: the router for every address not on your local network.
ip addr show eth0
ip route
01Read an interface block
inet 192.168.1.50/24 is the IPv4 address with its prefix length: the first 24 bits (192.168.1) identify the local network. link/ether is the hardware (MAC) address of the network card.
ip addr show eth02: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP
link/ether 52:54:00:12:34:56
inet 192.168.1.50/24 scope global eth002Loopback never leaves the machine
127.0.0.1 on lo always means "this computer". Services that listen only on 127.0.0.1 cannot be reached from other machines, which is often deliberate for databases.
03The default route is the way out
192.168.1.0/24 dev eth0 means local addresses are reached directly. Everything else follows default via 192.168.1.1, the router.
Your turn
eth0 interface only. Then save the default route line from ip route into route.txt in your home folder.What the checks look for
- Shows eth0 with address 192.168.1.50/24
- route.txt contains only the default route
Take this with you
ip addr shows who you are on the network; ip route shows how you reach everyone else.
Go a little further
Run ip route and explain in one sentence why 192.168.1.20 does not use the gateway.