Exercises — Module 4: Networking
Two environments: your Linux VM (namespaces, tools) and an AWS free-tier account (VPC labs). Cost note: NAT Gateways bill ~$0.045/hr — create late, delete immediately after each session.
Part A — Warm-Up Drills
Drill 1 — CIDR math on paper (repeat daily until instant). For each, write network range, broadcast, usable host count:
192.168.1.0/24·10.0.0.0/16·10.0.5.0/28·172.16.0.0/12·10.0.5.64/26Then answer: is10.0.5.130inside10.0.5.128/26? Is10.0.6.1inside10.0.4.0/22? How many/24s fit in a/16? ✓ Check withipcalc(apt install ipcalc) — target: 30 seconds per item, zero errors.
Drill 2 — Know thyself. On your VM, answer using commands only: my IP(s)? my default gateway? my DNS resolvers? my public IP (curl ifconfig.me) — and why do the last two differ?
✓ You can explain private-IP + NAT from your own machine's evidence.
Drill 3 — Port census. ss -tulpn: for every listening socket, name the process, the port's purpose, and whether it's bound to 127.0.0.1 or 0.0.0.0 — and what that difference means for an attacker.
✓ A one-line explanation per socket.
Drill 4 — DNS reps. For github.com: get the A record (dig +short); full answer with TTL (dig); query a specific resolver (dig @1.1.1.1); find the CNAME chain of www.github.com; watch TTL count down between two queries.
✓ You can read a dig answer section aloud and explain every field.
Drill 5 — HTTP anatomy. curl -v https://example.com — identify in the output: DNS resolution, TCP connect, TLS handshake, request headers, response status/headers. Then curl -I, then the timing one-liner (-w '%{http_code} %{time_total}\n' -o /dev/null -s).
✓ You can point at where each Module-4 layer appears in -v output.
Part B — Guided Labs
Lab 1 — Bind Address Investigation (30 min)
python3 -m http.server 8000 --bind 127.0.0.1. From the VM: curl works. From your laptop (VM's IP): fails. Show why with onessline.- Restart with
--bind 0.0.0.0. Laptop curl works (open SG/firewall for 8000 if EC2). - Write the incident note: symptom → diagnostic command → root cause → fix. (This is the #1 "app unreachable" cause in real life.) ✓ Your note is 4 lines and would let a teammate fix it in 1 minute.
Lab 2 — Build Docker's Network by Hand: Namespaces (90 min) — the flagship lab
Follow module §9, but go further:
- Create
redandbluenamespaces, veth pair, IPs10.10.0.1/2 /24, ping works. - Run a web server inside one:
sudo ip netns exec red python3 -m http.server 80; curl it fromblue. ✓ Two isolated "containers" serving HTTP to each other — no Docker installed. - Add a THIRD namespace via a bridge: create
br0, move all veths onto it, give each ns an IP in the same /24. All three ping each other. - Give namespaces internet: IP on br0 for the host, default routes in each ns pointing to it, enable
ip_forward, add an iptables MASQUERADE rule for the /24.ip netns exec red curl ifconfig.mesucceeds. ✓ You just built: bridge network + NAT = exactlydocker0. Write 5 sentences mapping each piece to its Docker equivalent — this paragraph is interview gold. - Cleanup:
sudo ip netns del red blue green; sudo ip link del br0.
Lab 3 — iptables Sandbox (45 min) (disposable VM; keep the console open!)
- Baseline: allow ESTABLISHED, allow 22, allow 80, then DROP the rest on INPUT (exact order matters — do 22 before the DROP!).
- Verify: SSH still alive;
nc -zv <vm> 80ok;nc -zv <vm> 8000times out. - Watch counters:
iptables -L -n -vbefore/after hitting each port — which rule's counters moved? - Add: allow 8000 only from YOUR laptop's IP (
-s x.x.x.x/32); prove it works from laptop and fails from elsewhere (or from the VM's public path). - Flush (
iptables -F) and document the rule set you'd apply to a real web server. ✓ You never lost your SSH session. If you did — write down why.
Lab 4 — The AWS VPC Build (2–3 h) — module §10 made real
Build in the console deliberately slowly (Terraform automates it later — first, feel every piece):
- VPC
10.0.0.0/16. Subnets: public10.0.1.0/24(AZ-a), private10.0.11.0/24(AZ-a). - Internet Gateway; public route table with
0.0.0.0/0 → IGW, associate to public subnet. - Launch
bastion(public subnet, public IP, SG: 22 from your IP) andapp(private subnet, NO public IP, SG: 22 from bastion's SG, 8080 from bastion's SG). - SSH: laptop → bastion → app (use
ssh -J bastion appagent-forward jump). ✓ You reached a machine that has no public IP. Explain the path out loud. - On
app:sudo apt update— hangs. Diagnose (route table has no internet path). Add NAT Gateway in the public subnet + private route0.0.0.0/0 → NAT. apt now works. ✓ You've experienced the exact difference between IGW and NAT, as symptoms. - Run
python3 -m http.server 8080on app; curl from bastion (works). Try from laptop directly (fails — why? two reasons: no public IP AND no inbound path). - Teardown in order: NAT GW first (billing!), then release its EIP, instances, IGW, subnets, VPC. Verify $ in Billing next day.
Lab 5 — DNS Hands-On (30 min)
- Add
127.0.0.1 myfakesite.testto/etc/hosts; run a local server on 80;curl http://myfakesite.testworks. Remove the entry; resolution fails. - Explain the resolution order you just exploited, and describe (3 sentences) the pre-migration /etc/hosts testing trick from the module.
- If you own any domain (optional): create an A record to your bastion's IP, set TTL 300, watch propagation with
dig +short @8.8.8.8vs@1.1.1.1.
Part C — Challenges
C1 — Subnet plan. Design (on paper) a VPC addressing plan for: 3 AZs × (public + app-private + db-private) inside 10.20.0.0/16, leaving ≥50% space for growth. Justify sizes.
C2 — netcat chat & file transfer. Between two machines (or two namespaces): a chat with nc -l 9000 ↔ nc host 9000; then transfer a file over nc and verify checksums match (sha256sum).
C3 — Port scan yourself. With only bash + nc, scan ports 20–1024 on your own VM (loop + nc -z -w1), print open ones. Compare against ss -tulpn.
C4 — Trace the path. traceroute to something far away; identify: your gateway hop, your ISP, where latency jumps (an ocean?). Then traceroute between your two AWS instances — how many hops inside a VPC, and what does that tell you?
C5 — The blackhole. In the namespaces lab, delete the default route in red only. Predict, then verify: ping blue? curl internet? Restore it.
Part D — Break & Fix Scenarios (build them, then "get paged")
D1 — Wrong subnet mask. In the namespace lab, set red to /25 and blue to 10.10.0.130/25 — same wire, ping fails. Diagnose from ip route in each ns; explain why L2 works but L3 doesn't; fix.
D2 — DNS down. Point /etc/resolv.conf at 127.0.0.99. Now: ping 1.1.1.1 (works) but ping google.com (fails) — internalize THE classic split: connectivity fine, DNS broken. Fix and write the 2-command diagnosis that distinguishes these cases forever.
D3 — Security-group knot (AWS). Have a friend (or your past self) misconfigure ONE of: app SG inbound, bastion SG outbound reference, private route table, NACL. Diagnose using the §8 playbook only — no console browsing until each step's verdict is written down.
D4 — The firewall lockout tabletop. You added iptables -A INPUT -j DROP before the port-22 ACCEPT on a cloud VM. Without doing it: write the recovery plan (console access? user-data? reboot rules persistence?) and the prevention (rule order, iptables-apply, at-job safety net).
Part E — Interview Rehearsal (out loud)
- Service A can't reach database B on 5432. Walk your exact playbook, and what each step's failure would mean.
- IGW vs NAT Gateway — explain to a junior, including why the DB subnet has neither.
- How many IPs in a /24? /26? Why do subnets exist at all?
- What happens, network-wise, when I type a URL and hit enter? (Go layer by layer.)
- What is a network namespace and why should a container engineer care?
- Public IP vs private IP vs elastic IP — and how does my private-IP'd laptop reach the internet?
Done when
CIDR drills are instant, Lab 2 step 4's paragraph is written, Lab 4 teardown left a $0 bill, and D2's two-command diagnosis is memorized.
