'Can I get the routing table entry in Android?

Is there any method for getting the routing table entry in Android?

Please share the information..



Solution 1:[1]

It is possible to get it through the ADB. You can get the routing table with

$ cat /proc/net/route

You can also execute these commands from within your program. I found this post that discusses this option. There is no answer however. If you could elaborate on what exactly you want in the end I can edit my answer to try and help out more.

Possibly complicated but maybe useful link :)

Solution 2:[2]

Thanks to Paul M for the hint!.

On my Android 6.0.1 (LineageOS)

/system/bin/ip route show table 0

shows routes of all tables

/system/bin/ip route show table rmnet0

shows route table which used when rmnet0 is active interface (mobile data).

/system/bin/ip route show table wlan0

shows route table which used when wlan0 is active.

in "Developers options" it is possible to keep rmnet0 active, even while wlan0 is active. But only one interface will be used at the same time (and one route table).

When WiFi connected to the network, but has no internet link, interface rmnet0 will be selected as main and route table will be used from rmnet0 table.

When WiFi has internet link, wlan0 will be used as main interface and "ip route show table wlan0" as current route table.

you can add or delete route from/to any route table as usual with ip command by adding "table xxx" to route string.

For example:

/system/bin/ip route delete table wlan0 default via 192.168.7.1 dev wlan0  proto static
/system/bin/ip route add table wlan0 192.168.7.0/24 dev wlan0 proto kernel scope link src 192.168.7.10 metric 327

All route tables will be overwritten every time interface goes on/off, lease renewed, etc...

Solution 3:[3]

adb shell "ip route show"

I found for myself more useful and easier to handle parsing.

Solution 4:[4]

Using Android Device Bridge(ADB)

  • Open the command prompt(windows) or terminal(mac & linux)

  • Do a cd(change directory) to platform-tools directory which is inside android sdk directory

  • Windows

    adb shell cat /proc/net/route

    Mac & Linux

    ./adb shell cat /proc/net/route

Solution 5:[5]

Android doesn't use just one routing table, so viewing the default or main table won't always help you!

If you run the command "ip rule list" then you will see how many routing tables there are; the "lookup nnnn" is the table. Then you can look at the specific table with "ip route show table 1006" for example.

I'm afraid I can't tell you which routing table is necessarily the one you want to look at, sorry.

Solution 6:[6]

Just install Termux or any other terminal emulator for android and enjoy using shell.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Culrurebt
Solution 3 Paul Roub
Solution 4
Solution 5 Paul M
Solution 6