As we know the "ip" command works on network namespaces by checking /var/run/ns/ dir, but apps like docker don't create a softlink of their network namespaces into this dir.
Below script scans network namespaces attached to all running processes and then uses "nsenter" to enter those namespaces and run the command "ip a" to get the addresses there.
ls -l /proc/*/ns/net | \
awk '{ print $9, $11}'| \
sort -k2 | uniq -f 1 | \
sed 's;^.*/\([0-9]*\)/.*\[\([0-9]*\)\].*$;\1;' | \
while read pid
do
echo PID:$pid
nsenter -t $pid -n ip address show
done
No comments:
Post a Comment