Homework — Lesson 02
~20 min · Two tasks · Uses ip netns
Task 1 — Static route to a phantom network
Write commands to:
- Add a route to network
10.20.0.0/16via gateway192.168.1.254through interfaceeth0. - Verify the kernel will use it for destination
10.20.5.5by runningip route get. - Remove the route.
Self-check:
ip route get 10.20.5.5outputs a line containingvia 192.168.1.254while the route is present.- After
ip route del, the same command resolves through the default route.
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)
- Create three namespaces:
ns-client,ns-router,ns-server. - Create two veth pairs and assign one end to each pair of adjacent namespaces.
- Assign IPs as shown. Bring all interfaces up.
- Enable IPv4 forwarding inside
ns-router:sysctl -w net.ipv4.ip_forward=1. - Add default routes in
ns-clientandns-serverpointing to the router. - Ping
ns-serverfromns-client. - 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:
- The ping succeeds with 0% loss.
- The tcpdump shows ICMP echo requests in both directions: from veth1 (client side) into the router AND out veth2 (server side) — and the corresponding replies coming back. If you only see one direction, you forgot the return route.