Tcpdump inside a container netns from host
Sniff a container's traffic using host's tcpdump via its netns; no tools needed in image
PID=$(docker inspect -f '{{.State.Pid}}' <name>); nsenter -t $PID -n tcpdump -ni any -c 50
- tool
- namespaces4 commands
More namespaces commands
-
nsenter -t $(pgrep -n <proc>) -n -m -p ss -tlnpEnter newest proc's net+mount+pid ns and list listening sockets it actually sees
-
unshare --net --pid --fork --mount-proc bash # then: ip netns add test; ip netns exec test ip aSpawn shell in fresh net+pid ns with private /proc; ip netns for named netns testing
-
lsns -p <pid>; readlink /proc/<pid>/ns/net /proc/1/ns/net # equal inode = same netnsList all ns a PID belongs to; compare ns inode links to prove shared namespace