android route

附加说明;

有时候android系统不识别route 命令,则在命令前加个“ip”就可以了,具体原因知道是啥 么?

知道的朋友请回个帖子,谢谢了。

查看路由表:

cat /proc/net/route

增加一条路由:

ip route add 10.0.0.2/32 dev tiwlan0

删除一条路由:

ip route del 10.0.0.2/32

Linux中增加软路由的三种方法

Linux中增加软路由的三种方法,第一种:route add -net 172.16.6.0 netmask 255.255.255.0 gw 172.16.2.254 dev eth0/* 增加一条网络172.16.6.0/24 经过172.16.2.254 eth0 *//* -net增加网络 -host增加主机 netmask 子网掩码 gw 网关 dev 装置,设备,这里是你的网卡名*/route del gw 172.16.2.254 /* 删除默认网关172.16.2.254 */route del -net 172.16.86.0/24 /* 删除默认网络172.16.86.0 */route /* 显示当前路由表 */常用的是这种方式,但有时你在删除或一条软路由时会不起作用,会有什么提

示:SIOCADDRT: 无法接触网路所以这时用如下的这种方法就可以了第二种:实现的功能和上面的一样ip route add 172.16.6.0/24 via 172.16.2.254 dev eth0ip route del gw 172.16.2.254ip route del 172.16.6.0/24 dev eth0ip route

删除的方法:添加路由:

route add -net 10.0.0.0 netmask 255.0.0.0 dev eth0

删除路由:

route del -net 10.0.0.0 netmask 255.0.0.0 dev eth0

添加默认路由:

route add default gw 10.0.0.1

删除默认路由:

route del default gw 10.0.0.1

或者

How to set the Android network interface using shell commands

Posted on May 30, 2016

In this post, I’d like to tell you how to set the Android network preferences on Android devices, that is, IP Address, Netmask, Gatewayand DNS. This process can be easily done using the Android GUI, specifically in the Settings/Ethernet menu configuration. However, sometimes it is useful to know the shell commands in order to add them in boot scripts. The commands that you’ll find below, has been tested with the Android Ltouch F multi-touch, but I’m confident that there settings should work also with other devices too.

The basic steps are the following:

1. Using the miniUSB-USB cable, connect it to the Android Ltouch F and respectively to the PC (on Windows, make sure that you’ve previously installed the Google USB driver).

2. Open a terminal (or a command prompt on Windows) and type the “adb shell” command. If the cable and the Google USB driver are correctly set up, you will login into the Android device. In case the adb program gives an error, verify that Android device has the debugging preferences enabled.

3. The main commands that are necessary for setting the network are the following:

where you have to substitute [IP] with the static IP Address you want, [NETMASK] with the network netmask and [GATEWAY] with your network’s gateway address. The last parameter of the route command, i.e., eth0, specifies the network interface to modify (that might vary)

4. The last step refers to setting the DNS, that is the addresses of the servers that convert web address like for instance www.biemmeitalia.net into the machine readable 62.149.142.97.

Dns settings are set in the global preferences, in particular: net.eth0.dns1, net.eth0.dns2. Sometimes, you can set them directly by using net.dns1 and net.dns2 properties.

Just type

for setting the Google DNS into the global preferences of your Android device. If you need to verify whether you’ve correctly set them, type the command

and you’ll get the whole list of global preferences together with their values.

5. Finally, check if the network is up and working. Use the following command in the shell terminal: netcfg. You might find, among other information, one line that tells you the current status of a specific Ethernet interface (eth0 in this example). UP means that is working. The last column might be different depending on your system

That’s it!

If you like this post, please share it

1

1

2

1

1

2

eth0 UP [IP ADDR] [NETMASK] 0x00001043

getprop

setprop net.eth0.dns1 8.8.8.8

setprop net.eth0.dns2 4.4.4.4

ifconfig eth0 [IP] netmask [NETMASK]

route add default gw [GATEWAY] dev eth0

up vote

9

down vote

favorite

4

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

Please share the information..

add a comment

10

up vote

down vote

accepted

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 :)

4,48752962

add a comment

5

up vote

down vote

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

21.9k4116198

add a comment

5

up vote

down vote

adb shell "ip route show"

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

32.5k85773

5111

add a comment

2

up vote

down vote

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.

answered Jul 21 '17 at 17:22

1606

add a comment

1

up vote

down vote

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.