The client and the server from the first exercise are two isolated networks inside one machine, and you run commands in them with ip -n and ip netns exec.
Apart from lo, the practice machine has no interfaces: it is cut off from outside networks. Preparation creates the client and the server as network namespaces: separate sets of interfaces, addresses and routes inside one kernel. A program in the lab-client namespace sees only that namespace's interfaces.
The namespaces are joined by a veth pair: two virtual interfaces that work like the two ends of a cable, so whatever goes into one end comes out of the other. lab0 is the client's end, lab1 is the server's.
| Command | Where it runs |
|---|---|
sudo ip -n lab-client … |
ip in the lab-client namespace |
sudo ip netns exec lab-client … |
any program there, such as ping |
Without sudo, both forms print Operation not permitted. The network from the first exercise is built by commands like these — for reference, you don't need to type them:
The network from the first exercise is built. You type ip -brief -4 address, without sudo and without -n. What will the output show?
-
Reading your own machine's interfaces needs no root. That error comes from
ip -n lab-clientwithoutsudo: entering another namespace takes root rights. -
The two ends of the pair are placed in the
lab-clientandlab-servernamespaces. Onlyloremains on the machine itself. -
lab0lives in thelab-clientnamespace, and a command without-nreads the interfaces of the machine itself.
Without -n, ip sees the machine's own interfaces, which is just lo. lab0 and lab1 live in the namespaces and can only be seen with sudo ip -n ….
Key points
- A network namespace has its own interfaces, addresses and routes inside one kernel.
-
A veth pair joins two namespaces like a cable:
lab0on the client,lab1on the server. -
sudo ip -n NAMErunsipin a namespace, andsudo ip netns exec NAMEruns any program there.