# wired & wireless network simultaneously > 2 default routes

## cor

I've just installed gentoo on my laptop, and I'm trying to get the wireless (ipw2100) working. Getting it to work when I disable the wired connection (/etc/init.d/net.eth0 stop) is flawless, but if I want it to work at the same time, resolving names stops. So, both interfaces work fine when the other one is stopped. I've searched the forums a bit and I get the idea that its an issue with my default routes:

```
Kernel IP routing table

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface

130.89.136.0    *               255.255.252.0   U     0      0        0 eth1

130.89.160.0    *               255.255.224.0   U     0      0        0 eth0

loopback        localhost       255.0.0.0       UG    0      0        0 lo

default         130.89.136.1    0.0.0.0         UG    0      0        0 eth1

default         130.89.160.1    0.0.0.0         UG    0      0        0 eth0
```

route takes a loooong time to complete, about a minute or two. My /etc/resolv.conf is still valid; the nameservers stay the same.

So, I am wondering how I can prevent two default routes, or even better, have eth0 be preferred (wired), but if it goes down, let eth1 take over (wireless). route works fine if only one intercae is up.

If I have only one interface up, my gateway is not represented by an ip adress but by name (which resolves to the gateway ip adress). Pinging anything by name fails (unknown host) if both interfaces are up , but by ip adress works ping works. When only one interface is up, ping by name works.

Maybe I'm looking at the wrong things as the cause for the problem, but I'm not at home with troubleshooting networks, so any help will be appreciated.

----------

## UberLord

Could you test with baselayout-1.12.0_pre8 please?

----------

## cor

Hi, thanks for the suggestion, I won't be able to do much work on my gentoo box during the week, but I'll try this in the weekend, I'll keep you informed on what happens.

Thanks!

----------

## cor

OK, I finally got around to upgrading (to baselayout-1.12.0_pre8-r2 I see now), and things haven't really become easier. My eth0 won't use dhcp:

```
/etc/init.d/net.eth0 start

 * Starting eth0

 *   Bringing up eth0

 *     dhcp

 *     No loaded modules provide "dhcp" (dhcp_start)

 *     Trying fallback configuration

 *     www.xxx.yyy.zzz                                                    [ ok ]
```

If I bring eth0 down (/etc/init.d/net.eth0 stop) and then run ifconfig eth0 up && dhcpcd I get my IP adress and everything works.

My wireless connection also won't work anymore, it seems that some file which I didn't know the existence of has changed for the worse:

```
/etc/init.d/net.eth1 start

 * Caching service dependencies ...                                       [ ok ]

 * Starting eth1

 *   Starting wpa_supplicant on eth1 ...                                  [ ok ]

/lib/rcscripts/net.modules.d/wpa_supplicant: array assign: line 103: syntax erro

r near unexpected token `('

/lib/rcscripts/net.modules.d/wpa_supplicant: array assign: line 103: `IEEE 802.1

X (NO WPA)'
```

I solved the wpa_supplicant error by removing a () pair form line 103 of the file in question:

```
 local -a status="$( wpa_cli -i"$1" status | sed -n -e 's/^\(key_mgmt\|wpa_state\|EAP state\)=\([^=]\+\).*/\U\2/p' )"
```

Now, if I try to start eth1 the way it should (/etc/init.d/net.eth1 start) the wpa supplicant starts, and if i run wpa_cli from another terminal, I see it is assocatied with the right AP, but it still times out.

```
 /etc/init.d/net.eth1 start

 * Starting eth1

 *   Starting wpa_supplicant on eth1 ...                                  [ ok ]

 *     Timed out                                                                        [ !! ] 
```

Again, if I start the whole thing manually, I get an ip adress: ifconfig eth1 up, wpa_supplicant -i eth1 -B -c /etc/wpa_supplicant.conf, dhcpcd eth1.

The bad thing is that I still have the same symptoms as I started out with, and I have to go through more hassle to get everything as I used to have it.

----------

## jamapii

Looks like a difficult problem. If you just remove one of the default routes (possibly in a postup() function), it will be missing when you need it again (when an interface goes down), so it must be restored in a predown() function. (in /etc/conf.d/net or /etc/conf.d/net.eth0 ...)

The removal must be conditional (if the other interface is up then remove our default route...)

If you unplug the wired net, you want it to go down (if only for its predown() function to restore the WLAN default route), maybe ifplugd can help with this.

----------

## a2gentoo

I have a laptop with the IPW wireless card.

I just turned off the wired port in the BIOS. That enede the fight. Now my wireless is ETH0

c

----------

## cor

@a2gentoo: This is not the problem I'm having. Both of my interfaces work, but not simultaneously. If your having problems with a fight between wired and wireless, remove eth0 (wired) from your standard runlevel, and only activate eth1 (wireless). This way, you won't have to reboot your pc if you want wired, but only activate eth1 via the usual, and deacitvate eth0.

@jamapii: Yeah, removing one of the default routes when both interfaces are up solves the problem. I guess using ifplugd's capabailities with postup and predown functions should do it, I'll see how far I get with that, and let you know of the progress. Thanks for the suggestion.

Also,  unless I'm doing something obviously wrong (I ran etc-update, but I might have ignored somethings, rejected some changes) I guess I'll downgrade back to the stable baselayout

----------

## UberLord

cor, the dhcp problem can be solved by emerging dhcpcd-2.0.0

Also, what version of wpa_supplicant are you using there?

----------

## cor

Thanks, upgrading dhcpcd to 2.0 (from 1.3 something) solved the problem with bringing up networking on boot.

I'm using net-wireless/wpa_supplicant-0.3.9-r1, which I believe is the latest stable version.

----------

## UberLord

Could you post the output of "wpa_cli -ieth1 status" please?

----------

## Apollyon

Hi,

I have a similar problem. I think the best solution to this double default route thing would be to give a higher metric to the routes used by a particular interface over the other. That is, have the wired connection have a metric of 0, and the wireless one a metric of 1. This way, connections will always use the wired connection over the wireless if both are available.

The problem is that I don't know how to set the metrics automatically. I know of a tool, ifmetric, which does this, but I have to execute it every time my wireless interface comes up. Is there a way to have this executed automagically by specifying something in /etc/conf.d/net? I haven't been able to find anything about it in the documentation, and setting config_eth1=("dhcp metric 1") does nothing.

----------

## petrjanda

 *Apollyon wrote:*   

> Hi,
> 
> I have a similar problem. I think the best solution to this double default route thing would be to give a higher metric to the routes used by a particular interface over the other. That is, have the wired connection have a metric of 0, and the wireless one a metric of 1. This way, connections will always use the wired connection over the wireless if both are available.
> 
> The problem is that I don't know how to set the metrics automatically. I know of a tool, ifmetric, which does this, but I have to execute it every time my wireless interface comes up. Is there a way to have this executed automagically by specifying something in /etc/conf.d/net? I haven't been able to find anything about it in the documentation, and setting config_eth1=("dhcp metric 1") does nothing.

 

Remove the default route entries from /etc/conf.d/net

```

emerge iproute2

touch /etc/init.d/routes

chmod 755 /etc/init.d/routes

```

/etc/init.d/routes

```

#!/sbin/runscript

start() {

        ebegin "Adding default routes"

        ip route add 0.0.0.0 dev eth0 via $GatewayIPAddress metric 0

        ip route add 0.0.0.0 dev eth1 via $GatewayIPAddress metric 1

        eend $?

}

stop() {

        ebegin "Removing default routes"

        ip route del 0.0.0.0 dev eth0 via $GatewayIPAddress metric 0

        ip route del 0.0.0.0 dev eth1 via $GatewayIPAddress metric 1

        eend $?

}

```

Substitute "$GatewayIPAddress" with real next-hop router addresses.

----------

## UberLord

 *Apollyon wrote:*   

> I have a similar problem. I think the best solution to this double default route thing would be to give a higher metric to the routes used by a particular interface over the other. That is, have the wired connection have a metric of 0, and the wireless one a metric of 1. This way, connections will always use the wired connection over the wireless if both are available.
> 
> The problem is that I don't know how to set the metrics automatically. I know of a tool, ifmetric, which does this, but I have to execute it every time my wireless interface comes up. Is there a way to have this executed automagically by specifying something in /etc/conf.d/net? I haven't been able to find anything about it in the documentation, and setting config_eth1=("dhcp metric 1") does nothing.

 

baselayout-1.12.0_pre9-r1 does this automatically for you if you set RC_AUTO_INTERFACE="yes" in /etc/conf.d/net

All stable dhcp clients can now just the route metric too  :Smile: 

@petrjanda that's better done in postup()/postdown() functions in conf.d/net otherwise there will be issues if you start/stop interfaces.

----------

## petrjanda

 *UberLord wrote:*   

>  *Apollyon wrote:*   I have a similar problem. I think the best solution to this double default route thing would be to give a higher metric to the routes used by a particular interface over the other. That is, have the wired connection have a metric of 0, and the wireless one a metric of 1. This way, connections will always use the wired connection over the wireless if both are available.
> 
> The problem is that I don't know how to set the metrics automatically. I know of a tool, ifmetric, which does this, but I have to execute it every time my wireless interface comes up. Is there a way to have this executed automagically by specifying something in /etc/conf.d/net? I haven't been able to find anything about it in the documentation, and setting config_eth1=("dhcp metric 1") does nothing. 
> 
> baselayout-1.12.0_pre9-r1 does this automatically for you if you set RC_AUTO_INTERFACE="yes" in /etc/conf.d/net
> ...

 

I thought RC_AUTO_INTERFACE was in /etc/conf.d/rc.

How exactly does it work?

----------

## UberLord

 *petrjanda wrote:*   

> I thought RC_AUTO_INTERFACE was in /etc/conf.d/rc.
> 
> How exactly does it work?

 

I blogged about it earlier

http://roy.marples.name/node/203

http://roy.marples.name/node/207

Essentially, baselayout-1.12 knows something about the link (wired, wireless, bridge, tunnel etc) so we add a magic number (1000 for wireless) to the no of gateways below us (in metric terms).

----------

## danton

 *Apollyon wrote:*   

> The problem is that I don't know how to set the metrics automatically. I know of a tool, ifmetric, which does this, but I have to execute it every time my wireless interface comes up. Is there a way to have this executed automagically by specifying something in /etc/conf.d/net? I haven't been able to find anything about it in the documentation, and setting config_eth1=("dhcp metric 1") does nothing.

 

These lines in /etc/conf.d/net

```
dhcpcd_eth0=("-t 30 -m 10")

dhcpcd_eth1=("-t 30 -m 20")
```

seems to work for me (stable baselayout). Also, I use ifplugd for wired ethernet (eth0) and wpa_supplicant for wireless (eth1). 

BTW,  I start my wireless eth1 from a custom non-blocking script in default runlevel  so that I don't have to wait for association with AP or timeout. Is there an "official gentoo" way of doing this?

----------

## UberLord

The way I do is to compile my NIC drivers as external modules. coldplug then runs on boot, loads the modules by itself which triggers hotplug. hotplug then starts net.xxx for me

So I don't have any net.xxx scripts in any runlevels - except for net.lo in boot

----------

## risa2000

 *UberLord wrote:*   

> The way I do is to compile my NIC drivers as external modules. coldplug then runs on boot, loads the modules by itself which triggers hotplug. hotplug then starts net.xxx for me
> 
> So I don't have any net.xxx scripts in any runlevels - except for net.lo in boot

 

I do find something scary about having hotplug running based on loading the driver. In fact I thought it is the other way, once the device is attached, the hotplug loads the driver, right?

Unfortunately I found out that at least for network drivers, udev on my system, somehow (have to figure it out yet) executes corresponding /etc/init.d/net.* scripts. I use hotplug_eth0="no" in net config, but is there a way to remove this hotpluging stuff completely? Or, in other words, is it safe to run only udev, without hotplug?

----------

## UberLord

You can always remove net.agent from /etc/hotplug to stop udev/hotplug from starting any network devices

----------

