# Bind iface to a specific card?

## nekranos

This is a really stupid question, but, can you bind net.eth0 to a certain card? I have both wireless (prism2, kernel module) and ethernet cards in my laptop, and net.eth0 constantly switches from controlling wireless or ethernet depending on which is available (which is plugged in), thus why I ask.

Better yet, is there any way to just set my wireless card to an iface like net.wlan0 and bind it to that? If that were possible, then I wouldn't have to mess with net.eth0 and have that be ethernet....

Another thing - when using the wireless-config script, it has modified things so that my ethernet also goes through "predown"; is there any way to have it do predown on the wireless but not ethernet?

(as if any of that made sense  :Neutral: )

Thanks,

-nek

----------

## veezi

Hi ..

I don't know much about wireless or the rest of your questions! But here's what I know: ethernet index is done by the kernel depending on how it enumerates devices, so the first module inserted will be eth0 and so on. I don't think that you can have an ethernet device stuck to one type of card.

Now, if you're using only one depending on your location (example: office, home, airport) then why not use init profiles. You get to specify which devices will be used in a profile and choose that profile at startup. Search the forum for 'init profile', you'll find lots of threads about the subject.

Just a thought,

----------

## moocha

Can't help you with the wireless stuff (don't have any experience with it). But it's possible to force a specific card to a specific interface when they're using different drivers. The trick is to create a new file under /etc/modules.d (call it "net" or whatever, the name doesn't matter), and alias eth0 to the driver for the card you want on eth0. For example, if your Ethernet card were using, say, the e100 driver, you'd put 

```
alias eth0 e100
```

 in /etc/modules.d/net. After you've created that file run 

```
modules-update
```

 which will recreate your modules.conf, and reboot (or get the interfaces down, rmmod the drivers, and bring the interfaces back up - which is a bit tedious, a reboot may be quicker).

The reason this works is that the kernel will modprobe a module called "eth0" when asked to bring the eth0 interface up - which will cause the e100 module to be loaded in this example, which in turn will cause the eth0 label to be assigned to the card using the e100 driver.

----------

## veezi

I didn't know that.

So, let's say I have one e100 card in my machine if I add 'alias eth1 e100' to config and then I do 'modprobe e100' then I'll have one ethernet device in kernel, and it's called eth1 not eth0?

Is that correct?

----------

## moocha

 *vzeidat wrote:*   

> I didn't know that.
> 
> So, let's say I have one e100 card in my machine if I add 'alias eth1 e100' to config and then I do 'modprobe e100' then I'll have one ethernet device in kernel, and it's called eth1 not eth0?
> 
> Is that correct?

 

Indirectly - only if you have TWO cards in that machine, and the other one isn't using the e100 driver, and you've aliased the other driver to eth0. If you have a single card it'll always be eth0. If you had 10 cards, all of different type, and you wanted to ensure a specific card were always, say, eth5, then you'd have to add aliases for eth0 through eth4 too. BTW, e100 was only an example, it works with any driver.

----------

## MikePikeFL

 *moocha wrote:*   

> Indirectly - only if you have TWO cards in that machine, and the other one isn't using the e100 driver, and you've aliased the other driver to eth0. If you have a single card it'll always be eth0. If you had 10 cards, all of different type, and you wanted to ensure a specific card were always, say, eth5, then you'd have to add aliases for eth0 through eth4 too. BTW, e100 was only an example, it works with any driver.

 

I asked basically this same question in this post, which incidently got no hits.

So related to this concept is aliasing a device as "wlan0". How does that work? Or is that an ndiswrapper specific option?

My problem is that when I put my laptop into the docking station it screws up all the ordering and my quickswitch scripts don't work so great. While ndiswrapper sucked for what I wanted to do, the wlan0 feature was quite nice!

----------

## nekranos

 *MikePikeFL wrote:*   

>  *moocha wrote:*   *snip* 
> 
> I asked basically this same question in this post, which incidently got no hits.
> 
> So related to this concept is aliasing a device as "wlan0". How does that work? Or is that an ndiswrapper specific option?
> ...

 

I actually saw that post of yours, and saw no replies, so that's why I made a new thread :)

I spoke with a few of the guys on #gentoo-laptop (great people), who recommended the usage of a tool called "nameif". It basically requires that you create a file [/etc/mactab] that specifies the MAC address of your card and the interface that you want it to be renamed to. Like:

```
#of course, rename the MAC addresses to your card's specific values

eth0 00:00:00:00:00

wlan0 00:00:00:00:01
```

After which, you'll have to make the net.eth0/net.wlan0 (name as you did in mactab), shut down all interfaces and run /sbin/nameif, and then restart them. I did a search on the forums, and saw that one user had written up an init.d startup script [can't find it, typing this from links in console].

That would've worked perfectly, execpt for that hotplug/udev/whatever loads the modules, and I don't know when to call the init.d script. Calling it before hotplug results in an error saying "interface does not exist" or something to that effect, and calling it after doesn't work, since I have to shutdown the automatically-connected connection. Messy.

Looking into modifying the udev rules file, something that I read on the forums instead....

(as if any of that post made sense)

----------

## MikePikeFL

 *nekranos wrote:*   

> I spoke with a few of the guys on #gentoo-laptop (great people), who recommended the usage of a tool called "nameif".

 

Awesome! Thanks. I'll have a look as well, and see what I can find. I just don't understand why it worked with ndiswrapper and not my current module. I'm sure there is a reason, and someone must know... plus now I have all my friends' interests piqued so they want to know the results.

----------

## nekranos

(yeah, yeah, thread necromancy, I know, but just following up)

Following the guide here, I was able to force my wireless card to use net.wlan0. I made two copies of the original net.eth0 in /etc/init.d and called them net.wlan0 and net.lan0 and deleted the original.

Created a file, /etc/udev/rules.d/10-local.rules (and along the way learned how to harness vim) with something like this:

```
# yes, that is eth*. As in, ee tee eechi star.

# that threw me off at first.

# again, replace the MAC address with your own~

KERNEL="eth*", SYSFS{address}="00:00:00:00:00:00", NAME="wlan0"

KERNEL="eth*", SYSFS{address}="00:00:00:00:00:00", NAME="lan0"
```

Reboot, and the card is correctly bound to the corresponding script you copied in /etc/init.d.

Although, in dmesg, it still shows up as the "old" and "unrenamed" interface name. Works, though. Don't even need "nameif", which is a plus. Yay!

----------

## veezi

Although I didn't have any problem since I have only one net  :Razz:  , But I sure did learn two new things from this thread, nameif, and a udev trick.

Thanks nekranos!  :Very Happy: 

----------

## nahpets

I was just having the same problem, and I may have found a simple solution.  Go edit "/etc/modules.autoload.d/kernel-2.6" and put your drivers in the order you want them loaded.  Check out "man modules.autoload" for more info.

----------

## jdgill0

 *nahpets wrote:*   

> I was just having the same problem, and I may have found a simple solution.  Go edit "/etc/modules.autoload.d/kernel-2.6" and put your drivers in the order you want them loaded.  Check out "man modules.autoload" for more info.

 

I had the same problems with two nics myself.  A friend of mine does the same trick you mention here. However, both of my nics are identical. To fix this problem I looked at "cat /proc/pci" and got the base address for each card. Then added the following to the kernel options in grub.conf:

```
ether=10,0xac00,eth0 ether=10,0xcc00,eth1
```

This fixed the problem without my having to uses any additional software or tricks.

----------

## nahpets

 *Quote:*   

> 
> 
> To fix this problem I looked at "cat /proc/pci" and got the base address for each card. Then added the following to the kernel options in grub.conf: 
> 
> ```
> ...

 

hmm... that's a nice trick.  My eth0 is an onboard nic, and eth1 is plugged into a PCI slot.  Can I do the same thing?

----------

## jdgill0

 *nahpets wrote:*   

>  *Quote:*   
> 
> To fix this problem I looked at "cat /proc/pci" and got the base address for each card. Then added the following to the kernel options in grub.conf: 
> 
> ```
> ...

 

I see no reason why you could not. You only need the irq and base address (that is what the "10" is for) ... don't let the "cat /proc/pci" get in the way, that was only so I could find the irq and base addy for my nics.

----------

## MikePikeFL

So I finally have all this working out the way I want. Took long enough   :Very Happy: 

I like the simplicity of nahpets' ordered module loading suggestion, but my problem was a little different, since I am doing this on my laptop and I have many different network configurations.

-onboard nic

-docking station

-pcmcia wireless

I also liked jdgill0's suggestion too, but again, sometimes I'm in the dock, sometimes I'm using the wireless.

So I followed these guides (in order!): 

http://www.gentoo.org/doc/en/migration-to-2.6.xml

http://www.gentoo.org/doc/en/udev-guide.xml

http://www.reactivated.net/udevrules.php

Now I'm running a pure udev system (with all the 2.6 bells and whistles) and quickswitch to do exactly what I want.

----------

## gorjusborg

 *Quote:*   

> 
> 
> So I followed these guides (in order!):
> 
> http://www.gentoo.org/doc/en/migration-to-2.6.xml
> ...

 

Me too, thanks to you  :Very Happy: 

I already had 2.6.10-r1 kernel running, and had a pure udev system up and running so I went straight to the third link.

This described exactly what I wanted to do.... map a real piece of hardware to a specific persistent device.  

Now, my wired ethernet hardware is always eth0 and my over-the-air ethernet hardware is always eth1, no matter what order the modules are loaded.  Personally, I think that it is cludgey to depend on the order devices are connected (or modules are loaded) to determine which NIC gets which name.  After all, a normal NIC is a whole lot different than a Wifi NIC, and should be recognized as being different in order to make managing them easier.

What got me looking for this sort of thing was that configurations I set up in quickswitch wouldn't work if I:

```

bash$ rmmod e100 #1st module loaded at boot, so eth0

bash$ rmmod airo  #2nd module loaded at boot, so eth1

bash$ modprobe airo  #now 1st module, so eth0

bash$ modprobe e100 #now 2nd module, so eth1

bash$ quickswitch WifiHome #incorrectly

```

Since quickswitch uses the device names to specify the correct network setups, my wifi card was not being configured correctly since it was no longer eth1 because I had manually re-loaded the modules in the wrong order.  This also meant that I could not simply load ONLY the airo driver, since it would be named eth0.  Sure, I could have loaded e100 module as an eth0 placeholder, then reloaded airo, which would correctly be name eth1, but this seemed ridiculous to me.

 There had to be a better way, and once again the gentoo forums come to the rescue  :Smile: 

----------

## MikePikeFL

 *gorjusborg wrote:*   

> Me too, thanks to you  

 

Glad to be of help! I have since discovered that sometimes renaming the interfaces to whatever I want is troublesome. On my laptop I call the built in NIC lan, and my pcmcia adaptor wlan, and then the docking station NIC dock.

Sometimes scripts and other programs expect ethX... even my own thesis scripts I've been developing. Whoops.  :Embarassed: 

I have a problem with quickswitch where it remembers my last config and uses that on boot up- even if I choose another one from my boot loader. Since you mentioned quickswitch, do you have this issue as well?

----------

