Linux Basics Lesson 31 of 38
Addresses and reachability
8 minutes
Learning goals
- Read the addresses of a server with ip a and ip -br a, and tell the loopback from the real network card.
- Find the default gateway with ip route.
- Check with ping -c whether another machine answers, and know what a missing answer does not prove.
ip: who am I on the network
ip a lists every network interface with its addresses. With -br, for brief, you get one line per interface, and that is usually enough:
ip -br a
Purpose: Shows the network interfaces with their addresses, and the routes.
Syntax: ip [-br] a | ip route
Options:
Example:
ip -br a
lo UNKNOWN 127.0.0.1/8 ::1/128
eth0 UP 203.0.113.10/24 Two interfaces. lo is the loopback with 127.0.0.1. It exists only inside the machine: whatever is sent there never leaves it. eth0 is the real network card, with 203.0.113.10/24. The /24 says that the first three numbers name the network, so 203.0.113.1 to 203.0.113.254 are neighbours that can be reached directly.
hostname -I prints only the addresses, without the loopback. The full ip a adds the hardware address and the MTU of each interface:
hostname -I
203.0.113.10
ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host proto kernel_lo
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 52:54:00:12:34:56 brd ff:ff:ff:ff:ff:ff
inet 203.0.113.10/24 brd 203.0.113.255 scope global eth0
valid_lft forever preferred_lft forever
On older guides you will find ifconfig. It belongs to the package net-tools, which new Debian, Ubuntu and RHEL installations no longer include. ip does the same job and more.
ip route: where the traffic goes
An address alone is not enough. The server also has to know where to send packets for other networks:
ip route
default via 203.0.113.1 dev eth0
203.0.113.0/24 dev eth0 proto kernel scope link src 203.0.113.10
The first line is the important one. default via 203.0.113.1 means: everything that is not in the own network goes to the gateway 203.0.113.1. The second line covers the own network, which eth0 reaches directly. If the default line is missing, the server talks to its neighbours and to nobody else.
ping: are you there?
ping sends small test packets and waits for the answers. -c 3 stops after three. Without -c it keeps going until you press Ctrl-C:
ping -c 3 203.0.113.1
Purpose: Checks whether a machine answers, and how fast.
Syntax: ping -c COUNT HOST
Options:
Example:
ping -c 3 203.0.113.1
PING 203.0.113.1 (203.0.113.1) 56(84) bytes of data.
64 bytes from 203.0.113.1: icmp_seq=1 ttl=64 time=0.412 ms
64 bytes from 203.0.113.1: icmp_seq=2 ttl=64 time=0.412 ms
64 bytes from 203.0.113.1: icmp_seq=3 ttl=64 time=0.412 ms
--- 203.0.113.1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.412/0.412/0.412/0.000 msThree sent, three received, and the times in milliseconds. ping also takes a name and looks it up first:
ping -c 1 shop.example.net
PING shop.example.net (198.51.100.7) 56(84) bytes of data.
64 bytes from shop.example.net (198.51.100.7): icmp_seq=1 ttl=64 time=12.8 ms
--- shop.example.net ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 13ms
rtt min/avg/max/mdev = 12.800/12.800/12.800/0.000 ms
A missing answer proves less than it seems. Many servers and firewalls drop ping packets on purpose and run perfectly well. The other way round, "ping works, but the app does not" is a valuable finding: the machine is reachable, so the problem sits with the service or its port. That is the next lesson.
cat, grep and ls are not loaded on this page and answer with command not found. You do not need them here.
Practice
Terminal task 1/3
Which address does this server have on its real network card? Show the interfaces.
Task 1/3: Which address does this server have on its real network card? Show the interfaces.
Which address does this server have on its real network card? Show the interfaces.
Task complete
Solution
ip -br a Why: 203.0.113.10 on eth0. The 127.0.0.1 on lo is the loopback and only exists inside the machine, so that is not the address anybody else can reach.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
Terminal task 2/3
Where does the traffic go that does not stay in the own network? Show the default gateway.
Task 2/3: Where does the traffic go that does not stay in the own network? Show the default gateway.
Where does the traffic go that does not stay in the own network? Show the default gateway.
Task complete
Solution
ip route Why: default via 203.0.113.1 is the gateway. Without this line the server only reaches its own network, 203.0.113.0/24.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
Terminal task 3/3
Check whether the gateway 203.0.113.1 answers. Send exactly three packets, so that ping stops by itself.
Task 3/3: Check whether the gateway 203.0.113.1 answers. Send exactly three packets, so that ping stops by itself.
Check whether the gateway 203.0.113.1 answers. Send exactly three packets, so that ping stops by itself.
Task complete
Solution
ping -c 3 203.0.113.1 Why: Three out, three back, no loss. The way to the gateway works. A real server could still drop ping on purpose, so a missing answer would not have been a proof of the opposite.
See the solution? You get fewer XP for this task.
Start over? Files, folders and output go back to the start. Your hints stay.
Loading terminal …
Esc, then Tab leaves the terminal
Not done yet
Repeat: you have solved this task before.
Fill the gap
127.0.0.1 belongs to the interface lo, the , and it only exists inside the machine.
127.0.0.1 belongs to the interface lo, the …, and it only exists inside the machine.
Check works once you have typed an answer.
Build the command
Build the line that checks the gateway with three packets and then stops.
Your command
Building blocks
Check works once your command has at least one block.
Next up: which program listens on which port, and what answers there.
Quiz
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
-
Check works once you have chosen an answer.
Cards
-
Card 1 of 3
Tap the card or press Space to turn it over.
-
Card 2 of 3
Tap the card or press Space to turn it over.
-
Card 3 of 3
Tap the card or press Space to turn it over.
End of the lesson
Still open: 5 exercises, 3 quiz questions
What you can do now: ip -br a, ping -c 3 203.0.113.1
+0 XP in this lesson
- Lesson 1: open
- Lesson 2: open
- Lesson 3: open
- Lesson 4: open
- Lesson 5: open
- Lesson 6: open
- Lesson 7: open
- Lesson 8: open
- Lesson 9: open
- Lesson 10: open
- Lesson 11: open
- Lesson 12: open
- Lesson 13: open
- Lesson 14: open
- Lesson 15: open
- Lesson 16: open
- Lesson 17: open
- Lesson 18: open
- Lesson 19: open
- Lesson 20: open
- Lesson 21: open
- Lesson 22: open
- Lesson 23: open
- Lesson 24: open
- Lesson 25: open
- Lesson 26: open
- Lesson 27: open
- Lesson 28: open
- Lesson 29: open
- Lesson 30: open
- Lesson 31: done
- Lesson 32: open
- Lesson 33: open
- Lesson 34: open
- Lesson 35: open
- Lesson 36: open
- Lesson 37: open
- Lesson 38: open
Cheat sheet
-
ip -br aevery interface and its addresses, one line each -
ip routethe routes, default via is the gateway -
hostname -Ionly the addresses, without the loopback -
ping -c 3 <host>three test packets, then stop
The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.
- Download PDF (PDF, 19 KB)
- View as image (PNG, 66 KB)