IP Addressing
IP Addressing
Forwarding starts with addressing: structure, masks, subnets, summarization, and enough IPv6 to run dual-stack labs. This chapter is calculation plus lab verification—not exam trick puzzles for their own sake.
Learning goals
By the end of this chapter you can:
- Convert between prefix length and masks fluently
- Design subnets for a multi-tier lab without overlaps
- Summarize contiguous blocks and predict blackholes from bad summaries
- Configure IPv4 and basic IPv6 on Linux
- Use documentation ranges and lab hygiene ranges deliberately
IPv4 structure
An IPv4 address is 32 bits, usually dotted decimal. A prefix address/len identifies network bits vs host bits.
| Prefix | Mask | Hosts (approx usable) |
|---|---|---|
| /32 | 255.255.255.255 | 1 (host route) |
| /31 | 255.255.255.254 | 2 (P2P often) |
| /30 | 255.255.255.252 | 2 usable classic |
| /24 | 255.255.255.0 | 254 usable classic |
| /16 | 255.255.0.0 | large |
| /8 | 255.0.0.0 | huge |
# Linux
ip addr add 192.0.2.10/24 dev eth1
ip -br a
ip routeOn-link decision
If destination is inside a connected prefix, the host uses ARP/ND on that interface. Otherwise it sends to a gateway (route lookup).
ip route get 192.0.2.50
ip route get 8.8.8.8Subnetting for labs
Example campus-ish allocation from 10.20.0.0/16:
| Use | Block |
|---|---|
| Users site A | 10.20.1.0/24 |
| Users site B | 10.20.2.0/24 |
| Servers | 10.20.10.0/24 |
| P2P core | 10.20.255.0/24 as /30s |
| Loopbacks | 10.20.254.0/24 as /32s |
Rules:
- No overlapping prefixes on different segments unless deliberate anycast
- Leave growth room
- Write the plan before deploy
- Align summaries with actual aggregation topology
Summarization
If you own 10.20.1.0/24 and 10.20.2.0/24, a summary 10.20.0.0/22 may or may not be correct depending on other contents of that /22.
| Action | Risk |
|---|---|
| Summary advertises space you do not have | Blackhole for missing parts |
| Too-specific everywhere | Table bloat (later IGP/BGP scale) |
| Forgetting more-specific local routes | Traffic steers wrong |
Paper drill
You have:
- 10.0.0.0/25
- 10.0.0.128/25
Correct tight summary? 10.0.0.0/24.
You have only 10.0.0.0/25 but advertise 10.0.0.0/24 upstream without a sink. What happens to 10.0.0.200? Blackhole toward you.
Special-use ranges (know them)
| Range | Role |
|---|---|
| 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 | Private (RFC 1918) |
| 127.0.0.0/8 | Loopback |
| 169.254.0.0/16 | Link-local |
| 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24 | Documentation (RFC 5737) |
| 224.0.0.0/4 | Multicast |
IPv6 essentials for dual-stack labs
IPv6 address is 128 bits; common lab prefix /64 on LANs.
ip -6 addr add 2001:db8:1::10/64 dev eth1
ip link set eth1 up
ip -6 route
ip -6 neigh
ping -6 -c 2 2001:db8:1::1| Prefix idea | Example |
|---|---|
| Documentation | 2001:db8::/32 |
| Unique local | fd00::/8 (with local generation rules) |
| Link-local | fe80::/10 auto on interfaces |
ND replaces ARP. Router Advertisements may autoconfigure hosts—labs often use statics for control.
Dual-stack habit
Give nodes both families when learning:
ip addr add 10.1.0.10/24 dev eth1
ip -6 addr add 2001:db8:1::10/64 dev eth1Test both paths; do not assume v4 success means v6 works.
Linux configuration patterns
Persistent lab style
In Containerlab, prefer startup scripts or image config over manual ip addr that vanishes.
#!/bin/sh
ip addr flush dev eth1
ip addr add 10.1.0.10/24 dev eth1
ip -6 addr add 2001:db8:1::10/64 dev eth1
ip link set eth1 up
ip route add default via 10.1.0.1
ip -6 route add default via 2001:db8:1::1Multiple addresses
ip addr add 10.1.0.10/24 dev eth1
ip addr add 10.1.0.11/24 dev eth1Secondary addresses appear in ARP; know who answers.
Lab: addressing plan + dual-stack hosts
name: l3-addr
topology:
nodes:
r1:
kind: linux
image: alpine:3.20
exec:
- apk add --no-cache iproute2 iputils
- sysctl -w net.ipv4.ip_forward=1
- sysctl -w net.ipv6.conf.all.forwarding=1
- ip addr add 10.1.0.1/24 dev eth1
- ip addr add 10.2.0.1/24 dev eth2
- ip -6 addr add 2001:db8:1::1/64 dev eth1
- ip -6 addr add 2001:db8:2::1/64 dev eth2
- ip link set eth1 up
- ip link set eth2 up
h1:
kind: linux
image: alpine:3.20
exec:
- apk add --no-cache iproute2 iputils
- ip addr add 10.1.0.10/24 dev eth1
- ip -6 addr add 2001:db8:1::10/64 dev eth1
- ip link set eth1 up
- ip route add default via 10.1.0.1
- ip -6 route add default via 2001:db8:1::1
h2:
kind: linux
image: alpine:3.20
exec:
- apk add --no-cache iproute2 iputils
- ip addr add 10.2.0.10/24 dev eth1
- ip -6 addr add 2001:db8:2::10/64 dev eth1
- ip link set eth1 up
- ip route add default via 10.2.0.1
- ip -6 route add default via 2001:db8:2::1
links:
- endpoints: ["h1:eth1", "r1:eth1"]
- endpoints: ["h2:eth1", "r1:eth2"]Predict
- h1 pings h2 v4 and v6 through r1
- Wrong mask on h1 (e.g. /32 only) breaks on-link perception of gateway
Observe
docker exec clab-l3-addr-h1 ping -c 2 10.2.0.10
docker exec clab-l3-addr-h1 ping -6 -c 2 2001:db8:2::10
docker exec clab-l3-addr-h1 ip route get 10.2.0.10
docker exec clab-l3-addr-r1 ip -br aFailure: overlapping subnets
Put h2 also in 10.1.0.0/24 while connected to r1 eth2 differently—create intentional overlap and journal chaos (ARP confusion, asymmetric paths). Restore clean plan.
Failure: bad summary (static preview)
On a third router path (optional), advertise/install 10.0.0.0/8 via a dead next hop while more specifics missing—observe blackhole for unused space.
Calculation practice (quick)
- How many /24s in a /16? → 256
- First/last usable in 10.0.0.0/30 classic? → 10.0.0.1 and 10.0.0.2
- Is 10.0.0.64/26 inside 10.0.0.0/24? → yes
- Can you summarize 10.1.0.0/24 and 10.2.0.0/24 as a single /23? → no (not contiguous bit boundary as one /23 covering both cleanly without others)
Work these on paper until automatic.
Host vs router addressing habits
| Role | Typical |
|---|---|
| Host | One address + default route |
| Router | Addresses on each L3 interface + routing table |
| Loopback | Stable /32 or /128 for protocols later |
ip addr add 1.1.1.1/32 dev loVerification checklist
ip -br a
ip route
ip -6 route
ip route get <dst>
ping -c 2 <dst>
ping -6 -c 2 <dst6>Summary
- Prefixes define on-link vs routed behavior
- Plan non-overlapping lab allocations; document them
- Summaries must match reality or they blackhole
- Dual-stack labs need explicit v6 config and tests
ip route getis your friend
Next: routing fundamentals—RIB/FIB, longest match, next hops, and host vs router behavior including ARP/ND.