
Most of these commands require root privileges or
sudo. Ensure you have the appropriate permissions before proceeding.1. Process Isolation
Inside a container’s PID namespace, a process always appears as PID 1. From the host’s root namespace, the same process has a distinct PID among all host processes:2. Creating Network Namespaces
By default, the host’s network stack is isolated to its own namespace. To spin up isolated network domains:3. Inspecting Interfaces Inside a Namespace
On the host, you’ll see all physical and virtual interfaces:eth0) appear in red. ARP and routing tables start empty:
4. Connecting Two Namespaces with veth Pairs
To create a virtual “cable” between red and blue, use a veth pair:5. Building a Virtual Switch with a Bridge
Connecting many namespaces via direct veth pairs is impractical. Instead, create a Linux bridge on the host:6. Host–Namespace Connectivity
To let the host join this virtual network, assign v-net-0 an IP in the same subnet:7. Namespace → LAN Connectivity via Host
By default, namespaces cannot reach external LANs:192.168.15.5):
Enabling NAT on the Host
Be careful when modifying
iptables rules on production systems. Always test in a safe environment first.8.8.8.8):
8. Port Forwarding into a Namespace
To expose a service (e.g., HTTP on port 80) running in blue, useiptables DNAT on the host: