Tuesday, June 29, 2010

Adding a route with android's route

Today I needed to add a route on the android shell but was greated with "Invalid Argument" failures, there is no "-h", no man page. So we will have to use the sourcecode.

First of all the code is in /system/core/toolbox/route.c
and it supports three types of argument..

  • route add default dev DEVICE
  • route add default gw IP dev DEVICE
  • route add -net IP netmask NETMASK gw IP


Shiron said...

Hello, thanks for the useful post. i would like to know if it is possible to print all the routes like "route print", and to delete the routes or it loses the routes after device resets? And it is possible to add a permanent route?

by the way, it is possible to add route with unrooted phones? i have terminal emulator, and route SOMETHING works, but i do not want to end with a fixed route..


Max Gontar said...

Thanks! It saved me a lot of time! I have to learn to look into code.

stephan.bohacek said...

For some reason, route.c does not allow routes to be deleted. So routes can only be added. ip route ... allows routes to be added, deleted, and has a nice show:

e.g., to add (must run as root):
ip route add via dev eth0

e.g., to delete (must run as root)
ip route del via dev eth0

e.g., to show
ip route show

Lucas said...

Any idea of how to make this persistent? route add -net and busybox ip route add work until I move out of my office or cycle my wifi.

Felipe said...

Try "route add -host". This works for Linux

Felipe said...

Try "route add -host". This works for persistent routes in linux releases.