2017年7月25日 星期二

List Linux network interface driver in all the network namespaces

Linux: How to find the device driver used for a device? - Unix & Linux Stack Exchange
https://unix.stackexchange.com/questions/41817/linux-how-to-find-the-device-driver-used-for-a-device
networking - How do I find what kernel module is behind a network interface? - Ask Ubuntu
https://askubuntu.com/questions/216110/how-do-i-find-what-kernel-module-is-behind-a-network-interface

Improved driver finding and output format:

#!/bin/bash
for f in /sys/class/net/*; do
    dev=$(basename $f)
    driver=$(ethtool -i $dev 2>/dev/null | grep driver: | cut -c 9-)
    addr=$(cat $f/address)
    operstate=$(cat $f/operstate)
    printf "%020s [%017s]: %015s (%s)\n" "$dev" "$addr" "$driver" "$operstate"
done
 Save the above script as test.sh.

Enumerate all the interface in all the network namespaces
echo === NameSpace: Global ===
sh test.sh
for a in $(ip netns list | sed -e 's/(.*$//g') ; do
echo
echo === NameSpace: $a ===
    ip netns exec $a sh test.sh
done

沒有留言: