terminal.cab

Linux Basics Lesson 31 of 38

guestLevel 1Badges and progress0/100 XP, XP to the next levelStreak0

Addresses and reachability

8 minutes

Learning goals

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:

  • a short for address, every interface with its addresses
  • -br brief, one line per interface
  • route the routes, with the default gateway in the first line

Example:

ip -br a
lo               UNKNOWN        127.0.0.1/8 ::1/128 
eth0             UP             203.0.113.10/24 

in the glossary: ip

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:

  • -c 3 stop after three packets
  • HOST an address or a name, ping looks the name up first

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 ms

in the glossary: ping

Three 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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

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.

Loading terminal …

lerner@web-01: ~bash
lerner@web-01:~$

Esc, then Tab leaves the terminal

Not done yet

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

    Tap the blocks below to build the 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

    1. Question 1 of 3ip -br a shows lo with 127.0.0.1/8 and eth0 with 203.0.113.10/24. Which address can another machine reach?

      Check works once you have chosen an answer.

    2. Question 2 of 3ping to a server gets no answer at all. What do you know for sure?

      Check works once you have chosen an answer.

    3. Question 3 of 3Which line of ip route says where the traffic for other networks goes?

      Check works once you have chosen an answer.

    Cards

    1. Card 1 of 3

      Tap the card or press Space to turn it over.

    2. Card 2 of 3

      Tap the card or press Space to turn it over.

    3. 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

    Next: lesson 32, Who listens, and what answers (9 min)

    What you can do now: ip -br a, ping -c 3 203.0.113.1

    +0 XP in this lesson

    1. Lesson 1: open
    2. Lesson 2: open
    3. Lesson 3: open
    4. Lesson 4: open
    5. Lesson 5: open
    6. Lesson 6: open
    7. Lesson 7: open
    8. Lesson 8: open
    9. Lesson 9: open
    10. Lesson 10: open
    11. Lesson 11: open
    12. Lesson 12: open
    13. Lesson 13: open
    14. Lesson 14: open
    15. Lesson 15: open
    16. Lesson 16: open
    17. Lesson 17: open
    18. Lesson 18: open
    19. Lesson 19: open
    20. Lesson 20: open
    21. Lesson 21: open
    22. Lesson 22: open
    23. Lesson 23: open
    24. Lesson 24: open
    25. Lesson 25: open
    26. Lesson 26: open
    27. Lesson 27: open
    28. Lesson 28: open
    29. Lesson 29: open
    30. Lesson 30: open
    31. Lesson 31: done
    32. Lesson 32: open
    33. Lesson 33: open
    34. Lesson 34: open
    35. Lesson 35: open
    36. Lesson 36: open
    37. Lesson 37: open
    38. Lesson 38: open
    1 of 38

    Next: lesson 32, Who listens, and what answers (9 min) That's enough for today

    Path complete

    You finished all 38 lessons of Linux Basics.

    Back to the path

    Cheat sheet

    The most important command lines of this module on one A4 page, black and white, to print or keep on your phone.