Is it possible to add two different default gateways to the routing table for two different network adapters in Android?

By default, packages will use eth0 for logout / logon by default. The default gateway in the routing table is eth0 gw ip.

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

Thank you for your help.

+4
source share
2 answers

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

Imagine the following:

eth0 - IP: 192.168.0.10/24 Gateway: 192.168.0.1 eth1 - IP: 192.168.1.10/24 

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

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

So, you see, you do not need more than one default gateway. What you may need is a gateway for a specific route. Imagine that you have a network 192.168.2.0 , access to which is possible only through the gateway in 192.168.1.1 . In the above configuration, your machine will try to use the default gateway 192.168.0.1 . You can use something like:

 route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1 

This way you will have 2 gateways, but only 1 is used by default. This second one is used only for the 192.168.2.0 network.

+5
source

This is possible on a machine with Windows 10, the second is processed as a software interface and is used for backup. I was expecting android to have this feature too, but instead, I have to change it manually every time my cable dies in order to switch to ADSL.

0
source

All Articles