Show namespaces of a PID
List all namespaces of a PID. If two ns links have the same inode, the namespace is shared
lsns -p <pid>; readlink /proc/<pid>/ns/net /proc/1/ns/net # equal inode = same netns
- tool
- namespaces4 commands
More namespaces commands
-
PID=$(docker inspect -f '{{.State.Pid}}' <name>); nsenter -t $PID -n tcpdump -ni any -c 50Capture container traffic with the host's tcpdump through its netns. The image needs no extra tools
-
nsenter -t $(pgrep -n <proc>) -n -m -p ss -tlnpEnter the net, mount and pid namespaces of the newest matching process and list the listening sockets it sees
-
unshare --net --pid --fork --mount-proc bash # then: ip netns add test; ip netns exec test ip aStart a shell in new net and pid namespaces with its own /proc. Use ip netns to test named netns