Lesson 02 How Linux Decides Where Packets Go
Theme:

Homework — Lesson 02

~20 min · Two tasks · Uses ip netns

Task 1 — Static route to a phantom network

Write commands to:

  1. Add a route to network 10.20.0.0/16 via gateway 192.168.1.254 through interface eth0.
  2. Verify the kernel will use it for destination 10.20.5.5 by running ip route get.
  3. Remove the route.

Self-check:

Task 2 — Three-namespace topology (client → router → server)

Build the following on a single host:

  ns-client (10.0.1.10)  ──veth0/veth1──  ns-router (10.0.1.1 + 10.0.2.1)  ──veth2/veth3──  ns-server (10.0.2.10)
  1. Create three namespaces: ns-client, ns-router, ns-server.
  2. Create two veth pairs and assign one end to each pair of adjacent namespaces.
  3. Assign IPs as shown. Bring all interfaces up.
  4. Enable IPv4 forwarding inside ns-router: sysctl -w net.ipv4.ip_forward=1.
  5. Add default routes in ns-client and ns-server pointing to the router.
  6. Ping ns-server from ns-client.
  7. While the ping is running, in a second terminal capture on the router: sudo ip netns exec ns-router tcpdump -i any icmp.

Self-check:

View solutions →