Android Hikey set gateway ip to static IP using ethernet connection


#1

My hikey is running Android + OPTEE. The branch I am building has some issue using wifi, so I get internet through Ethernet. I want to modify the gateway IP to my proxy server (192.168.0.104). Android support modifying gateway IP through Setting app if it is a wifi connection but I did not find similar options in Setting app for ethernet connection.
I run the following command to manually set gateway IP:

ip route add default via 192.168.0.104 dev eth0

The ip route shows following:

Destination	     Gateway 	    Genmask 	    Flags     MSS Window  irtt Iface
0.0.0.0         192.168.0.104   0.0.0.0         UG        0 0          0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U         0 0          0 eth0

Looks like the gateway is added. However, when I run any apps and monitor the wireshark on my proxy server, the hikey does not forward any traffic to proxy.

Any advice where I did wrong? Any other suggestion how should I set up static gateway IP on Hikey?

Thanks for the assistance.


#2

The ip route looks a bit strange to me. Can you compare it with the one before you manually set the gateway IP, and try to make the destination and genmask the same?

Alternatively, try reverting https://android-git.linaro.org/device/linaro/hikey.git/commit/?id=17ea3f3016b967ddcca535acb90dc1c3f8d98ec2 to see if you can get the wifi to work.


#3

Thanks for your reply. After investigation, Android actually has multiple routing table with different priority as shown in following.

hikey:/ # ip rule show
0: from all lookup local
10000: from all fwmark 0xc0000/0xd0000 lookup legacy_system
10500: from all oif eth0 uidrange 0-0 lookup eth0
13000: from all fwmark 0x10063/0x1ffff lookup local_network
13000: from all fwmark 0x10065/0x1ffff lookup eth0
14000: from all oif eth0 lookup eth0
15000: from all fwmark 0x0/0x10000 lookup legacy_system
16000: from all fwmark 0x0/0x10000 lookup legacy_network
17000: from all fwmark 0x0/0x10000 lookup local_network
19000: from all fwmark 0x65/0x1ffff lookup eth0
22000: from all fwmark 0x0/0xffff lookup eth0
23000: from all fwmark 0x0/0xffff uidrange 0-0 lookup main
32000: from all unreachable

The one I changing is the main routing table but with lowest priority. Just changing the higher priority routing table solved the problem.

Thanks again for your help.