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/
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
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!
8 thoughts on “unplumb (or unbinding) NICs on Linux”
welcome back to the living, Dan! 🙂 Good post!
welcome back, long time no see (in Chinglish) 🙂
Good to see you blogging again, Dan you are da man!
This is a little complex to unplumb NIC on Linux…
Agreed, that’s why I wrote the post. However, if you have an easier method,
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.
Comments are closed.