Monday, May 2, 2016

RHEL - Find the driver for attached Ethernet Card


How to find the device driver used for a device?

For eg, lets find the driver for Ethernet card

$ sudo lspci
# lspci | grep -i net


# lspci | grep -i net
00:19.0 Ethernet controller: Intel Corporation 82567LM-3 Gigabit Network Connection (rev 02)

# find /sys | grep drivers.*00:19.0
/sys/bus/pci/drivers/e1000e/0000:00:19.0

So, ether netcard is e1000

Find PCI vendor and device codes

# lspci -n | grep '00:19.0'
00:19.0 0200: 8086:10de (rev 02)


8086:10de stands for vendor:device ID

Now, go to the site
http://elrepo.org/tiki/DeviceIDs
and search for the vendor:dev id, you will find,

pci 8086:10DE kmod-e1000e


Now, go to http://elrepo.org/linux/elrepo

Find the right version such as el5/el6/el7

go the the specified version location and download the RPM

http://elrepo.org/linux/elrepo/el7/x86_64/RPMS/

# wget http://elrepo.org/linux/elrepo/el7/x86_64/RPMS/kmod-e1000e-3.3.3-1.el7.elrepo.x86_64.rpm

# rpm -ivh kmod-e1000e-3.3.3-1.el7.elrepo.x86_64.rpm

Once you done, reboot the machine.


# lspci -nk # show you attached drivers


$ cat find_ethernet_driver.sh
#!/bin/bash
for f in /sys/class/net/*; do
    dev=$(basename $f)
    driver=$(readlink $f/device/driver/module)
    if [ $driver ]; then
        driver=$(basename $driver)
    fi
    addr=$(cat $f/address)
    operstate=$(cat $f/operstate)
    printf "%10s [%s]: %10s (%s)\n" "$dev" "$addr" "$driver" "$operstate"
done


$ sh find_ethernet_driver.sh
   enp0s25 [00:23:ae:b0:32:0c]:     e1000e (up)
        lo [00:00:00:00:00:00]:            (unknown)
    virbr0 [52:54:00:a0:6d:79]:            (down)
virbr0-nic [52:54:00:a0:6d:79]:            (down)

No comments:

Post a Comment