(Was: Detecting ethernet gadget connections) Is bonding possible?

Evgeny nad.oby at gmail.com
Fri Mar 6 17:02:10 CET 2009

On Fri, Mar 6, 2009 at 6:11 PM, Daniel Benoy <daniel at benoy.name> wrote:
>> Is this necessary?
>> Just set a higher metric on usb0, then routes thorough eth0 will be
>> preferred when available. The default route through usb0 will only be
>> used as a last resort when there is no other way.
> Yes.  Packets will route out that interface whether it's connected or not because it never disappears even when the cable is completely unplugged, and I want (obviously) the usb0 interface to be a higher priority than my gprs interface, so every packet would go out usb0 if I set it to a preferable metric.
> Unless I brought the interface up and down manually when the cable is disconnected, which brings us back to the original problem.
> Also, I'm setting up routing based on firewall rules, so it complicates things.  When I'm writing my firewall script it needs to know whether usb is up or not to decide where web and ssh and instant messaging should be routed.
> I eventually did come up with a solution to this.  I check the charger state.  If it detects a host it should be charging at 500mA.  This doesn't prove that the network interface is successfully configured, but it's good enough for my purposes.
> If anyone's interested in seeing the convoluted script I had to make, I've attached it to this e-mail.
> Here's basically what it does for me:
> 1) Automatically brings up and down network interfaces.  (Only for usb0 now.  I took out eth0 wifi scanning because I found a way to do it outside of the script.  And ppp0 I'm still handling manually.. may change that in the future)
> 2) Creates a routing table for each device with a default route out that device automatically by detecting changes to the main table made by ifup and other connection software.
> 3) Creates iptables rules automatically based on which interfaces are up and which are down, in accordance with my preferences.  (xmpp and ssh always go out GPRS, because I want the connections to be unbroken when I roam away from my usb or wifi connection, and they're low bandwidth)
> The effect is that web browsing and such will switch over seamlessly when I come within range of my home network, while my instant messager never has its connection broken so long as it's in cell phone range.
> If you want to try the script as well you'll need some firewall rules, such as:
> iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
> iptables -t nat -A POSTROUTING -o usb0 -j MASQUERADE
> iptables -t nat -A POSTROUTING -o ppp+ -j MASQUERADE
> iptables -t mangle -A OUTPUT -j CUSTOMROUTE
> Someone let me know if there's a better way to achieve this.  I thought about using the ROUTE iptables target, but it seemed pretty complicated to get installed.
> One problem I've encountered is that when software determines its source address automatically (There's rarely an option to set it by hand, and I wouldn't want to be doing that anyway) then it will examine the routing table for its source address *without sending a packet* so therefore firewall never marks the packet, and the routing table thinks its supposed to use the main rule chain.  My solution for this was the MASQUERADE lines above.
> --
> Daniel Benoy
> http://daniel.benoy.name

Is it possible to use "bonding" to all possible interfaces (eth0,
usb0, bnep0) making preferences trough bonding?

guessed /etc/network/interfaces
iface bond0
inet static
	up /sbin/ifenslave bond0 usb0
	up /sbin/ifenslave bond0 eth0
	up /sbin/ifenslave bond0 bnep0
	up /sbin/ifenslave bond0 ppp0

alias bond0 bonding
options bonding mode=1 miimon=100 downdelay=200 updelay=200
So it will end with only one bond0 to work with.
may be it's not applicable here

So long, and thanks for all the fish.

More information about the community mailing list