# different /etc/conf.d/net files at boot based on runlevel?

## SirronD

I have a IBM Thinkpad with a built in lan (eepro100 - and eth0). I also have a linksys wan card (pcmcia_core, i82365, ds, orinoco orinoco_cs - and eth1).

They both work well, but I need a way to selectively (at boot) choose which one to use (but have the same static IP and gateway).

So I did the following

1. create seperate "gentoo" runlevels named xdm-lan and xdm-wan. And in xdm-lan there is a link to /etc/init.d/net.eth0, and in xdm-wan there is a link to /etc/init.d/net.eth1

2. modified the depend in net.eth1 to need pcmcia

3. added seperate menus in grub with one for runlevel 5 (xdm-lan) and the other to runlevel 4 (xdm-wan).

4. modified /etc/inittab to point to xdm-wan and xdm-lan at runlevels 4 and 5.

Each "runlevel" works correctly except for one BIG problem, and that is 

/etc/conf.d/net.

How do I properly define my gateway as eth0 or eth1 depending on which runlevel I choose? Somehow /etc/init.d/net.eth0 and /etc/init.d/net.eth1 both point to the same /etc/conf.d/net script and so I always must manually switch my gateway after logging in.

----------

## klieber

 *SirronD wrote:*   

> Somehow /etc/init.d/net.eth0 and /etc/init.d/net.eth1 both point to the same /etc/conf.d/net script and so I always must manually switch my gateway after logging in.

 

Unless I'm misunderstanding your quesiton, you would define both gateways in the same /etc/conf.d/net script: 

```
gateway="eth0/192.168.2.1"

gateway="eth1/192.168.1.1"
```

Then, the right gateway should get defined correctly no matter which eth interface you start.

--kurt

----------

## Guest

If I set both gateway strings in the /etc/conf.d/net file it does not work.

Here is a copy of my net file (of course I have real IP, broadcast, mask and gateway addresses)

iface_eth0="1.2.3.4 broadcast 1.2.3.7 netmask 255.255.255.xxx"

iface_eth1="1.2.3.4 broadcast 1.2.3.7 netmask 255.255.255.xxx"

gateway="eth0/1.2.3.1"

gateway="eth1/1.2.3.1"

If I have the "gateway=" line twice, then it assigns eth1 (the last listed) as my gateway device even though eth0 is the only device activated. So I cannot use any outside address until I manually "route -add..." to swithc to "eth0/..." as the gateway.

In your example you have two different IP addresses for eth0 and eth1. I only have a single address, and a single gateway.

----------

## klieber

 *Anonymous wrote:*   

> I only have a single address, and a single gateway.

 

OK, now I'm confused -- if you only have a single address and a single gateway, then why do you need to change your gateway at all?

--kurt

----------

## Guest

I have a wireless PC Card (linksys) and accesspoint on my 100mbit home lan network. The wireless part works at 11mbits. This is great for most access including internet access thru my DSL as the 11mbits exceeds the speed of my DSL connection. So when I use my laptop I normally use the wireless connetion. The wireless card is eth1 on my laptop.

But sometimes I need to backup big files (2GB database container files) to other computers in my home network. And sometimes I access a database running on another machine in my network. For those tasks I plug in my cat5 cable, and remove the wireless PCMCIA card. The builtin lan in my laptop is eth0, and it operates at 100mbit.

The difference in backup time between 11 vs 100 speed connection is hours for these 2GB files. And response time when accessing data from an NFS mount to another machine is noticable. 

So when I use my laptop for internet surfing (playtime!), I use the wireless connection, and I can roam around my house. But when I am working, I need the cat5 connection, and I am tethered to my home/office.

----------

## klieber

 *Anonymous wrote:*   

> So when I use my laptop for internet surfing (playtime!), I use the wireless connection, and I can roam around my house. But when I am working, I need the cat5 connection, and I am tethered to my home/office.

 

I understand that part, but it sounds like the gateway is the same in either case.  Your original post said you had to switch your gateway -- that's the part that I don't get.

--kurt

----------

## Guest

It is the gateway device that is the problem. The system needs the device (eth0 or eth1). 

So with the statement as:   gateway="eth0/1.2.3.1" then it searches for the gateway (1.2.3.1) over eth0.

With the statement as:   gateway="eth1/1.2.3.1" then it searches for the gateway (1.2.3.1) over eth1.

If both statemnts are active (in the /etc/conf.d/net file), only the last one "takes".

When I have the wireless card, my only active net device is eth1, and the gateway device must be eth1. When I have my cat5 cable plugged in, my only active net device is eth0, and the gateway device must be eth0.

So the problem is that "eth0" is the only active device, but the gateway device is assigned to "eth1". So no gateway, and no net access.

----------

## Guest

First, I'll say I don't have a clue  :Smile: .  Next, I'll say I was curious, so I started poking around.

Could you put something in /etc/init.d/net.eth0 and net.eth1 that would make or mv the correct file?

```
checkconfig() {

   if [ -z "$(eval echo \$\{iface_${IFACE}\})" ]

   then

      eerror "Please make sure that /etc/conf.d/net has \$iface_$IFACE set"

      return 1

   fi

}
```

Since net.eth0 (on my system) makes sure the interface is set (above code), I'd think you could do 

some work in the script to do some work.  Just a thought.  Maybe there is a better place than the net.eth? files to do the work.

----------

## pjp

 :Mad:  darn timeout

----------

## SirronD

I finally figured out what I need to do. And it's very easy (of course after figuring it out !!!)

the "/sbin/runscript.sh" script sources the file /etc/conf.d/net for any of the /etc/init.d/net.XXXX starts. But if there is a matching /etc/conf.d/net.XXXX then that is the file it will use rather than the generic /etc/conf.d/net.

So I did not need to do anything special (like trying to cp special /etc/conf.d/net files).

I created /etc/conf.d/net.eth0 with a gateway of - gateway="eth0/xxx.xxx.xxx.xxx"

I created /etc/conf.d/net.eth1 with a gateway of - gateway="eth1/xxx.xxx.xxx.xxx"

I created runlevel xdm-lan which includes net.eth0 (my lan connection). I created runlevel xdm-wan which included net.eth1 (my wireless connection).

Now in grub I choose to boot xdm-lan (when connected to my cat 5 cable and I need the 100mbit connection) or boot xdm-wan (connected to my wireless pcmcia card and I want to wander around my house).

All with the same IP and gateway. And the gateway uses the correct device!

----------

