If you know the name of the driver that the device will be bound to, then you can search the /sys
filesystem and get a list of network devices that are using it.
If you don't know the name of the driver just yet, you can find it first with: lspci -nnk | grep -i 'network\|ethernet' -A3
.
Example 1
Let's find the drivers:
$ lspci -nnk | grep -i 'network\|ethernet' -A3
06:00.0 Ethernet controller [0200]: Intel Corporation 82574L Gigabit Network Connection [8086:10d3]
Subsystem: Super Micro Computer Inc 82574L Gigabit Network Connection [15d9:10d3]
Kernel driver in use: e1000e
Kernel modules: e1000e
07:00.0 Ethernet controller [0200]: Intel Corporation 82574L Gigabit Network Connection [8086:10d3]
Subsystem: Super Micro Computer Inc 82574L Gigabit Network Connection [15d9:10d3]
Kernel driver in use: e1000e
Kernel modules: e1000e
08:08.0 FireWire (IEEE 1394) [0c00]: Texas Instruments TSB43AB22A IEEE-1394a-2000 Controller (PHY/Link) [iOHCI-Lynx] [104c:8023]
Notice that is says Kernel driver in use: e1000e. That's the driver my network cards are using. For your system, substitute your driver name in place of e1000e in the following example.
Now that we know the driver in use, e1000e, I can search the /sys
filesystem and find which network devices are using this driver with the following command:
$ find -L /sys/class/net -maxdepth 3 -name "uevent" -exec grep -iH "e1000e" {} \; 2> /dev/null
/sys/class/net/eth0/device/uevent:DRIVER=e1000e
/sys/class/net/eth1/device/uevent:DRIVER=e1000e
From there, I can use awk
to get the network device names:
$ find -L /sys/class/net -maxdepth 3 -name "uevent" -exec grep -iH "e1000e" {} \; 2> /dev/null | awk -F / '{print $5}'
eth0
eth1
Example 2
As another example on a different computer, I have both WIFI and an ethernet controller, each with a different driver.
Let's find the drivers:
$ lspci -nnk | grep -i 'network\|ethernet' -A3
09:00.0 Network controller [0280]: Intel Corporation Device [8086:2725] (rev 1a)
Subsystem: Intel Corporation Device [8086:0020]
Kernel driver in use: iwlwifi
Kernel modules: iwlwifi
--
0b:00.0 Ethernet controller [0200]: Intel Corporation Device [8086:15f2] (rev 03)
Subsystem: Lenovo Device [17aa:22d8]
Kernel driver in use: igc
Kernel modules: igc
WIFI with the iwlwifi driver:
$ find -L /sys/class/net -maxdepth 3 -name "uevent" -exec grep -iH "iwlwifi" {} \; 2> /dev/null
/sys/class/net/wlp9s0/device/uevent:DRIVER=iwlwifi
$ find -L /sys/class/net -maxdepth 3 -name "uevent" -exec grep -iH "iwlwifi" {} \; 2> /dev/null | awk -F / '{print $5}'
wlp9s0
Ethernet Controller with the igc driver:
$ find -L /sys/class/net -maxdepth 3 -name "uevent" -exec grep -iH "igc" {} \; 2> /dev/null
/sys/class/net/enp11s0/device/uevent:DRIVER=igc
$ find -L /sys/class/net -maxdepth 3 -name "uevent" -exec grep -iH "igc" {} \; 2> /dev/null | awk -F / '{print $5}'
enp11s0