Connect two network namespaces
Build a private network and connect it through a veth pair.
Jump to code and terminal ↓The network stack is namespaced
A network namespace owns interfaces, addresses, routes, and port bindings. A new one starts with a down loopback interface and no connectivity. Here “parent” means the disposable Linux guest, not your computer.
A veth is a virtual cable
Packets sent on one veth endpoint arrive at the other. Keep lab-host0 in the parent namespace and move lab-child0 into a named namespace. Give them 10.44.0.1/24 and 10.44.0.2/24 and bring both up. No bridge or Internet gateway is needed for this two-endpoint network.
ip link add lab-host0 type veth peer name lab-child0 ip link set lab-child0 netns NAME
Your change
The launcher receives a command. Create the namespace and cable, configure its loopback and endpoints, run the command with ip netns exec, and clean up on exit. The test sends real ICMP packets across the cable.
Your goal
Create a network namespace with its own loopback and a veth endpoint at 10.44.0.2 that can reach the guest parent at 10.44.0.1.
What the tests observe
- Separate interfaces and routes
- Real veth ICMP exchange
- Private loopback
- Resource cleanup
Need a nudge?
Hint 1
Use ip netns add NAME and ip netns exec NAME COMMAND.
Hint 2
The full ip utility is available. ip -n NAME addr/link operates in that namespace.
Hint 3
Bring up both veth ends and lo, and install cleanup with trap before creating resources.
What happens inside Linux
A veth transfers actual kernel sk_buffs between separate network stacks. The child gained controlled connectivity to exactly one peer. Bridges, routing, NAT, and firewall policies extend this same topology for more containers.
Optional account sync. Exercises work without an account.