Skip to content
devops.academy

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/26 Then answer: is 10.0.5.130 inside 10.0.5.128/26? Is 10.0.6.1 inside 10.0.4.0/22? How many /24s fit in a /16? ✓ Check with ipcalc (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)

  1. 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 one ss line.
  2. Restart with --bind 0.0.0.0. Laptop curl works (open SG/firewall for 8000 if EC2).
  3. 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:

  1. Create red and blue namespaces, veth pair, IPs 10.10.0.1/2 /24, ping works.
  2. Run a web server inside one: sudo ip netns exec red python3 -m http.server 80; curl it from blue. ✓ Two isolated "containers" serving HTTP to each other — no Docker installed.
  3. 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.
  4. 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.me succeeds. ✓ You just built: bridge network + NAT = exactly docker0. Write 5 sentences mapping each piece to its Docker equivalent — this paragraph is interview gold.
  5. 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!)

  1. Baseline: allow ESTABLISHED, allow 22, allow 80, then DROP the rest on INPUT (exact order matters — do 22 before the DROP!).
  2. Verify: SSH still alive; nc -zv <vm> 80 ok; nc -zv <vm> 8000 times out.
  3. Watch counters: iptables -L -n -v before/after hitting each port — which rule's counters moved?
  4. 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).
  5. 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):

  1. VPC 10.0.0.0/16. Subnets: public 10.0.1.0/24 (AZ-a), private 10.0.11.0/24 (AZ-a).
  2. Internet Gateway; public route table with 0.0.0.0/0 → IGW, associate to public subnet.
  3. Launch bastion (public subnet, public IP, SG: 22 from your IP) and app (private subnet, NO public IP, SG: 22 from bastion's SG, 8080 from bastion's SG).
  4. SSH: laptop → bastion → app (use ssh -J bastion app agent-forward jump). ✓ You reached a machine that has no public IP. Explain the path out loud.
  5. On app: sudo apt update — hangs. Diagnose (route table has no internet path). Add NAT Gateway in the public subnet + private route 0.0.0.0/0 → NAT. apt now works. ✓ You've experienced the exact difference between IGW and NAT, as symptoms.
  6. Run python3 -m http.server 8080 on app; curl from bastion (works). Try from laptop directly (fails — why? two reasons: no public IP AND no inbound path).
  7. 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)

  1. Add 127.0.0.1 myfakesite.test to /etc/hosts; run a local server on 80; curl http://myfakesite.test works. Remove the entry; resolution fails.
  2. Explain the resolution order you just exploited, and describe (3 sentences) the pre-migration /etc/hosts testing trick from the module.
  3. 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.8 vs @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)

  1. Service A can't reach database B on 5432. Walk your exact playbook, and what each step's failure would mean.
  2. IGW vs NAT Gateway — explain to a junior, including why the DB subnet has neither.
  3. How many IPs in a /24? /26? Why do subnets exist at all?
  4. What happens, network-wise, when I type a URL and hit enter? (Go layer by layer.)
  5. What is a network namespace and why should a container engineer care?
  6. 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.