Assigning eth0 to a particular NIC
From: Ben (johndoe_at_lets-send-spam-to.verisign.com)
Date: Tue, 04 Nov 2003 23:34:54 -0500
More than once, I've found that RedHat assigned eth0 to the card I
intended (and wired) as eth0, and vice versa. I figured there had to be
some way to get Linux to do what I wanted, instead of what it wanted.
And there is.
However, I had so much trouble finding the answer to these questions, I
thought I'd better post the information I found. I've seen several
postings of some variation of this question, and most went unanswered.
What's below works for me . . . but that doesn't guarantee anything for you!
As best I can tell, there are two (2.5?) ways, and two references. My
apologies for any errors: corrections are welcomed.
In Redhat, it appears that you can modify the ifcfg-ethxx files using
the MACADDR and the HWADDR configuration variables. At present, this is
documented here (along with many of the other ifcfg variables):
The MACADDR variable is apparently used to force a particular network
device, say eth0, to report the ASSIGNED MAC, rather than the burned in MAC.
The HWADDR variable is used to force the eth0 device handle to be
assigned to the network interface card (in a mult-NIC environment)
having a MAC = HWADDR.
At least, this is what I *think* happens: I haven't tested it. Some one
more skilled in reading Bash scripts than I may be able to confirm this,
by checking the relevant scripts. It appears that the following scripts
(under RH9) read the HWADDR value:
and these read the MACADDR value:
Only ONE of these variables should be used in a network device
configuration file. I assume that configuring the device handles this
way is persistent over a reboot, but also that it only works with RedHat
installations. Also in RedHat, the "neat" GUI tool can be used to set
these values, but the results some users reported were erratic and
There's another way, that I HAVE tested. Assignments made this way will
NOT survive a reboot (unless you write a boot script) but the method
should work with most distros. The "ip" program can be used to either
assign a particular MAC to a particular NIC *or* to assign a particular
handle to a particular NIC.
Anyhow, to switch eth0 and eth1 name assignments (and assign eth0 to
the card of MY choice):
ip link set eth0 down
ip link set eth1 down
ip link set dev eth0 name eth9
ip link set dev eth1 name eth0
ip link set dev eth9 name eth1
ip link set eth0 up
ip link set eth1 up
As a script, this takes less than a second to run on my machine.
Documentation for the "ip" tool is found in Alex Kuznetsov's "IP Command
Reference". Here's one copy:
Additional Google keys:
How can you bind an network device handle to a particular NIC?
Binding a NIC to a MAC
How can you bind eth0 to a particular NIC?