# Network device order - how to tell what order they will use?

## haven

Hi Guys

I've a big hole in my knowledge and its causing me some issues - I'm hoping someone can help me out. 

I have a machine with four PCI network cards, 3 x intell 10/100 pro's and 1 dual intel gigabit card. A quick lspci shows:

```
0000:00:09.0 Ethernet controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (rev 0c)

0000:00:0b.0 Ethernet controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (rev 0c)

0000:00:0d.0 Ethernet controller: Intel Corp. 82557/8/9 [Ethernet Pro 100] (rev 0c)

0000:00:0f.0 Ethernet controller: Intel Corp. 82546GB Gigabit Ethernet Controller (rev 03)

0000:00:0f.1 Ethernet controller: Intel Corp. 82546GB Gigabit Ethernet Controller (rev 03)

```

What I am trying to figure out is how it is determined which device will be eth0 all the way through to eth4. The reason that I ask is that I am currently running an old'ish 2.6.3-gentoo-r2 kernel and I would like to upgrade to linux-2.6.11-gentoo-r9. When I do boot into the new kernel all my network devices are scrambled i.e. eth0 has somehow become eth2 etc. This makes life very hard as my network setup is pretty complex and it takes a while to remap what is actually going where. Surely there is a better way of figuring it out, and I'd like to understand why it changes between kernel revisions ? 

So my question is how do I tell in advance how a network card in PCI slot 4 will correspond to an ethx device ?

Thanks in advance for any help.

----------

## MrUlterior

AFAIK, nameif (in sys-apps/net-tools) can do this.

See the end of this page:

http://www.science.uva.nl/research/air/wiki/LogicalInterfaceNames

----------

## haven

Brilliant, that looks exactly like what I need. Many thanks  :Smile: 

----------

## MrUlterior

So, what (beyond the obvious) do you need all those NICs for?

----------

## haven

The server is acting as both a router and a switch for my home network - this gives me a lot of control over what passes over the network without having to fork out a lot of money for an expensive managed switch with gigabit capability (I had most of the NIC's lying around from old systems anyway). Since I only have five wired network devices in my home network - two of which are gigabit - this does everything I need  :Smile:  It also allows me to snort traffic passing through any device, firewall ports that shouldnt be running, pipe certain traffic through an anonymous proxy automatically, load balance all traffic using HTB - and is generally a great learning tool. I've been running the system for a couple of years now and I honestly cant see a reason why I would ever stop doing things this way.

----------

## tecknojunky

 *MrUlterior wrote:*   

> AFAIK, nameif (in sys-apps/net-tools) can do this.
> 
> See the end of this page:
> 
> http://www.science.uva.nl/research/air/wiki/LogicalInterfaceNames

 

This is far from being perfect.  If at least ifconfig and nameif would be combine to name interfaces at invocation, it would be much better.  nameif is just an hack to rename interfaces, but it does not permit you to control the order in which they are invoked.  So if you want one nic to be always eth0, you still can head into trouble with nameif unless you perform a two pass renaming (the 1st being temporaries to avoid clashing, the second for effective names you want your nics to have).

I have genuine questions about nameif.  Does it consider physical or logical MAC addresses?  How would you integrate this into the boot process of Gentoo?

----------

## haven

 *Quote:*   

> Does it consider physical or logical MAC addresses? How would you integrate this into the boot process of Gentoo?

 

It uses physical mac addresses, have a read of the MAC address section of the url posted above (http://www.science.uva.nl/research/air/wiki/LogicalInterfaceNames)

As for booting, I just slapped the following in /etc/init.d/net.lo, its not pretty but it works for me.

```
if [[ -x /sbin/nameif ]]; then

        echo "executing nameif"

        /sbin/nameif

fi

```

As for the two pass naming - I may be missing the point but I dont think its needed. Here's my /etc/mactab for example, sure I could rename the interfaces but I'd only do that to help my understanding of what each interface was doing, keeping the standard naming sysem also keeps breakage to a minimum (I'm just too lazy to go through all my configs and change them all):

```
eth0 00:02:B3:2A:5A:70

eth1 00:02:B3:2A:57:27

eth2 00:02:B3:8A:5C:4A

eth3 00:04:23:AC:68:D0

eth4 00:04:23:AC:68:D1

```

----------

## tecknojunky

 *haven wrote:*   

>  *Quote:*   Does it consider physical or logical MAC addresses? How would you integrate this into the boot process of Gentoo? 
> 
> It uses physical mac addresses, have a read of the MAC address section of the url posted above (http://www.science.uva.nl/research/air/wiki/LogicalInterfaceNames)

 

Have you actualy tried to reference a spoofed mac address?  (ifconfig ethX hw XX:XX:XX:XX:XX:XX and then try nameif again).  I'll try eventuely, but I have urgencies to attend at this very moment.

 *haven wrote:*   

> As for booting, I just slapped the following in /etc/init.d/net.lo, its not pretty but it works for me.
> 
> ```
> if [[ -x /sbin/nameif ]]; then
> 
> ...

 Whoooo.  Clever.  :Very Happy:  Might work.

 *haven wrote:*   

> As for the two pass naming - I may be missing the point but I dont think its needed.

 

The point is that you can't rename an interface to something that exist already, so I guess that if you try to rename eth0 to eth1 without first renaming eth1 to something else, you'll have problems.  I haven't played at all with nameif yet.  SO' that's why I thought asking.  The way you put it, it would seem that nameif would somehow rename them succesfuly if you do it through /etc/mactab

----------

## UberLord

Guys - although you can slap nameif or ip link set name or ifrename or whatever into init.d/net.lo or conf.d/net preup() it's a Bad Idea (tm). Here's why.

rc starts net.eth1 (for whatever reason - hotplug,coldplug, run level, user)

eth1 gets renamed to foobar

now rc cannot stop foobar as it as no clue it's been started

what's more, rc cannot stop eth1 either as it thinks eth1 does not exist

Basically, the device needs to be renamed before the net.xxx script is called.

You can do this in /etc/hotplug/net.agent (hint look for ifrename as it uses that)

Or you can write a udev rule.

Or if your drivers are compiled into the kernel you can write a init.d script to use your renaming program of choice - just make sure that it depends before net and stick it in the boot runlevel.

But back to the origonal post, baselayout-1.12.0-alpha3 (not yet in portage) supports network configuration via MAC address instead of just interface name

----------

## tecknojunky

 *UberLord wrote:*   

> Basically, the device needs to be renamed before the net.xxx script is called.

 But, isn't net.lo called before net.whatever?

Admitidly, it is fudging, and that's why I way prefered Slackware back then, because YOU were in control of what's going on whith the initialisation scripts, contrary to Gentoo that is too much distro to my own taste when all I really need is dependency resolving when installing sources.  

That said, you can always fudge things when they behave as expected.  On the long term, doing stunts like that you soon realize how ridicoulous the presence of .keep in /etc/init.d is, as there will come an emerge when the diff will be a series of minuses lines followed by a series of pluses lines, rendering your modified script completely useless and unsalvagable.  I know, I tried once when I started using Gentoo.  

Like the Borgs will say: resistence is futile.

 *UberLord wrote:*   

> But back to the origonal post, baselayout-1.12.0-alpha3 (not yet in portage) supports network configuration via MAC address instead of just interface name

 Like Dr. Evil would say: Right...

----------

## UberLord

[quote="tecknojunky"But, isn't net.lo called before net.whatever?[/quote]

There's no guarantee that net.lo is in a runlevel.

What's more, each net.xxx script links to net.lo so you'll run through your device rename for every net.xxx script called

 *Quote:*   

> 
> 
> Admitidly, it is fudging, and that's why I way prefered Slackware back then, because YOU were in control of what's going on whith the initialisation scripts, contrary to Gentoo that is too much distro to my own taste when all I really need is dependency resolving when installing sources.

 

If you like it so much install slacks init system then.

----------

## tecknojunky

 *UberLord wrote:*   

>  *tecknojunky wrote:*   But, isn't net.lo called before net.whatever? 
> 
> There's no guarantee that net.lo is in a runlevel.

 My...  A Linux box without lo.  :Confused:   I have yet to see that.

 *UberLord wrote:*   

> What's more, each net.xxx script links to net.lo so you'll run through your device rename for every net.xxx script called

 Yes, but I'm the one creating those symlinks anyway, so...  :Sad: 

 *UberLord wrote:*   

>  *Quote:*   Admitidly, it is fudging, and that's why I way prefered Slackware back then, because YOU were in control of what's going on whith the initialisation scripts, contrary to Gentoo that is too much distro to my own taste when all I really need is dependency resolving when installing sources. 
> 
> If you like it so much install slacks init system then.

 I can do that?  :Shocked:  And Gentoo wont complain?!?  :Shocked:   :Shocked:   :Shocked: 

----------

## UberLord

 *tecknojunky wrote:*   

> I can do that?  And Gentoo wont complain?!?   

 

Well, I have no idea what the slack system looks like.

Provided that it doesn't overwrite any files used by baselayout (and maybe sysvinit for /etc/inittab) then yes you can.

Another option is to put baselayout in profile.provided or mask it somehow so portage never installs it again.

----------

## UberLord

And for all you whingers out there, baselayout-1.12.0-alpha3 will ship with a new module - rename.

```

rename_001122334455="foo1"

rename_eth1="foo2"

```

----------

## tecknojunky

 *UberLord wrote:*   

> And for all you whingers out there, baselayout-1.12.0-alpha3 will ship with a new module - rename.
> 
> ```
> 
> rename_001122334455="foo1"
> ...

 Interresting.

I'm getting literate about this because I'm replacing my router with one I build myself with Gentoo, now I have 3 identical NIC's and I would not want my firewall opening everything to the outside world just because the eth0 and eth1 got swapped after a kernel update or whatever reason.

----------

