Saturday, November 13, 2010

Routing : Add different subnet using ip route

i found this useful note but can't remember where.. hope this help

|xxxxxxx][===================>

Last time I tried to add a network which is outside of my subnet and I got errors something like as follows;



# ip route add default via 100.100.100.100 dev eth0


RTNETLINK answers: Network is unreachable


# route add default gw 100.100.100.100 dev eth0


RTNETLINK answers: Network is unreachable



This error just indicates that ip “100.100.100.100″ is not reachable from my PC since the PC has got one interface with ip 10.10.10.1. Even network babies know that 100.100.100.100 is not pingable from 10.10.10.1


In very rare cases I have seen some ISPs give gateway address which does not fall in the assigned subnet, so what to do in this case?!.. interestingly windows machines do not give any errors while setting this type of gateways.

So the solution is to use “onlink” option with “ip route” command




# ip route add default via 100.100.100.100 dev eth0 onlink


When you use “onlink” option it just assume that the gateway/nexthop is directly attached to the link. Done

2 comments:

Amandine said...

Thanks.
I still don't understand why it wouldn't add the route in the first place, but at least it works with "onlink".

Kawe said...

Glad it works

 Simple Python Calculator This script will allows your to calculate the integers given with the chosen operation. You can add, substract, mu...