Network Namespaces
Cheat sheet · https://pcornel.dk/topic.php?topic=2787
Answer
A network namespace is an isolated copy of the network stack — its own interfaces, addresses, routes and firewall rules. Containers each get one; ip netns manages named ones.
Remember
Commands run inside a namespace see only its interfaces: use ip netns exec <ns> <cmd> or nsenter -t <pid> -n <cmd> for a container's PID. veth pairs connect a namespace to a bridge or the host.
First checks
nsenter -t <pid> -n ip -br addr— network view of a process/containerip -br addr— interfaces and addressesip route— routing table and default routeip neigh— ARP/neighbour cacheip route get <dest>— route, interface and source chosen for a destinationnmcli device status / networkctl— which tool manages each interface
Commands
ip netnsip netns execip link set dev <if> netns <name>ip netns add <name>ip netns listip netns exec <name> <cmd>ip netns identify <pid>ip netns pids <name>ip netns attach <name> <pid>ip netns monitorip routetcpdump
Verify in this order
namespace created → veth/interface moved in → address and route set → connected via bridge or routing → traffic flows
Where it usually breaks
First mismatch in link/interface → address/namespace → route/neighbor → firewall/policy → socket/daemon → DNS/TLS/SSH/application peer path; preserve identity/native diagnostic/pre-state before mutation.
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=2787