ip-netns
Manage network namespaces
SYNOPSIS
ip netns { add NAME | delete NAME | identify PID | list [ dev DEV ] | list-id | attach NETNS PID | exec NETNS cmd ... | monitor [ all | name | id ] | pids NETNS }
PARAMETERS
add NAME
Create new network namespace named NAME.
delete NAME
Delete network namespace NAME (fails if processes remain).
identify PID
Print namespace name containing process PID.
list [ dev DEV ]
List namespaces; filter by device DEV if specified.
list-id
List numeric IDs of all network namespaces.
attach NETNS PID
Move process PID into namespace NETNS.
exec NETNS cmd ...
Execute cmd ... inside namespace NETNS.
monitor [ all | name | id ]
Monitor namespace add/delete events (default all).
pids NETNS
List all PIDs in namespace NETNS.
DESCRIPTION
ip netns is a command from the iproute2 suite for creating, deleting, listing, and manipulating Linux network namespaces. Network namespaces isolate network stack resources like interfaces, routes, iptables rules, and sockets, enabling secure multi-tenancy, containers (e.g., Docker, LXC), and testing environments.
Key operations include adding a namespace with ip netns add foo, executing commands inside it via ip netns exec foo ip addr, or attaching processes with ip netns attach foo PID. It lists namespaces, monitors changes, and identifies namespace per PID. Namespaces persist until deleted and require kernel support (CONFIG_NET_NS). Most actions need root privileges; unprivileged users can use user namespaces for nesting.
Common in DevOps for network simulation and virtualization, it complements tools like veth for inter-namespace links.
CAVEATS
Requires CAP_NET_ADMIN (root usually); cannot delete busy namespaces; kernel must support namespaces (2.6.24+); exec forks new processes, does not migrate existing ones.
EXAMPLES
ip netns add demo
ip netns exec demo ip link set lo up
ip netns pids demo
ip netns delete demo
FILES
Namespaces stored in /var/run/netns/ as symlinks to /proc/PID/ns/net.
HISTORY
Added in iproute2 2.6.29 (2008) with Linux kernel 2.6.24 network namespaces; developed by Eric W. Biederman and Pavel Emelyanov.


