How Networks Work Module 1: What a network is Lesson 1.4 12 min

Your first lab: two laptops and a cable

Join two laptops with one cable, give them addresses and send the first ping. Learn to read ip addr and ping line by line, and see what happens when nobody answers.

The smallest network there is: two laptops and one cable between them. No router, no internet, no Wi-Fi. Can they talk?

They can, if each one has an address and they agree which network they are on. In this lesson you will type your first two commands, ip addr and ping, and learn to read every line they print.

Your first commands

A terminal is a window where you type commands instead of clicking. You type a line, press Enter, and the computer prints its answer. In the labs, a line starting with $ is what was typed; everything under it is the answer. The terminal in the lab is labelled “Simulated”: it prints what a Linux computer would print, but no real machine is behind it.

Two laptops, one cable, three pings

  1. laptop-a: ip addr laptop-a lists its network interfaces: the ways it can connect to a network.
    Time
    0 µs
  2. laptop-a: ping -c 3 192.168.1.11 Now it pings laptop-b three times (-c 3 means "count 3").
    Time
    0 µs
    Cable
    laptop-a eth0 → laptop-b eth0
    Ethernet
    02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
    ARP
    who has 192.168.1.11? tell 192.168.1.10
    On the wire
    64 bytes
    laptop-a ARP cache
    192.168.1.11: asking (INCOMPLETE)
  3. laptop-b: ARP: 192.168.1.11 is at 02:00:00:00:00:0b Before the first ping can leave, laptop-a has to find laptop-b's hardware address. You will see how in Lesson 2.3.
    Time
    100.512 µs
    Cable
    laptop-b eth0 → laptop-a eth0
    Ethernet
    02:00:00:00:00:0b → 02:00:00:00:00:0a
    ARP
    192.168.1.11 is at 02:00:00:00:00:0b
    On the wire
    64 bytes
    laptop-b ARP cache
    192.168.1.10 is at 02:00:00:00:00:0a
  4. laptop-a: ICMP echo request seq=1 192.168.1.10 → 192.168.1.11 laptop-a sends an ICMP echo request ("are you there?") to 192.168.1.11, in a frame addressed to laptop-b. laptop-a saves it in its ARP cache: 192.168.1.11 is at 02:00:00:00:00:0b.
    Time
    201.024 µs
    Cable
    laptop-a eth0 → laptop-b eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:0b
    IP
    192.168.1.10 → 192.168.1.11
    TTL
    64
    ICMP
    echo request, seq 1
    On the wire
    102 bytes
    laptop-a ARP cache
    192.168.1.11 is at 02:00:00:00:00:0b
  5. laptop-b: ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10 laptop-b answers with an echo reply.
    Time
    301.84 µs
    Cable
    laptop-b eth0 → laptop-a eth0
    Ethernet
    02:00:00:00:00:0b → 02:00:00:00:00:0a
    IP
    192.168.1.11 → 192.168.1.10
    TTL
    64
    ICMP
    echo reply, seq 1
    On the wire
    102 bytes
  6. laptop-a receives ICMP echo reply seq=1 192.168.1.11 → 192.168.1.10 laptop-a gets the frame. The reply arrived 0.403 ms after the request left: that is the round-trip time. laptop-a prints: 64 bytes from 192.168.1.11: icmp_seq=1 ttl=64 time=0.403 ms
    Time
    402.656 µs
    Ethernet
    02:00:00:00:00:0b → 02:00:00:00:00:0a
    IP
    192.168.1.11 → 192.168.1.10
    TTL
    64
    ICMP
    echo reply, seq 1
    On the wire
    102 bytes
  7. laptop-a: ICMP echo request seq=2 192.168.1.10 → 192.168.1.11 One second later, the second ping. ping waits a second between requests.
    Time
    1 s
    Cable
    laptop-a eth0 → laptop-b eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:0b
    IP
    192.168.1.10 → 192.168.1.11
    TTL
    64
    ICMP
    echo request, seq 2
    On the wire
    102 bytes
  8. laptop-b: ICMP echo reply seq=2 192.168.1.11 → 192.168.1.10 laptop-b answers with an echo reply.
    Time
    1 s
    Cable
    laptop-b eth0 → laptop-a eth0
    Ethernet
    02:00:00:00:00:0b → 02:00:00:00:00:0a
    IP
    192.168.1.11 → 192.168.1.10
    TTL
    64
    ICMP
    echo reply, seq 2
    On the wire
    102 bytes
  9. laptop-a receives ICMP echo reply seq=2 192.168.1.11 → 192.168.1.10 laptop-a gets the frame. The reply arrived 0.202 ms after the request left: that is the round-trip time. laptop-a prints: 64 bytes from 192.168.1.11: icmp_seq=2 ttl=64 time=0.202 ms
    Time
    1 s
    Ethernet
    02:00:00:00:00:0b → 02:00:00:00:00:0a
    IP
    192.168.1.11 → 192.168.1.10
    TTL
    64
    ICMP
    echo reply, seq 2
    On the wire
    102 bytes
  10. laptop-a: ICMP echo request seq=3 192.168.1.10 → 192.168.1.11 laptop-a sends an ICMP echo request ("are you there?") to 192.168.1.11, in a frame addressed to laptop-b.
    Time
    2 s
    Cable
    laptop-a eth0 → laptop-b eth0
    Ethernet
    02:00:00:00:00:0a → 02:00:00:00:00:0b
    IP
    192.168.1.10 → 192.168.1.11
    TTL
    64
    ICMP
    echo request, seq 3
    On the wire
    102 bytes
  11. laptop-b: ICMP echo reply seq=3 192.168.1.11 → 192.168.1.10 laptop-b answers with an echo reply.
    Time
    2 s
    Cable
    laptop-b eth0 → laptop-a eth0
    Ethernet
    02:00:00:00:00:0b → 02:00:00:00:00:0a
    IP
    192.168.1.11 → 192.168.1.10
    TTL
    64
    ICMP
    echo reply, seq 3
    On the wire
    102 bytes
  12. laptop-a receives ICMP echo reply seq=3 192.168.1.11 → 192.168.1.10 laptop-a gets the frame. The reply arrived 0.202 ms after the request left: that is the round-trip time. laptop-a prints: rtt min/avg/max/mdev = 0.202/0.269/0.403/0.095 ms
    Time
    2 s
    Ethernet
    02:00:00:00:00:0b → 02:00:00:00:00:0a
    IP
    192.168.1.11 → 192.168.1.10
    TTL
    64
    ICMP
    echo reply, seq 3
    On the wire
    102 bytes

Reading ip addr

ip addr, line by line
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 ...
    link/ether 02:00:00:00:00:0a brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global eth0
  • lo (the first entry) is the loopback: a pretend network inside the computer, always 127.0.0.1, which a program uses to talk to another program on the same machine.
  • eth0 is the Ethernet port, where the cable goes. UP,LOWER_UP means it is switched on and a cable is connected. mtu 1500 is the largest packet it sends, in bytes.
  • link/ether 02:00:00:00:00:0a is the card’s MAC address, its hardware address (Lesson 2.1).
  • inet 192.168.1.10/24 is the IP address. The /24 says which part of the address names the network; for now, read it as “everyone whose address starts 192.168.1. is on my network” (Lesson 3.2).

Reading ping

ping sends a small “are you there?” message (an ICMP echo request) and waits for “yes” (an echo reply).

  • 64 bytes from 192.168.1.11: a reply of 64 bytes came back from that address.
  • icmp_seq=1: which request this answers. Missing numbers mean lost packets.
  • ttl=64: a counter in every packet that drops by one at each router. Linux starts it at 64. Nobody was in the way here, so it arrived unchanged (Lesson 3.5).
  • time=0.403 ms: the round-trip time.
  • The summary: how many were sent and answered, the percentage lost, and the fastest, average and slowest times.

In the real world

On a Mac, ifconfig shows the same information as ip addr. On Windows, open “Command Prompt” and type ipconfig. ping exists everywhere, but Windows sends 4 pings and stops, while Linux and macOS keep going until you press Ctrl+C, which is why you will often see -c (-n on Windows) to choose how many.

When nobody answers

What if you ping an address that nobody on the cable has?

Pinging an address nobody has

  1. laptop-a: ping -c 1 192.168.1.99 laptop-a asks who has 192.168.1.99. laptop-b sees the question, but it is not its address, so it stays quiet.
    Time
    0 µs
    Cable
    laptop-a eth0 → laptop-b eth0
    Ethernet
    02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
    ARP
    who has 192.168.1.99? tell 192.168.1.10
    On the wire
    64 bytes
    laptop-a ARP cache
    192.168.1.99: asking (INCOMPLETE)
  2. laptop-a: ARP: who has 192.168.1.99? Tell 192.168.1.10 laptop-a knows the IP address 192.168.1.99 but not its MAC address, so it asks everyone on the network: who has 192.168.1.99?
    Time
    1 s
    Cable
    laptop-a eth0 → laptop-b eth0
    Ethernet
    02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
    ARP
    who has 192.168.1.99? tell 192.168.1.10
    On the wire
    64 bytes
  3. laptop-a: ARP: who has 192.168.1.99? Tell 192.168.1.10 laptop-a knows the IP address 192.168.1.99 but not its MAC address, so it asks everyone on the network: who has 192.168.1.99?
    Time
    2 s
    Cable
    laptop-a eth0 → laptop-b eth0
    Ethernet
    02:00:00:00:00:0a → ff:ff:ff:ff:ff:ff (broadcast)
    ARP
    who has 192.168.1.99? tell 192.168.1.10
    On the wire
    64 bytes
  4. Nobody answered: laptop-a gives up on 192.168.1.99 After three questions with no answer, laptop-a stops asking. laptop-a prints: 1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
    Time
    3 s
    laptop-a ARP cache
    192.168.1.99: nobody answered (FAILED)

After three unanswered questions, three seconds in all, laptop-a gives up and ping prints Destination Host Unreachable. The ping itself never left: laptop-a could not even find someone to hand it to.

When the addresses do not match

Now laptop-b has been given an address on a different network, 10.0.0.11, while laptop-a is still on 192.168.1.x.

Two laptops on different networks

  1. laptop-a: ip route ip route lists where laptop-a knows how to send things. It knows exactly one network: 192.168.1.0/24, through eth0.
    Time
    0 µs
  2. laptop-a: ping -c 1 10.0.0.11 laptop-a runs ping -c 1 10.0.0.11.
    Time
    0 µs

This time nothing at all goes on the cable. 10.0.0.11 is not on laptop-a’s network, and laptop-a has no gateway, a router to hand other networks’ traffic to (Lesson 3.3). So ping fails at once with Network is unreachable. The cable is fine; the addresses are wrong. You will fix exactly this kind of problem in the project at the end of Module 2.

For programmers

A program does not ping. It opens a connection. This script starts a tiny server on the loopback address and times how long connecting to it takes. Your numbers will differ.

connect_time.py
import socket, time

server = socket.socket()
server.bind(("127.0.0.1", 0))      # port 0: let the system pick a free port
server.listen()
port = server.getsockname()[1]

start = time.perf_counter()
client = socket.create_connection(("127.0.0.1", port))
ms = (time.perf_counter() - start) * 1000
print(f"Connected to port {port} in {ms:.3f} ms")
client.close()
server.close()

Output (one run)

Connected to port 59143 in 1.867 ms

:::

Recap

  • ip addr shows each interface’s MAC address and IP address; UP,LOWER_UP means a cable is in.
  • ping sends an echo request and times the reply: time= is the round-trip time.
  • If nobody has the address, Linux asks three times and ping says Destination Host Unreachable.
  • If the address is on another network and there is no gateway, ping says Network is unreachable and sends nothing.

Quick check

  1. In ping's output, what does time=0.403 ms tell you?
  2. You ping an address on your own network that no device has. What does Linux's ping finally print?
  3. Two laptops are joined by a working cable, but ping fails at once with "Network is unreachable". What is the likely cause?

Your progress is saved in this browser. Sign in to keep it on every device. Free, no password.

Join the discussion