OpenWrt Forum Archive

Topic: No default route on WAN interface

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

Hi all,

I finally bit the bullet today and upgraded from white russian to kamikaze (8.09.1 + x-wrt). It went pretty smoothly with one notable exception. I can not, for the life of me, get it to add a default route on the WAN interface - with obvious negative results. When I manually did "route add default gw `uci get network.wan.gateway`", everything became happy. I've been digging through the scripts and can't even find the code that's supposed to add the default route - I wondered if udhcpc is supposed to do it implicitly but wasn't able to establish either way.

I ended up creating a static route entry that matched my default and with that I can at least get the system to boot to full functionality (as long as my cable company doesn't change what my gateway is) but this clearly can't be the preferred way of doing this.

Any clarifications would be much appreciated!

Thanks,

--phil

Are you using static or DHCP on the WAN interface? Have a look in /tmp and see if you have two files resolv.conf and resolv.conf.auto and what their contents are. resolv.conf should be a sym link to resolv.conf.auto.

rick

Show us the output from 'uci show network.wan'.

I'm using dhcp on the WAN interface and it's picking up the address, dns servers and gateway address fine - as shown in the uci output.

network.wan=interface
network.wan.ifname=eth0.1
network.wan.proto=dhcp
network.wan.macaddr=
network.wan.ip6addr=
network.wan.gateway=98.234.152.1
network.wan.ip6gw=
network.wan.dns=68.87.76.182 68.87.78.134
network.wan.defaultroute=1
network.wan.ipaddr=98.234.156.166
network.wan.netmask=255.255.248.0
network.wan.target=default

However, I see my /tmp/resolv.conf is a real file that says 'namesever 127.0.0.1' while resolv.conf.auto is the real data from my ISP. But tmp is a tmpfs and this is how it comes up after a reboot.

Have a look at ticket https://dev.openwrt.org/ticket/5637

The fix may be to replace the line in dnsmasq start()
    rm -f /tmp/resolv.conf
with the line
    echo -n "" > /tmp/resolv.conf

This will result in one file and a sym link to it, and the file contents will be removed during a start.

The above fix fails if you run "/etc/init.d/dnsmasq restart" as it wipes out the information put in /tmp/resolv.conf by udhcpc at boot. udhcpc only runs if you do an "ifup wan". However if you do nothing then every time you restart dnsmasq it will re-enter all of its nameservers into the resolv.conf file.

A better fix is as follows
/usr/sbin/dnsmasq $args --log-queries --log-facility=/tmp/dns.log && {
#               rm -f /tmp/resolv.conf
                DNS_SERVERS="$DNS_SERVERS 127.0.0.1"
                for DNS_SERVER in $DNS_SERVERS ; do
                        grep -q "nameserver $DNS_SERVER" /tmp/resolv.conf \
                        || echo "nameserver $DNS_SERVER" >> /tmp/resolv.conf
                done
        }

The grep does not enter the nameserver entry if it is already there

Hello,

I want to revive this thread because I have the same original problem, "no default route." Unfortunately this thread switched from the "no default route" issue to the "resolv.conf" issue without solving the original problem.

I just flashed my old WRT54GL router with the latest x-wrt, 8.09.2. I configured my wan interface for DHCP, and my LAN interface static:

# uci show network.wan
network.wan=interface
network.wan.ifname=eth0.1
network.wan.proto=dhcp
network.wan.macaddr=
network.wan.ip6addr=
network.wan.ip6gw=
network.wan.gateway=192.168.1.1
network.wan.dns=192.168.1.2
network.wan.netmask=255.255.255.0
network.wan.ipaddr=192.168.1.150

# uci show network.lan
network.lan=interface
network.lan.type=bridge
network.lan.ifname=eth0.0
network.lan.proto=static
network.lan.netmask=255.255.255.0
network.lan.macaddr=
network.lan.ip6addr=
network.lan.gateway=
network.lan.ip6gw=
network.lan.dns= 192.168.1.2
network.lan.ipaddr=192.168.0.1

After a reboot these are the only route entries:

# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0.1
192.168.0.0     *               255.255.255.0   U     0      0        0 br-lan

So, no default route, I can't access the Internet from within the LAN.
But if I manually do

# route add default gw 192.168.1.1
# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0.1
192.168.0.0     *               255.255.255.0   U     0      0        0 br-lan
default         192.168.1.1     0.0.0.0         UG    0      0        0 eth0.1

then everything is fine, no routing problems. why is this?
How can I get the default route to be set up automatically after reboot?

Thanks

Remove the gateway option from the wan interface config, it prevents uhcpc from adding a default route.

Thanks. it works. But, why was this entry there in the first place? I configured the router via the Web interface and only logged in to capture the information I shared in this list. I then realized the lack of a default route and I added it manually.

Anyway, thanks for the tip. Now on to my next problem ... no wireless :-(

I ran into the same issue today with X-Wrt r4838 on OpenWrt Kamikaze 8.09. I suspect the web interface puts the gateway value into the config.

X-Wrt. LOL...

The discussion might have continued from here.