joyce7216 joyce7216 - 2 months ago 6x
Android Question

Is that possible to add two different default gateways into the routing table for two different NICs in android?

By default, the packets of default connection will use eth0 to go out/in.
The default gateway in the routing table is eth0's gw ip.

When another interface said eth1 is up, I want to add another default gateway for eth1.
Is that possible in android?
Since I cannot add another default gateway for eth1 because there already exists eth0's.

Thanks for your help.


A default gateway is only one, it's the default. You can have several interfaces each one with a different gateway, but only one default (your system cannot choose).

Imagine this:

eth0 - IP: Gateway:
eth1 - IP:

You should have at least 3 routes (usually automatic):

To go to some IP on, go thru eth0.
To go to some IP on, to thru eth1.
To go to anywhere else, go thru

So you see, you don't need more than one default gateway. What you might want is a gateway for a specific route. Imagine that you have the network that can only be reached by using gateway at With the above configuration, your machine would try to use the default gateway You could use something like:

route add -net netmask gw

This way you'll have a 2 gateways, but only 1 is the default. This second one is only used for network.