# eth0 and eth1 exchanged on reboot [solved]

## daemonflower

Every few reboots my eth0 and eth1 are exchanged.

I don't need to tell you that this sucks, but just to mention it: This sucks.

Does anybody know this problem? How can I tell the system once and for all which NIC is eth0 and which one is eth1?

TIA,

HelgeLast edited by daemonflower on Tue Jul 11, 2006 2:27 pm; edited 1 time in total

----------

## guduri

It used to happen to me with my dvd devices. /dev/dvd used to link to /dev/hdc sometimes and /dev/hdd other times. Fixed this by adding custom udev rules (Maybe you could do something similar). Here is the wiki

http://gentoo-wiki.com/HOWTO_Customizing_UDEV

----------

## Clansman

Hi,

This can be solved with nameif (don't remember to which package it belongs, but it's a base ebuild one so you probably have it installed).

nameif associates mac addresses with network interface names. avoid at all costs using "standard" names like eth0, eth1 and such (it won't work). Use instead ethLAN, ethWAN, ethUPLINK, ethDMZ, etc.

configure your associations in /etc/mactab and all that's left is running nameif before starting network interfaces:

```

# /etc/mactab

ethLAN AA:BB:CC:DD:EE:FF

```

create a nameif init.d script just to run the nameif program on boot (rc-update add nameif boot) *BEFORE* attempting to even probe network devices.

update your init scripts to reflect new interface names and you're done. you can now glue some stickers/post-its with names on the cards themselves because no matter where (slot) they are, they will allways correspond to the same network interface name.

i'd appreciate some comments, because I'm not sure if there's a more clever way of achieving this goal.

Cheers,

----------

## Clansman

whoops! just found it. The referred link about udev shows just how it can be done:

```

KERNEL=="eth*", SYSFS{address}=="00:52:8b:d5:04:48", NAME="lan"

```

all that's left is figuring the syntax of the beast and I can get rid of the nameif startup script.

Cheers,

----------

## thepustule

If your problem is only with two interfaces, just build the driver for your your eth0 interface directly into the kernel and do your eth1 driver as a module.  That will guarantee that the eth0 driver is always loaded first.  For three or more interfaces, this won't work, bur for two it should be a slam-dunk.

I mean, who wants to go through every flaming config file in their /etc just to change all the interface names in every config for every service, because you had to rename the interface with nameif?

----------

## Clansman

erm... sed?

----------

## kbps

see my last post https://forums.gentoo.org/viewtopic-t-451044-highlight-eth0+eth1+randomly.html

----------

## feld

make them both modules and then in /etc/modules-autoload.d/kernel-2.6 list them in the order you want them to be in........

----------

## Clansman

 *feld wrote:*   

> make them both modules and then in /etc/modules-autoload.d/kernel-2.6 list them in the order you want them to be in........

 

yes yes, but what do you do when you have 8 NICs with the same chip (=same module)? 

I could say 2 instead of 8 - it's exactly the same.

hacking the load order is just that - a hack for a corner case.

[]

----------

## NightShadow7

Have you tried ifrename?

Open up/create /etc/iftab in your favorite text editor, add a line in the form of "desired_name mac macaddress" (man 5 iftab for more information)

After that, run /sbin/ifrename

Not sure if this is what you want, but it appears to serve the right purpose.

----------

## daemonflower

Making the driver for eth0 builtin and the one for eth1 a module solved it for me. I think after a couple of reboots it is safe to say that.

----------

## spottswoode

Hi,

I had the same f%&$ing troubles lately, and got rid of it thanks to Clansman's hint to nameif...

It was quite annoying before, because actually I had solved the problem before using some modules.conf entries.

Just after one of the regular Gentoo updates, my custom settings became either overwritten or

ineffective... and the troubles started again. 

However:

nameif works like a glowing banana....

For poeple who don't like to type  or appreciate a checklist when converting:

Here is my init-script.

The lines in the depend() function make sure, the script is started before the net.ethLAN and net.ethWAN scripts.

------------------------------------

#!/sbin/runscript

# my /etc/init.d/ifnames

opts="start"

depend(){

        before net.ethLAN net.ethWAN

        return 0

}

start() {

        ebegin "Renaming the network cards"

        (

        /sbin/nameif

        )

        eend $?

}

-------------------------------------------

Of course, there was more to do on my computer (used as router and file server) then activating this script using:

rc-update add ifnames default

Remove the symbolic links net.eth0 and net.eth1 in /etc/init.d 

Make new symbolic links in /etc/init.d by issuing 'ln -s net.lo net.ethLAN' and the same for ethWAN

remove net.eth0 and net.eth1 from the default runlevel using

rc-update del net.eth0

rc-update del net.eth1

inserting the new scripts:

rc-update add net.ethWAN default

rc-update add net.ethLAN default

adjust the /etc/conf.d/net settings file

adjust  (in case you use it) the iptables settings.

check corresponding server settings to listen to the new interface names

e.g. adjust /etc/conf.d/dnsmasq

possible /etc/hosts.allow /etc/hosts.deny settings.

Ok. I cease.

Good night.

----------

## jphelps

I recently started experiencing this too.  I appreciate that there are a lot of work arounds for this here but the underlying problem is still a mystery.  This was working for me for years on one machine and with UDEV to boot so what specificaly changed?  Is this a bug or a feature?

----------

## TimoTye

Happened to me for the first time last week.  I had rebooted the machine two days before with no issues.  The machine wasn't touched before the next reboot occurred a couple days later.  At this point the interfaces swapped.  Strange...

----------

## firehawk

Hi guys

Have a look at this thread too. Might be of help.

Cheers

----------

