OpenWrt Forum Archive

Topic: DHCP fails to set default route

The content of this topic has been archived on 7 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hi all,

I'm unable to get OpenWRT to set up my Internet connection properly, as it's unable to set up the default route, and I have to do it manually every time my IP changes.

The problem is that for some reason the default gateway my ISP uses is on a different subnet, so when the DHCP client tries to set it it comes up with SIOCADDRT, Network is unreachable.

I worked around this on my Gentoo box by editing the DHCP scripts and adding a static route to the gateway's IP before setting it as the default gateway, i.e. what I need on OpenWRT is: route add -host <gateway IP> dev eth0.1

I'm just not sure where to add this.  Given that at least two Australian DSL ISPs do this, it might also be worth adding it into OpenWRT permanently, so it will work out of the box in Australia.

Any ideas?

A workaround I did to solve this.
Edit /usr/share/udhcpc/default.script
change line : route add default gw $i dev $interface
to : route add default dev $interface

It is very common for ISPs worldwide to provide IP with mask 255.255.255.255 (which is a single host). This makes any other IP address not member of the same subnet, so you cannot add a gateway by the IP because there is no valid connected network to reach that gateway.

I have to have a play around with this, but I think your suggestion will only work if the modem has been configured to route all traffic on its ethernet port regardless of the gateway.  I don't think mine is set up to do this, but I think I can change the script to explicitly tell the kernel how to reach the gateway, i.e. by adding this command to the script just above your suggested change:

route add -host $i dev $interface

I haven't had a chance to test this yet, but it should mean when the normal command is run the gateway is available and will be set up correctly.

If you are single homed internet user this setup will work fine with you. Your default gateway would be either way the WAN port. But if your provider (like mine) leases IPs with 255.255.255.255 netmask, the gateway cannot be applied because the IP of the gateway is not directly connected to the router. So you just route packets directly to the interface and this option is accepted.

a small patch:

*** default.script_orig 2011-02-20 22:21:11.000000000 +0200
--- default.script      2011-02-20 22:25:01.000000000 +0200
***************
*** 53,58 ****
--- 53,65 ----
        }
 
        [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && [ "$router" != "$old_router" ] && {
+               #Route bug-fix
+               [ -n "${subnet:-255.255.255.0}" ] && [ "${subnet:-255.255.255.0}" == "255.255.255.255" ] && {
+                       echo "-=Fixing route to different subnet=-"
+                       echo "udhcpc: route add -net $router netmask ${subnet:-255.255.255.0} $interface"
+                       route add -net $router netmask ${subnet:-255.255.255.0} $interface
+                       echo "-=End Fix=-"
+               }
 
                echo "udhcpc: setting default routers: $router"

(Last edited by mclooker on 20 Feb 2011, 21:31)

The discussion might have continued from here.