# Bridging depending on one interface OR another

## marcelvs

Hello, I am configuring my laptop in order to gain the same ip address from my wireless router, so I am using a bridged network interface (the documentation helped a lot).

I am having a little problem (I am almost there) concerning starting the interface br0. I used as an example the script from the bridging documentation.

This documentation works as follow:

bridge_br0="eth0 wlan0"

config_eth0=( "null" )

config_wlan0=( "null" )

config_br0=( "dhcp" )

mac_br0="xxxxxxxx" -> this garantees I will receive the same ip address for both interfaces

If I stop here, I got a dhcp timeout because my wlan0 nor eth0 (I disconnect the ethernet cable) are not up yet. I receive some fallback ip address  from dhcpcd that is useless. I discovered by running manually the interfaces init script that if  I bring eth0 up and wlan0 up BEFORE br0 all works, so I added the following lines (just like the documentation).

depend_br0() {

  need net.eth0 net.wlan0

}

Now there is a problem because, it indeed starts eth0 and wlan0 before trying to start br0 BUT as I will never have both interfaces up at the same time (in my case I have disconnected eth0) br0 keeps waiting for eth0 forever.

I tried to use "use" instead of "need" because "use" is weaker then "need" but there is useless as well. I only need to have two commands being executed before bringing br0 up to this work:

/etc/init.d/net.eth0 start 

and

/etc/init.d/net.wlan0 start 

Now would be perfect if I have some LOGICAL operators just like:

depend_br0() {

  need net.eth0 OR net.wlan0

}

that would be perfect so br0 only will have to wait for the first itf brings up.

So, if there is a way to do this I will be glad to know.

Thanks in advance.

----------

## dmpogo

```

I am configuring my laptop in order to gain the same ip address from my wireless router

```

Can't you just tell the router to give your laptop always the same address ? My router has an option to specify a list of machines which should get fixed ip.

----------

## dmpogo

But answering your question, I think you can try to configure eth0 and wlan0 with '0.0.0.0' adresses in your net script.

I even think that startup scripts will be smart enough to start eth0 and wlan0 before the bridge

----------

## marcelvs

 *dmpogo wrote:*   

> 
> 
> ```
> 
> I am configuring my laptop in order to gain the same ip address from my wireless router
> ...

 

I think the option to bring up always br0 interface is more elegant and I don't think if my dd-wrt router can send the same ip to two different mac.

----------

## dmpogo

 *marcelvs wrote:*   

>  *dmpogo wrote:*   
> 
> ```
> 
> I am configuring my laptop in order to gain the same ip address from my wireless router
> ...

 

Agree, I understood that you actually want not jsut to have same IP between reboots but to have same IP whatever interface is up.

Bridging indeed can do it (at a some overhead cost, I believe)

----------

## marcelvs

 *dmpogo wrote:*   

> But answering your question, I think you can try to configure eth0 and wlan0 with '0.0.0.0' adresses in your net script.
> 
> I even think that startup scripts will be smart enough to start eth0 and wlan0 before the bridge

 

I tried that but the problem is the same if I start eth0 with the eth cable disconnected /etc/init.d/net.eth0 status reports "inactive" that is different than the answer this "need etho wlan0" expects.  I think I really need to say to this function somehow that only one interface is needed or simply tell "try to bring up these interfaces and I don't care about the results, just run the damm command lol". So until now I have this problem that br0 waits forever for eth0 brings up.

----------

## dmpogo

 *marcelvs wrote:*   

>  *dmpogo wrote:*   But answering your question, I think you can try to configure eth0 and wlan0 with '0.0.0.0' adresses in your net script.
> 
> I even think that startup scripts will be smart enough to start eth0 and wlan0 before the bridge 
> 
> I tried that but the problem is the same if I start eth0 with the eth cable disconnected /etc/init.d/net.eth0 status reports "inactive" that is different than the answer this "need etho wlan0" expects.  I think I really need to say to this function somehow that only one interface is needed or simply tell "try to bring up these interfaces and I don't care about the results, just run the damm command lol". So until now I have this problem that br0 waits forever for eth0 brings up.

 

I was assuming that you take away 'need' function in init.d/net.br0 script.   This of course can't get through.

Try to rely on the default script, just with some configuration for eth0.

I took this idea from the following advice for manual configuration

http://www.linuxfoundation.org/en/Net:Bridge#Adding_devices_to_a_bridge

which suggests the following way to manually bring up the bridge

```

# ifconfig eth0 0.0.0.0

 # ifconfig eth1 0.0.0.0

 # brctl addbr mybridge

 # brctl addif mybridge eth0

 # brctl addif mybridge eth1 

 # ifconfig mybridge up

```

and I suspect net script will do something similar

----------

## Inodoro_Pereyra

Callme lazy. I'll probably would go for the easy way:

 */etc/conf.d/net wrote:*   

> 
> 
> #-----------------------------------------------------------------------------
> 
> # MAC changer
> ...

 

 :Very Happy: 

Cheers!

----------

## marcelvs

 *dmpogo wrote:*   

>  *marcelvs wrote:*    *dmpogo wrote:*   But answering your question, I think you can try to configure eth0 and wlan0 with '0.0.0.0' adresses in your net script.
> 
> I even think that startup scripts will be smart enough to start eth0 and wlan0 before the bridge 
> 
> I tried that but the problem is the same if I start eth0 with the eth cable disconnected /etc/init.d/net.eth0 status reports "inactive" that is different than the answer this "need etho wlan0" expects.  I think I really need to say to this function somehow that only one interface is needed or simply tell "try to bring up these interfaces and I don't care about the results, just run the damm command lol". So until now I have this problem that br0 waits forever for eth0 brings up. 
> ...

 

I first tried this (add all interfaces to boot runlevel) but I was unlucky because the init tried to start br0 first  :Sad:  so br0 got a randon IP based on dhcpcd timeout. I think I will play with net.lo script. I was just avoiding doing this because I will have to merge all updates to net.lo script from now on. If you have any additional idea let me know, anyway thank you all very much for the help.

----------

## marcelvs

 *Inodoro_Pereyra wrote:*   

> Callme lazy. I'll probably would go for the easy way:
> 
>  */etc/conf.d/net wrote:*   
> 
> #-----------------------------------------------------------------------------
> ...

 

I thought this too but in case I plug eth cable I would have 2 interfaces (eth0 and wlan0) broadcasting the same mac address and getting the same IP (in fact I dont know what would happen with dhcp server in this case).

----------

## dmpogo

 *marcelvs wrote:*   

> 
> 
> I first tried this (add all interfaces to boot runlevel) but I was unlucky because the init tried to start br0 first  so br0 got a randon IP based on dhcpcd timeout. I think I will play with net.lo script. I was just avoiding doing this because I will have to merge all updates to net.lo script from now on. If you have any additional idea let me know, anyway thank you all very much for the help.

 

I agree that's not the way.   If you play with net.lo script, you are better off writing your own startup script.  

I am tempted to destroy my network setup and play with a bridge, but can't do it today  :Smile: 

Based on net.example to get eth0 up without assigning any address is

config_eth0=( "null" )

and

bridge_add_eth0="br0"

bridge_add_eth1="br0"

will dynamically add eth0 and eth1 AS THEY COME UP  (in contrast to bridge_br0="eth0 eth1")

isn't it what you want ?

----------

## marcelvs

 *Quote:*   

> 
> 
> I agree that's not the way.   If you play with net.lo script, you are better off writing your own startup script.  
> 
> I am tempted to destroy my network setup and play with a bridge, but can't do it today 
> ...

 

The problem still remains, because (I tried this in fact) br0 interface (now without any port added) tries to get IP via DHCP but because it got no port it gets its fake ip address (after a 30 seconds pausing the boot process). I am sure if I use static ip in this interface it will work, but the problem in dynamic adding interfaces is that you may run in trouble with dhcp.

As I said I am only playing with bridge because I want in gentoo the same behavior I have in Windows Vista (if I connect a network cable in eth0 it should not even try to get an IP in wireless interface) as I could not do this (I tried but ifplugd never detected my cable connected so it always start wlan0) I am playing with bridged network. 

I would like to know how most of people play with their notebooks in this aspect because I think what I am trying to do would be a very common task.

----------

## dmpogo

 *marcelvs wrote:*   

>  *Quote:*   
> 
> I agree that's not the way.   If you play with net.lo script, you are better off writing your own startup script.  
> 
> I am tempted to destroy my network setup and play with a bridge, but can't do it today 
> ...

 

So, can we say that currently your problem is that the bridge does not get IP through DHCP ?  If I follow the link I gave before, it says that manually the following sequence should work

```

# ifconfig eth0 0.0.0.0

 # ifconfig eth1 0.0.0.0

 # brctl addbr mybridge

 # brctl addif mybridge eth0

 # brctl addif mybridge eth1 

 # dhclient mybridge

```

If you do not use any startup scripts (disable /etc/init.d/net.{eth0,wlan0,br0}).   Will this sequence give an IP to the bridge ? (replace eth1  -> wlan0 and load wireless modules)

 *Quote:*   

> 
> 
> As I said I am only playing with bridge because I want in gentoo the same behavior I have in Windows Vista (if I connect a network cable in eth0 it should not even try to get an IP in wireless interface) as I could not do this (I tried but ifplugd never detected my cable connected so it always start wlan0) I am playing with bridged network. 
> 
> 

 

No need to be apologetic  :Smile: 

----------

## marcelvs

 *Quote:*   

> 
> 
> If you do not use any startup scripts (disable /etc/init.d/net.{eth0,wlan0,br0}). Will this sequence give an IP to the bridge ? (replace eth1 -> wlan0 and load wireless modules)
> 
> 

 

In fact I tried to remove from rc-update all interfaces to start with a non-network environment but I've got a lot of error messages because I have some services depending on "net" and it is a little dificult for me to start by hand my wlan0 interface without rc-script. 

I did the following: put eth0 wlan0 and br0 to start at boot level (as usual) and after I logged in I typed "....net.br0 stop" and ".....net.br0 start" (br0 down does not bring wlan0 nor eth0 down) so as eth0 and wlan0 was already up and present, it works. I think this might have the same effect these commands you told me to do.

----------

## marcelvs

I tried one more thing now, I removed net.br0 from runlevel boot and added it in default runlevel. After the reset it brings eth0, wlan0 and entered default runlevel but br0 timed-out again so I have to restart br0 after I logged in. That I did not understand.

----------

## dmpogo

 *marcelvs wrote:*   

>  *Quote:*   
> 
> If you do not use any startup scripts (disable /etc/init.d/net.{eth0,wlan0,br0}). Will this sequence give an IP to the bridge ? (replace eth1 -> wlan0 and load wireless modules)
> 
>  
> ...

 

Why is it difficult to start wlan0 ? You just load the module and wlan0 is created automatically but not up (you should see it with 'ifconfig -a ').

Next you can bring it up with 'ifconfig wlan0 up', if you wish. or try that 'ifconfig wlan0 0.0.0.0' as I am trying to suggest.

Ignore the rest of staff that wants the net. Let it time out. Use console if necessary.

----------

## dmpogo

 *marcelvs wrote:*   

> I tried one more thing now, I removed net.br0 from runlevel boot and added it in default runlevel. After the reset it brings eth0, wlan0 and entered default runlevel but br0 timed-out again so I have to restart br0 after I logged in. That I did not understand.

 

Does br0 gets IP if you run by hand

/etc/init.d/net.br0 start 

?

I see that your problem is that dhcp does not give IP to the bridge - may be it is your dhcp server problem ? Did you ever get IP from the dhcp to the bridge ?

----------

## marcelvs

 *Quote:*   

> Does br0 gets IP if you run by hand
> 
> /etc/init.d/net.br0 start 
> 
> ?
> ...

 

Yes, most of the time. But I have to had previously  ran /etc/init.d/net.eth0 start   and /etc/init.d/net.wlan0 start 

 *Quote:*   

> 
> 
> I see that your problem is that dhcp does not give IP to the bridge - may be it is your dhcp server problem ? Did you ever get IP from the dhcp to the bridge ?
> 
> 

 

My router gives an IP to the bridge, the problem is that most of the time br0 asks for an IP wlan0 is not up.

----------

