Chapter 2 · Hands-on labs
Six small, beginner-friendly labs. Just type the commands and read the output — no programming. Each one maps to a Chapter 2 topic and ends by tying what you saw back to the slide.
sudo apt install -y ipcalc. The ❯ is just the prompt — the Copy button grabs only the command.Your IP address & subnet (look at the line that isn’t lo):
ip -br addr
lo UNKNOWN 127.0.0.1/8 eth0 UP 192.168.1.23/24
So this machine’s IP is 192.168.1.23 and the /24 is its subnet (the local network).
Your MAC address — the card’s permanent name (the link/ether line):
ip link show
2: eth0: <BROADCAST,MULTICAST,UP> ...
link/ether 6c:f0:49:68:95:68 brd ff:ff:ff:ff:ff:ffYour gateway — the “door” out to other networks (the default via line):
ip route
default via 192.168.1.1 dev eth0
Neighbours you’ve talked to — their IP and MAC, side by side:
ip neigh
A letter, as bits and hex. See the 0s and 1s behind “A”:
echo -n "A" | xxd -b echo -n "A" | xxd
00000000: 01000001 A <- binary (8 bits) 00000000: 41 A <- hex
So A = 01000001 in binary = 41 in hex. Same letter, two outfits.
Decimal → hex with printf (try the IP octet 192):
printf '%X\n' 192
C0
Hex → decimal (put 0x in front of the hex):
printf '%d\n' 0xC0
192
Decimal ↔ binary with bc (obase = output base):
echo "obase=2; 192" | bc echo "ibase=2; 11000000" | bc
11000000 192
Read your MAC again and look at the six pairs:
ip link show
6c:f0:49 : 68:95:68 └──────┘ └──────┘ OUI serial (vendor) (this card)
The first 3 octets (6c:f0:49) are the OUI — the maker, registered with the IEEE. The last 3 are this card’s unique serial. (You can paste the first 3 into any “MAC vendor lookup” site to see the brand.)
Recognise the 3 delivery types by how the address looks:
Unicast 6c:f0:49:68:95:68 one card (a normal MAC) Broadcast ff:ff:ff:ff:ff:ff everyone (all F's) Multicast 01:00:5e:00:00:fb a group (starts 01:00:5e)
Watch a broadcast on the wire — capture ARP and look at the destination:
sudo tcpdump -e -nn -c 5 arp
... 6c:f0:49:68:95:68 > ff:ff:ff:ff:ff:ff, Request who-has 192.168.1.1
01:00:5e:00:00:fb a unicast, broadcast, or multicast address? (answer below)Find your IP and mask (e.g. 192.168.1.23/24):
ip -br addr
Let ipcalc do the maths — feed it your address and mask:
ipcalc 192.168.1.23/24
Address: 192.168.1.23 Netmask: 255.255.255.0 = 24 => Network: 192.168.1.0/24 HostMin: 192.168.1.1 HostMax: 192.168.1.254 Broadcast: 192.168.1.255 Hosts/Net: 254 Class C, Private Internet
Read it off: the Network is the .0, the usable range is HostMin → HostMax, the Broadcast is the .255, there are 254 usable hosts, and it’s Class C.
Shrink the network and watch the numbers change (a sneak peek at subnetting, Chapter 6):
ipcalc 192.168.1.23/26
Network: 192.168.1.0/26 Broadcast: 192.168.1.63 Hosts/Net: 62 Class C
ipcalc 10.0.0.5/8. What class is it, and roughly how many hosts? (answer below)Start capturing in Terminal A (-e shows Layer 2, -vv shows detail):
sudo tcpdump -i any -c 3 -e -vv -nn 'tcp port 80'
Make some traffic in Terminal B:
curl -s http://example.com -o /dev/null
Read one packet back in Terminal A — every layer is there:
6c:f0:49:68:95:68 > 52:54:00:aa:bb:cc, ethertype IPv4 (0x0800) <- Layer 2 (Ethernet: MACs + type)
(ttl 64, proto TCP (6), length 56) <- Layer 3 (IP: ttl, protocol)
192.168.1.23.49152 > 93.184.216.34.80: Flags [S], win 8192 <- Layer 4 (TCP: ports, flags)
GET / HTTP/1.1 <- Layer 7 (the data)Open Wireshark (Applications ▸ Sniffing, or the command below). Double-click your interface (eth0/wlan0) to start, browse a website, then click the red square to stop.
sudo wireshark &
Click any packet, then in the middle pane click the ▸ triangles to expand each layer. You’ll see one address per layer:
▸ Ethernet II Src/Dst MAC <- Layer 2 ▸ Internet Protocol Src/Dst IP <- Layer 3 ▸ Transmission Control Protocol <- Layer 4 (ports) ▸ Hypertext Transfer Protocol <- Layer 7 (host name)
Prefer the terminal? Read the Ethernet frame header with tcpdump (-e = show Layer 2):
sudo tcpdump -i any -e -c 5 -nn
6c:f0:49:68:95:68 > 52:54:00:aa:bb:cc, ethertype IPv4 (0x0800), length 74 52:54:00:aa:bb:cc > ff:ff:ff:ff:ff:ff, ethertype ARP (0x0806), length 42
Each frame begins with dest MAC > src MAC, then the ethertype — 0x0800 = IPv4, 0x0806 = ARP. That Type field tells the receiver which upper layer to hand the data to.
Lab 1. The IP would change (you’d get a new address from the café’s network). The MAC stays the same — it’s burned into the card and goes everywhere with you.
Lab 2. 255 = 11111111 in binary (echo "obase=2; 255" | bc) and FF in hex (printf '%X\n' 255).
Lab 3. 01:00:5e:00:00:fb is multicast — the 01:00:5e prefix is the giveaway (it’s a “send to a group” address, not one card and not everyone).
Lab 4. 10.0.0.5/8 → first octet 10 → Class A; a /8 has about 16.7 million hosts (16,777,214 usable).
Lab 5. The line with 192.168.1.23 > 93.184.216.34 shows the IP addresses; the first line with the two xx:xx:xx:xx:xx:xx values shows the MAC addresses.
Lab 6. The MAC changes at every hop (it’s only local to each link); the IP stays the same end-to-end. That’s “IP end-to-end, MAC hop-to-hop” — the big idea of Chapter 3.
| This lab’s tool | Returns in… |
|---|---|
| ip addr / neigh (Lab 1, 3) | Chapter 3 — MAC, ARP, frames |
| ipcalc / IPv4 (Lab 4) | Chapter 4 & 6 — the IP header, masks & subnetting |
| tcpdump layers (Lab 5, 6) | Chapter 4 & 5 — IP TTL, ICMP, fragmentation |
| Wireshark (Lab 6) | Every later chapter — your go-to packet viewer |