# Multiple NIC mapping [SOLVED+HOWTO]

## danomac

Where to start...

I have 3 NICs in a PC, and I'm wondering how the kernel determines the order they are mapped in. I need to set up 2 as static and one as DHCP, so if eth0 becomes eth1 and vice versa on a reboot, it'll seriously muck things up and the PC's database won't be able to synchronize with another PC.

Is there a way to define a static way to define the mapping? All net modules are compiled directly in the kernel, and 2 of the NICs are of the same chipset.

lspci:

```

00:0a.0 Ethernet controller: Linksys NC100 Network Everywhere Fast Ethernet 10/100 (rev 11)

00:0b.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)

00:13.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)

```

dmesg: (the onboard LAN got named to eth1? I figured it'd be eth0, but oh well...)

```

eth0: RealTek RTL8139 at 0xe800, 00:30:bd:bb:25:e8, IRQ 10

eth0:  Identified 8139 chip type 'RTL-8100B/8139D'

eth1: RealTek RTL8139 at 0xd400, 00:20:ed:68:45:ec, IRQ 10

eth1:  Identified 8139 chip type 'RTL-8100B/8139D'

eth2: ADMtek Comet rev 17 at f880ec00, 00:50:BF:AE:E9:DC, IRQ 10.

```

ifconfig -a

```

eth0      Link encap:Ethernet  HWaddr 00:30:BD:BB:25:E8

          BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

          Interrupt:10 Base address:0xe800

eth1      Link encap:Ethernet  HWaddr 00:20:ED:68:45:EC

          inet addr:192.168.247.80  Bcast:192.168.247.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:2976 errors:0 dropped:0 overruns:0 frame:0

          TX packets:834 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:241888 (236.2 Kb)  TX bytes:70030 (68.3 Kb)

          Interrupt:10 Base address:0xd400

eth2      Link encap:Ethernet  HWaddr 00:50:BF:AE:E9:DC

          BROADCAST MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

          Interrupt:10 Base address:0xec00

```

The NICs are all detected and working. Before I do this final configuration I wanted to see if it could possibly change the mapping on me.Last edited by danomac on Wed Aug 16, 2006 4:58 am; edited 2 times in total

----------

## nielchiano

IIRC, there are 2 ways: the old nameif-way, and the much better udev way.

For the second way, see this guide. It's best to read it all, but the link should point directly to the interesting part.

You can change eth0 to eth1, but even (like I do) to eth_int or eth_wlan

----------

## danomac

Perfect, thanks... now I can make sure by MAC address that eth1 is the physical port I think it is.   :Smile: 

----------

## nielchiano

 *danomac wrote:*   

> Perfect, thanks... now I can make sure by MAC address that eth1 is the physical port I think it is.  

 

Glad it helped.

Could you add [solved] in the subject?

----------

## danomac

 *nielchiano wrote:*   

> Could you add [solved] in the subject?

 

Done.  :Smile: 

----------

## Bob P

 *danomac wrote:*   

> Perfect, thanks... now I can make sure by MAC address that eth1 is the physical port I think it is.  

 

insofar as rewriting the udev rules requires you to reconfigure all of your system interfaces, execution of this method is a little complicated.  writing the udev rules is simple enough following @dsd's guide, but then the user is also required to rewrite all of the references to the hardware interfaces on the system as well.  

could you do us all a favor and document what you've done to achieve a working configuration?  specifically, the modifications to /etc/init.d, /etc/conf.d, and your firewall configs would be a real time saver.

thanks!

----------

## nielchiano

 *Bob P wrote:*   

> could you do us all a favor and document what you've done to achieve a working configuration?  specifically, the modifications to /etc/init.d, /etc/conf.d, and your firewall configs would be a real time saver.

 

Isn't realy hard to find that out yourself, but here is mine:

```

cd /etc/udev/rules.d

cat > 10-local.rules <<EOF

KERNEL="eth*", SYSFS{address}="00:51:8c:a3:12:83", NAME="eth_wlan"

EOF

reboot

```

----------

## danomac

 *Bob P wrote:*   

> could you do us all a favor and document what you've done to achieve a working configuration?  specifically, the modifications to /etc/init.d, /etc/conf.d, and your firewall configs would be a real time saver.
> 
> thanks!

 

Bob P, I know what you mean. You mean to have everything [i.e all the initscripts and configs] set up correctly so that the system is aware of a system-wide change, correct? Gentoo's initscripts make this somewhat easy, I found out.

This has been moved to the Documentation, Tips & Tricks forum.

Is this enough information?   :Wink:  The bonus of setting it up this way is that if you have to stop a specific interface for whatever reason, you don't have to try to remember if it was eth0, 1, 2, 3 etc. Worth the mucking about and experimenting I did, I think.Last edited by danomac on Fri Feb 02, 2007 4:56 pm; edited 4 times in total

----------

## danomac

Hmm, maybe I should copy the howto over to the Tips forum.

----------

## Bob P

Thanks for your detailed tips.  I had done the udev thing, and ran into a problem when I renamed the interfaces with an alias.  I had renamed eth0, eth1 and eth2 to wan, lan, and dmz, respectively. this seemed to be intuitively obvious and user-friendly naming scheme at the time.   

Although the udev rules worked fine, the problem that came up was that the aliasing names really borked shorewall.  to get the udev aliases to work, I would have had to rewrite all of the shorewall scripts, replacing all references to eth0, etc.  that seemed like an unnecessarily burdensome task, which was something i didn't want to undertake.  i was hoping that you had a simple answer, and while i waited for your response i tried another approach.

my approach was to alias all of the eth* statements in udev to rename the devices with the aliases eth0, eth1 and eth2.  although it may seem like doing this would be frought with errors, you can do it this way if you're careful enough to perform the assignments in the right order, and assign the interfaces in the numeric order that they're detected by bios on your mobo.  (ie: slot ordering).  this prevents the user from having to rewrite all of their network dependent scripts.  the only downside i've noticed is the undesirable side effect of forcing you to pay attention to slot ordering if you should ever have to change a NIC again.

all things consdiered, its probably just as easy (or even easier) to just pass the ethernet interface configuration information, including the base address and interrupt , via the kernel parameters specificed in grub.conf.  as we all know, udev implementation is still incomplete, its still kind of buggy, and over all its still a rapidly moving target in gentoo.  at times i wonder if what i work on with udev today  will still work next week or next month.  :Confused: 

thanks again.

----------

## danomac

I've posted it the Documentation, Tips & Tricks forum here as well.

When it comes to configuring iptables/firewalls there's no real easy way other than aliases like you mentioned or editing the scripts. I'd just use grep and see where eth? is mentioned and run a script or something to change the references.

Edit: Wouldn't shorewall have a way to specify the interfaces you are using? I don't use it, but it seems odd that it would just "assume" the WAN side is always eth0!

----------

## Bob P

 *danomac wrote:*   

> Edit: Wouldn't shorewall have a way to specify the interfaces you are using? I don't use it, but it seems odd that it would just "assume" the WAN side is always eth0!

 

well, accepted convention in the industry is that eth0 is ALWAYS the external interface. similarly, when building a firewall, this convention is followed and eth0 is defined as the external interface on the firewall.  the LAN and DMZ are typically mapped to eth1 and eth2, again by convention.

the only "official" work that i've ever encountered that violates this convention is Mike Frysinger's Gentoo Home Router howto.   IMHO that guide intentionally violates accepted conventions and teaches people to do things bass ackwards.

----------

## zxy

@danomac

You made a little mistake, or maybe udev changed.

You should use == instead of = in udev configuration file.

```
KERNEL=="eth*", SYSFS{address}=="??:??:??:??:??:??", NAME="eth_wan"

KERNEL=="eth*", SYSFS{address}=="??:??:??:??:??:??", NAME="eth_lan"

```

That's at least how it works for me.

----------

## dtread

Good afternoon,

I would like to know if there is any way of configuring witch network adapter is eth0 and witch is eth1 and so on.

Regards

----------

## nixnut

merged above post here.

----------

