namespaces commands

4 commands, each with a one-line explanation. Click a command to copy it, or its title for details.

Commands 4 shown

  • lsns -p <pid>; readlink /proc/<pid>/ns/net /proc/1/ns/net # equal inode = same netns

    List all ns a PID belongs to; compare ns inode links to prove shared namespace

    debug · troubleshooting · network

  • PID=$(docker inspect -f '{{.State.Pid}}' <name>); nsenter -t $PID -n tcpdump -ni any -c 50

    Sniff a container's traffic using host's tcpdump via its netns; no tools needed in image

    network · debug · troubleshooting

  • nsenter -t $(pgrep -n <proc>) -n -m -p ss -tlnp

    Enter newest proc's net+mount+pid ns and list listening sockets it actually sees

    network · debug · troubleshooting

  • unshare --net --pid --fork --mount-proc bash # then: ip netns add test; ip netns exec test ip a

    Spawn shell in fresh net+pid ns with private /proc; ip netns for named netns testing

    network · security · kernel