Pcornel
Linux · Linux Networking

Network Namespaces

Cheat sheet · https://pcornel.dk/topic.php?topic=2787

Back to the Topic

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/container
  • ip -br addr — interfaces and addresses
  • ip route — routing table and default route
  • ip neigh — ARP/neighbour cache
  • ip route get <dest> — route, interface and source chosen for a destination
  • nmcli device status / networkctl — which tool manages each interface

Commands

ip netns
ip netns exec
ip link set dev <if> netns <name>
ip netns add <name>
ip netns list
ip netns exec <name> <cmd>
ip netns identify <pid>
ip netns pids <name>
ip netns attach <name> <pid>
ip netns monitor
ip route
tcpdump

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

Confirmation

Confirm action

Continue?