I’ve been quiet for a long time now, but this entry hopefully will shake the cobwebs off and get me back into the habit.

I recently had a need to “unplumb” (from Solaris fame) or make interfaces on Linux “disappear” from the ifconfig list. It could be that I don’t know how to completely deconfigure an interface, but I didn’t find any methods to unassign an IP address from a Linux Ethernet interface after it was assigned. You can take interfaces down (ifconfig eth3 down) and reconfigure them to assign different addresses, but not remove the address completely.

After many searches and finding nothing that matched my need, I turned to my fellow Oakies (thanks, Mark!) who turned up this post from 2 years ago that hinted at a solution. It is driver-specific which is not ideal, but that makes sense given what I’m trying to do.

Here’s the generic version of the solution:

echo "<interface_name>" > /sys/bus/pci/drivers/<driver_name>/unbind

Determining the driver_name is pretty simple: check the /etc/modprobe.conf file (on OEL/RHEL 5.x). In that file, you’ll find things like this:

...
alias eth0 igb
alias eth1 igb
alias eth2 igb
alias eth3 igb
...

These lines indicate that the Ethernet driver used on this system by eth[0-3] is the igb driver. Now that you know the driver name, the tricky part is figuring out what the driver wants you to use as the interface name. I’ll give a few examples (and I haven’t figured out the scientific way to determine what the driver expects short of reading source code).

For the bnx2 driver, you can use the relatively simple ethernet interface name, like this:

echo "eth2" > /sys/bus/pci/drivers/bnx2/unbind

For my test system, the igb driver doesn’t use the “simple” Ethernet interface name like the bnx2 driver does. Instead, when trying that, it gives an error that the interface doesn’t exist. Time to dig in a little deeper.

On this system, the igb directory looks like this:

# ls -l /sys/bus/pci/drivers/igb/

total 0
lrwxrwxrwx 1 root root    0 Jul 16 13:12 0000:01:00.0 -> ../../../../devices/pci0000:00/0000:00:01.0/0000:01:00.0
lrwxrwxrwx 1 root root    0 Jul 16 13:12 0000:01:00.1 -> ../../../../devices/pci0000:00/0000:00:01.0/0000:01:00.1
lrwxrwxrwx 1 root root    0 Jul 16 13:12 0000:07:00.0 -> ../../../../devices/pci0000:00/0000:00:02.0/0000:07:00.0
lrwxrwxrwx 1 root root    0 Jul 16 13:12 0000:07:00.1 -> ../../../../devices/pci0000:00/0000:00:02.0/0000:07:00.1
--w------- 1 root root 4096 Jul 16 13:12 bind
lrwxrwxrwx 1 root root    0 Jul 16 13:12 module -> ../../../../module/igb
--w------- 1 root root 4096 Jul 16 13:12 new_id
--w------- 1 root root 4096 Jul 16 13:12 remove_id
--w------- 1 root root 4096 Jul 16 13:12 unbind
#

So, knowing that I have 4 interfaces on the system, I made the correlation to the 4 addresses that appear as symlinks in the driver’s directory and expect that they indicate the interface name. Checking a couple of those (each symlink references a directory), I see this:

# ls -Ll /sys/bus/pci/drivers/igb/0000:01:00.0

total 0
-rw-r--r-- 1 root root   4096 Jul 16 13:15 broken_parity_status
drwxr-xr-x 5 root root      0 Jul 16 13:12 bus
-r--r--r-- 1 root root   4096 Jul 16 12:57 class
-rw-r--r-- 1 root root   4096 Jul 16 12:57 config
-r--r--r-- 1 root root   4096 Jul 16 12:57 device
drwxr-xr-x 2 root root      0 Jul 16 13:12 driver
-rw------- 1 root root   4096 Jul 16 13:15 enable
-r--r--r-- 1 root root   4096 Jul 16 12:57 irq
-r--r--r-- 1 root root   4096 Jul 16 13:00 local_cpus
-r--r--r-- 1 root root   4096 Jul 16 13:15 modalias
drwxr-xr-x 3 root root      0 Jul 16 12:57 net:eth0
drwxr-xr-x 2 root root      0 Jul 16 12:55 power
-r--r--r-- 1 root root   4096 Jul 16 12:57 resource
-rw------- 1 root root 131072 Jul 16 13:15 resource0
-rw------- 1 root root 131072 Jul 16 13:15 resource1
-rw------- 1 root root     32 Jul 16 13:15 resource2
-rw------- 1 root root  16384 Jul 16 13:15 resource3
-r-------- 1 root root 131072 Jul 16 13:15 rom
drwxr-xr-x 5 root root      0 Jul 16 13:12 subsystem
-r--r--r-- 1 root root   4096 Jul 16 13:15 subsystem_device
-r--r--r-- 1 root root   4096 Jul 16 13:15 subsystem_vendor
--w------- 1 root root   4096 Jul 16 13:15 uevent
-r--r--r-- 1 root root   4096 Jul 16 12:57 vendor
# ls -Ll /sys/bus/pci/drivers/igb/0000:07:00.0
total 0
-rw-r--r-- 1 root root   4096 Jul 16 13:13 broken_parity_status
drwxr-xr-x 5 root root      0 Jul 16 13:12 bus
-r--r--r-- 1 root root   4096 Jul 16 12:57 class
-rw-r--r-- 1 root root   4096 Jul 16 12:57 config
-r--r--r-- 1 root root   4096 Jul 16 12:57 device
drwxr-xr-x 2 root root      0 Jul 16 13:12 driver
-rw------- 1 root root   4096 Jul 16 13:13 enable
-r--r--r-- 1 root root   4096 Jul 16 12:57 irq
-r--r--r-- 1 root root   4096 Jul 16 13:00 local_cpus
-r--r--r-- 1 root root   4096 Jul 16 13:13 modalias
drwxr-xr-x 3 root root      0 Jul 16 12:57 net:eth2
drwxr-xr-x 2 root root      0 Jul 16 13:13 power
-r--r--r-- 1 root root   4096 Jul 16 12:57 resource
-rw------- 1 root root 131072 Jul 16 13:13 resource0
-rw------- 1 root root 131072 Jul 16 13:13 resource1
-rw------- 1 root root     32 Jul 16 13:13 resource2
-rw------- 1 root root  16384 Jul 16 13:13 resource3
-r-------- 1 root root 131072 Jul 16 13:13 rom
drwxr-xr-x 5 root root      0 Jul 16 13:12 subsystem
-r--r--r-- 1 root root   4096 Jul 16 13:13 subsystem_device
-r--r--r-- 1 root root   4096 Jul 16 13:13 subsystem_vendor
--w------- 1 root root   4096 Jul 16 13:15 uevent
-r--r--r-- 1 root root   4096 Jul 16 12:57 vendor

You can see the directory with name “net:<interface_name>” as a subdirectory in each listing above. This tells us which interface from /sys/bus/pci/drivers/igb/0000* corresponds with which of the Linux Ethernet interface names. From this, we can see that eth2 is really 0000:07:00.0. So, in order to unbind this interface such that it no longer appears in the “ifconfig -a” output, we run this command:

echo "0000:07:00.0" > /sys/bus/pci/drivers/igb/unbind

and then it no longer appears in the “ifconfig -a” output. If you wanted to make this permanent, you should comment out the corresponding line from /etc/modprobe.conf so that it won’t be configured at boot time. Using the echo command above takes effect immediately, but won’t persist through a reboot (after reboot, the interface will return) unless the /etc/modprobe.conf changes are made.

Now, hopefully the next blog post after this one won’t require 14 more months of preparation!

  • http://kevinclosson.wordpress.com kevinclosson

    welcome back to the living, Dan! :-) Good post!

  • http://www.dbform.com Kamusis

    welcome back, long time no see (in Chinglish) :-)

  • Ben Prusinski

    Good to see you blogging again, Dan you are da man!

    Cheers,
    Ben

  • Pingback: Blogroll Report 16/07/2010 – 23/07/2010 « Coskan’s Approach to Oracle()

  • Liu Maclean

    This is a little complex to unplumb NIC on Linux…

  • http://www.dannorris.com/ Dan Norris

    Agreed, that’s why I wrote the post. However, if you have an easier method,
    please share.

  • Paul Schaefer

    Appreciated this – doesn’t seem to be available anywhere else (except the referenced site, which I was unable to follow as it wasn’t explained fully) – thanks.

  • Pingback: ifconfig eth0 unplumb equivalent - The UNIX and Linux Forums()