Default gateway disappears after some time

Hello,

After some time using a customized OpenWRT OS for a Dragino Yun, the default gateways that are passed by DHCP disappear and I loose internet access. Why is this happening? Here are some outputs of the system:

ping 8.8.8.8 -I wlan0 and ping 8.8.8.8 -I eth0

PING 8.8.8.8 (8.8.8.8): 56 data bytes
ping: sendto: Network is unreachable

No internet access, but the gateways are still reachable by the device:
ping 192.168.35.1

PING 192.168.35.1 (192.168.35.1): 56 data bytes
64 bytes from 192.168.35.1: seq=0 ttl=64 time=0.618 ms

ping 192.168.43.1

PING 192.168.43.1 (192.168.43.1): 56 data bytes
64 bytes from 192.168.43.1: seq=0 ttl=64 time=7.989 ms

Before loosing internet access:
route -n

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    5      0        0 wlan0
0.0.0.0         192.168.35.1    0.0.0.0         UG    10     0        0 eth0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     10     0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     5      0        0 wlan0

After loosing internet access:
route -n

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     10     0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     5      0        0 wlan0

ifconfig (after loosing internet access)

eth0      Link encap:Ethernet  HWaddr A8:40:41:17:45:A1  
          inet addr:192.168.35.67  Bcast:192.168.35.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4452 errors:0 dropped:1 overruns:0 frame:0
          TX packets:3025 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:613802 (599.4 KiB)  TX bytes:585775 (572.0 KiB)
          Interrupt:5 

eth0:9    Link encap:Ethernet  HWaddr A8:40:41:17:45:A1  
          inet addr:172.31.255.254  Bcast:172.31.255.255  Mask:255.255.255.252
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:5 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1456 (1.4 KiB)  TX bytes:1456 (1.4 KiB)

wlan0     Link encap:Ethernet  HWaddr A8:40:41:17:45:9E  
          inet addr:192.168.43.29  Bcast:192.168.43.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:245 errors:0 dropped:2 overruns:0 frame:0
          TX packets:245 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:25423 (24.8 KiB)  TX bytes:30746 (30.0 KiB)

ifconfig (Before losing internet connection, looks the same as after loosing iaccess)

eth0      Link encap:Ethernet  HWaddr A8:40:41:17:45:A1  
          inet addr:192.168.35.67  Bcast:192.168.35.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:89 errors:0 dropped:0 overruns:0 frame:0
          TX packets:71 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:14731 (14.3 KiB)  TX bytes:11424 (11.1 KiB)
          Interrupt:5 

eth0:9    Link encap:Ethernet  HWaddr A8:40:41:17:45:A1  
          inet addr:172.31.255.254  Bcast:172.31.255.255  Mask:255.255.255.252
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:5 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:16 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:1621 (1.5 KiB)  TX bytes:1621 (1.5 KiB)

wlan0     Link encap:Ethernet  HWaddr A8:40:41:17:45:9E  
          inet addr:192.168.43.29  Bcast:192.168.43.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:25 errors:0 dropped:0 overruns:0 frame:0
          TX packets:26 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:2778 (2.7 KiB)  TX bytes:3753 (3.6 KiB)

Before and After loosing internet access:
netstat -lunp

Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 0.0.0.0:53              0.0.0.0:*                           1473/dnsmasq
netstat: /proc/net/udp6: No such file or directory

cat /etc/config/dhcp

config dnsmasq
	option domainneeded	1
	option boguspriv	1
	option filterwin2k	0  # enable for dial on demand
	option localise_queries	1
	option rebind_protection 1  # disable if upstream must serve RFC1918 addresses
	option rebind_localhost 1  # enable for RBL checking and similar services
	#list rebind_domain example.lan  # whitelist RFC1918 responses for domains
	option local	'/lan/'
	option domain	'lan'
	option expandhosts	1
	option nonegcache	0
	option authoritative	1
	option readethers	1
	option leasefile	'/tmp/dhcp.leases'
	option resolvfile	'/tmp/resolv.conf.auto'
	#list server		'/mycompany.local/1.2.3.4'
	#option nonwildcard	1
	#list interface		br-lan
	list notinterface	wan
	list notinterface	wwan
	#list bogusnxdomain     '64.94.110.11'

config dhcp lan
	option interface	lan
	option start 	100
	option limit	150
	option leasetime	12h

config dhcp wan
	option interface	wan
	option ignore	1

config dhcp wwan
	option interface	wwan
	option ignore 	1

cat /etc/config/network


config interface 'loopback'
	option ifname 'lo'
	option proto 'static'
	option ipaddr '127.0.0.1'
	option netmask '255.0.0.0'

config interface 'lan'
	option proto 'static'
	option ipaddr '192.168.240.1'
	option netmask '255.255.255.0'
	option hostname 'ElIoT-Dragino-17459e'

config interface 'wan'
	option ifname 'eth0'
	option proto 'dhcp'
	option metric '10'
	option hostname 'ElIoT-Dragino-17459e'

config interface 'wwan'
	option ifname 'wlan0'
	option proto 'dhcp'
	option metric '5'

ps

  644 root      1532 S    /sbin/syslogd -C16
  646 root      1516 S    /sbin/klogd
  648 root       860 S    /sbin/hotplug2 --override --persistent --set-rules-file /etc/hotplug2.rules --set-coldplug-cmd /sbin/udevtrigger --max-children 1
  656 root       876 S    /sbin/ubusd
  666 root      1484 S    /sbin/netifd
  766 root      1532 S    udhcpc -p /var/run/udhcpc-eth0.pid -s /lib/netifd/dhcp.script -f -t 0 -i eth0 -H ElIoT-Dragino-17459e -C
 1221 root      1620 S    wpa_supplicant -B -P /var/run/wifi-wlan0.pid -D nl80211 -i wlan0 -c /var/run/wpa_supplicant-wlan0.conf
 1360 root      1524 S    /sbin/watchdog -t 5 /dev/watchdog
 1373 root      1532 S    udhcpc -p /var/run/udhcpc-wlan0.pid -s /lib/netifd/dhcp.script -f -t 0 -i wlan0 -C
 1430 root      1152 S    /usr/sbin/dropbear -P /var/run/dropbear.1.pid -p 22
 1473 nobody     952 S    /usr/sbin/dnsmasq -C /var/etc/dnsmasq.conf
 1486 root      1524 S    /usr/sbin/ntpd -n -p 0.openwrt.pool.ntp.org -p 1.openwrt.pool.ntp.org -p 2.openwrt.pool.ntp.org -p 3.openwrt.pool.ntp.org
 1519 root      1216 R    /usr/sbin/dropbear -P /var/run/dropbear.1.pid -p 22

cat /var/etc/dnsmasq.conf

# auto-generated config file from /etc/config/dhcp
conf-file=/etc/dnsmasq.conf
dhcp-authoritative
domain-needed
localise-queries
read-ethers
bogus-priv
expand-hosts
domain=lan
server=/lan/
except-interface=eth0
except-interface=wlan0
dhcp-leasefile=/tmp/dhcp.leases
resolv-file=/tmp/resolv.conf.auto
addn-hosts=/tmp/hosts
stop-dns-rebind
rebind-localhost-ok




no-dhcp-interface=eth0
no-dhcp-interface=wlan0


address=/ElIoT-Dragino-17459e.lan/192.168.240.1
ptr-record=1.240.168.192.in-addr.arpa,ElIoT-Dragino-17459e.lan

logread (after losing connection)

Jan  1 00:00:37 ElIoT-Dragino-17459e daemon.notice netifd: Interface 'loopback' is now up
Jan  1 00:00:38 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): udhcpc (v1.19.4) started
Jan  1 00:00:38 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Sending discover...
Jan  1 00:00:39 ElIoT-Dragino-17459e kern.info kernel: [   39.230000] eth0: link up (1000Mbps/Full duplex)
Jan  1 00:00:41 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Sending discover...
Jan  1 00:00:41 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Sending select for 192.168.35.67...
Jan  1 00:00:41 ElIoT-Dragino-17459e user.info sysinit: sh: auto: bad number
Jan  1 00:00:42 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Lease of 192.168.35.67 obtained, lease time 3600
Jan  1 00:00:42 ElIoT-Dragino-17459e daemon.notice netifd: Interface 'wan' is now up
Jan  1 00:00:43 ElIoT-Dragino-17459e user.notice firewall: Reloading firewall due to ifup of wan (eth0)
Jan  1 00:00:45 ElIoT-Dragino-17459e kern.info kernel: [   45.590000] wlan0: authenticate with 90:17:c8:18:05:59
Jan  1 00:00:45 ElIoT-Dragino-17459e kern.info kernel: [   45.600000] wlan0: send auth to 90:17:c8:18:05:59 (try 1/3)
Jan  1 00:00:45 ElIoT-Dragino-17459e kern.info kernel: [   45.610000] wlan0: authenticated
Jan  1 00:00:45 ElIoT-Dragino-17459e kern.info kernel: [   45.630000] wlan0: associate with 90:17:c8:18:05:59 (try 1/3)
Jan  1 00:00:45 ElIoT-Dragino-17459e kern.info kernel: [   45.650000] wlan0: RX AssocResp from 90:17:c8:18:05:59 (capab=0x1631 status=0 aid=3)
Jan  1 00:00:45 ElIoT-Dragino-17459e kern.info kernel: [   45.650000] wlan0: associated
Jan  1 00:00:46 ElIoT-Dragino-17459e kern.warn kernel: [   46.440000] EXT2-fs (sda2): warning: mounting ext3 filesystem as ext2
Jan  1 00:00:46 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): udhcpc (v1.19.4) started
Jan  1 00:00:46 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Sending discover...
Jan  1 00:00:48 ElIoT-Dragino-17459e authpriv.info dropbear[1430]: Running in background
Jan  1 00:00:49 ElIoT-Dragino-17459e user.notice dnsmasq: DNS rebinding protection is active, will discard upstream RFC1918 responses!
Jan  1 00:00:49 ElIoT-Dragino-17459e user.notice dnsmasq: Allowing 127.0.0.0/8 responses
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: started, version 2.66 cachesize 150
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP no-DHCPv6 no-Lua TFTP no-conntrack no-ipset no-auth
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: using local addresses only for domain lan
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: reading /tmp/resolv.conf.auto
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: using nameserver 192.168.35.1#53
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: using local addresses only for domain lan
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: read /etc/hosts - 1 addresses
Jan  1 00:00:49 ElIoT-Dragino-17459e user.info sysinit: setting up led wlan
Jan  1 00:00:49 ElIoT-Dragino-17459e user.info sysinit: uci: Entry not found
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Sending discover...
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Sending select for 192.168.43.29...
Jan  1 00:00:49 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Lease of 192.168.43.29 obtained, lease time 3600
Jan  1 00:00:50 ElIoT-Dragino-17459e daemon.notice netifd: Interface 'wwan' is now up
Jan  1 00:00:50 ElIoT-Dragino-17459e user.notice firewall: Reloading firewall due to ifup of wwan (wlan0)
Feb 16 22:51:14 ElIoT-Dragino-17459e authpriv.info dropbear[1519]: Child connection from 192.168.35.1:37240
Feb 16 22:52:25 ElIoT-Dragino-17459e authpriv.notice dropbear[1519]: Password auth succeeded for 'root' from 192.168.35.1:37240
Feb 16 22:53:27 ElIoT-Dragino-17459e authpriv.info dropbear[1529]: Child connection from 192.168.35.1:37242
Feb 16 22:53:31 ElIoT-Dragino-17459e authpriv.warn dropbear[1529]: Bad password attempt for 'root' from 192.168.35.1:37242
Feb 16 22:53:33 ElIoT-Dragino-17459e authpriv.notice dropbear[1529]: Password auth succeeded for 'root' from 192.168.35.1:37242
Feb 16 22:53:35 ElIoT-Dragino-17459e authpriv.info dropbear[1529]: Exit (root): Disconnect received
Feb 16 22:59:07 ElIoT-Dragino-17459e kern.info kernel: [  532.480000] Custom GPIO-based SPI driver version 0.1
Feb 16 23:20:57 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Sending renew...
Feb 16 23:20:58 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Lease of 192.168.35.67 obtained, lease time 3600
Feb 16 23:20:58 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: reading /tmp/resolv.conf.auto
Feb 16 23:20:58 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: using nameserver 192.168.43.1#53
Feb 16 23:20:58 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: using nameserver 192.168.35.1#53
Feb 16 23:20:58 ElIoT-Dragino-17459e daemon.info dnsmasq[1473]: using local addresses only for domain lan
Feb 16 23:21:04 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Sending renew...
Feb 16 23:21:04 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Lease of 192.168.43.29 obtained, lease time 3600
Feb 16 23:50:58 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Sending renew...
Feb 16 23:50:59 ElIoT-Dragino-17459e daemon.notice netifd: wan (766): Lease of 192.168.35.67 obtained, lease time 3600
Feb 16 23:51:05 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Sending renew...
Feb 16 23:51:05 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1373): Lease of 192.168.43.29 obtained, lease time 3600

Where did you get the customized firmware?

I compiled it myself following dragino's wiki

Looks like Dragino bases it on OpenWrt for their devices.

However, it's not official OpenWrt, so you should contact them.

Ok, but.. Any ideas where I could be looking ? Maybe some tool I can install to monitor network changes ?

You might search the OpenWrt documentation -

I monitored the time I lost connection via ping (30 minutes after reboot), and in the syslog it maches the time I got:

Feb 17 00:53:55 ElIoT-Dragino-17459e daemon.notice netifd: wan (781): Sending renew...
Feb 17 00:53:56 ElIoT-Dragino-17459e daemon.notice netifd: wan (781): Lease of 192.168.35.67 obtained, lease time 3600
Feb 17 00:54:03 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1372): Sending renew...
Feb 17 00:54:03 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1372): Lease of 192.168.43.29 obtained, lease time 3600

I noticed that there are some errors with the /lib/netifd/dhcp.script

root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-eth0.pid -s /lib/netifd/dhcp.script -t 0 -i eth0 -H ElIoT-Dragino-17459e
udhcpc (v1.19.4) started
Command failed: Not found
Sending discover...
Sending select for 192.168.35.67...
Lease of 192.168.35.67 obtained, lease time 3600
Command failed: Not found

However, by removing /lib/netifd/dhcp.script, I get:

root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-eth0.pid -t 0 -i eth0 -H ElIoT-Dragino-17459e
udhcpc (v1.19.4) started
Sending discover...
Sending select for 192.168.35.67...
Lease of 192.168.35.67 obtained, lease time 3600
udhcpc: ifconfig eth0 192.168.35.67 netmask 255.255.255.0 broadcast 192.168.35.255
udhcpc: setting default routers: 192.168.35.1

I will try launching udhcpd without the script and I will report back.

Ok so after removing the line:

-s /lib/netifd/dhcp.script \

from the file:

openwrt/package/netifd/files/lib/netifd/proto/dhcp.sh

or

/lib/netifd/proto/dhcp.sh

The syslog looks different, however, now I lose just one gateway:

Jan  1 00:30:42 ElIoT-Dragino-17459e daemon.notice netifd: wan (761): Sending renew...
Jan  1 00:30:43 ElIoT-Dragino-17459e daemon.notice netifd: wan (761): Lease of 192.168.35.67 obtained, lease time 3600
Jan  1 00:30:43 ElIoT-Dragino-17459e daemon.notice netifd: wan (761): udhcpc: ifconfig eth0 192.168.35.67 netmask 255.255.255.0 broadcast 192.168.35.255
Jan  1 00:30:43 ElIoT-Dragino-17459e daemon.notice netifd: wan (761): udhcpc: setting default routers: 192.168.35.1
Jan  1 00:30:48 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1284): Sending renew...
Jan  1 00:30:48 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1284): Lease of 192.168.43.29 obtained, lease time 3600
Jan  1 00:30:48 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1284): udhcpc: ifconfig wlan0 192.168.43.29 netmask 255.255.255.0 broadcast 192.168.43.255
Jan  1 00:30:48 ElIoT-Dragino-17459e daemon.notice netifd: wwan (1284): udhcpc: setting default routers: 192.168.43.1
root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    0      0        0 wlan0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0

I am missing the 192.168.35.1 gateway on eth0..

And for some reason, ntp is not updating the time.

Ok so I noticed that when leasing a DHCP on one interface, I lose the gateway of the other interface. Example:

root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    0      0        0 wlan0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-eth0.pid -t 0 -i eth0 -H ElIoT-Dragino-17459e -C
udhcpc (v1.19.4) started
Sending discover...
Sending select for 192.168.35.67...
Lease of 192.168.35.67 obtained, lease time 3600
udhcpc: ifconfig eth0 192.168.35.67 netmask 255.255.255.0 broadcast 192.168.35.255
udhcpc: setting default routers: 192.168.35.1
root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.35.1    0.0.0.0         UG    0      0        0 eth0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-eth0.pid -t 0 -i eth0 -H ElIoT-Dragino-17459e -C
udhcpc (v1.19.4) started
Sending discover...
Sending select for 192.168.35.67...
Lease of 192.168.35.67 obtained, lease time 3600
udhcpc: ifconfig eth0 192.168.35.67 netmask 255.255.255.0 broadcast 192.168.35.255
udhcpc: setting default routers: 192.168.35.1
route: SIOCADDRT: File exists
root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.35.1    0.0.0.0         UG    0      0        0 eth0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-wlan0.pid -t 0 -i wlan0 -C
udhcpc (v1.19.4) started
Sending discover...
Sending select for 192.168.43.29...
Lease of 192.168.43.29 obtained, lease time 3600
udhcpc: ifconfig wlan0 192.168.43.29 netmask 255.255.255.0 broadcast 192.168.43.255
udhcpc: setting default routers: 192.168.43.1
root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    0      0        0 wlan0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-wlan0.pid -t 0 -i wlan0 -C
udhcpc (v1.19.4) started
Sending discover...
Sending select for 192.168.43.29...
Lease of 192.168.43.29 obtained, lease time 3600
udhcpc: ifconfig wlan0 192.168.43.29 netmask 255.255.255.0 broadcast 192.168.43.255
udhcpc: setting default routers: 192.168.43.1
root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    0      0        0 wlan0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-eth0.pid -t 0 -i eth0 -H ElIoT-Dragino-17459e -C
udhcpc (v1.19.4) started
Sending discover...
Sending select for 192.168.35.67...
Lease of 192.168.35.67 obtained, lease time 3600
udhcpc: ifconfig eth0 192.168.35.67 netmask 255.255.255.0 broadcast 192.168.35.255
udhcpc: setting default routers: 192.168.35.1
root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.35.1    0.0.0.0         UG    0      0        0 eth0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0
root@ElIoT-Dragino-17459e:~# udhcpc -p /var/run/udhcpc-wlan0.pid -t 0 -i wlan0 -C
udhcpc (v1.19.4) started
Sending discover...
Sending select for 192.168.43.29...
Lease of 192.168.43.29 obtained, lease time 3600
udhcpc: ifconfig wlan0 192.168.43.29 netmask 255.255.255.0 broadcast 192.168.43.255
udhcpc: setting default routers: 192.168.43.1
root@ElIoT-Dragino-17459e:~# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.43.1    0.0.0.0         UG    0      0        0 wlan0
172.31.255.252  0.0.0.0         255.255.255.252 U     0      0        0 eth0
192.168.35.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
192.168.43.0    0.0.0.0         255.255.255.0   U     0      0        0 wlan0

¿Any Ideas?

The default script for udhcpc is:

cat /usr/share/udhcpc/default.script

#!/bin/sh
[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1

set_classless_routes() {
	local max=128
	local type
	while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
		[ ${1##*/} -eq 32 ] && type=host || type=net
		echo "udhcpc: adding route for $type $1 via $2"
		route add -$type "$1" gw "$2" dev "$interface"
		max=$(($max-1))
		shift 2
	done
}

setup_interface() {
	echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
	ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}

	[ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && {
		echo "udhcpc: setting default routers: $router"

		local valid_gw=""
		for i in $router ; do
			route add default gw $i dev $interface
			valid_gw="${valid_gw:+$valid_gw|}$i"
		done
		
		eval $(route -n | awk '
			/^0.0.0.0\W{9}('$valid_gw')\W/ {next}
			/^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
		')
	}

	# CIDR STATIC ROUTES (rfc3442)
	[ -n "$staticroutes" ] && set_classless_routes $staticroutes
	[ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
}


applied=
case "$1" in
	deconfig)
		ifconfig "$interface" 0.0.0.0
	;;
	renew)
		setup_interface update
	;;
	bound)
		setup_interface ifup
	;;
esac

# user rules
[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user

exit 0

Commenting, these lines prevent the deletion of the other gateways:

		eval $(route -n | awk '
			/^0.0.0.0\W{9}('$valid_gw')\W/ {next}
			/^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
		')

I think these lines have to be tweaked so that it deletes the gateway that corresponds to the same interface.

Ordinarily there is one WAN connection and one default gateway. Juggling two connections requires helper scripts like mwan3.

When DHCP is renewed, by default the DHCP client process adds the advertised gateway IP, which is likely to mess up a multiple WAN system.

2 Likes

Thanks, sounds right, well then I suppose this issue is solved by:

Normally there should not be an issue with dual wan connections, since you have correctly assigned metrics for wan and wwan. In this case both default routes should be available in the routing table and the one with the lower metric would be preferred. However it is not used as you can see:

In both cases it is 0, so it is not installed properly.

1 Like

The default gateway is working, but yes the metric is 0. So changing this line in /usr/share/udhcpc/default.script:

route add default gw $i dev $interface

To say:

route add default gw $i dev $interface metric $metric

¿Would solve the issue?.

¿Where can I read the metric of an interface in OpenWRT? I guess I could from /etc/config/network, but I am no expert in grepping. ¿Somewhere else? ¿uci show network.wan.metric?¿Maybe somewhere in /proc/net/?

And an other thing I would like to add, the default script: /usr/share/udhcpc/default.script (openwrt/package/netifd/files/usr/share/udhcpc/default.script) does not assign DNS servers. So I added to setup_interface():

# Only replace resolv.conf if we have at least one DNS server
  RESOLV_CONF="/tmp/resolv.conf"                           
  if [ -n "$dns" ]                                                 
  then                                                             
          echo -n > $RESOLV_CONF                                   
          [ -n "$domain" ] && echo domain $domain >> $RESOLV_CONF  
          for i in $dns                                            
          do                                                       
                  echo adding dns $i                          
                  echo nameserver "8.8.8.8" >> $RESOLV_CONF       
                  echo nameserver "8.8.4.4" >> $RESOLV_CONF            
                  echo nameserver "1.1.1.1" >> $RESOLV_CONF       
                  echo nameserver "1.0.0.1" >> $RESOLV_CONF           
                  echo nameserver $i >> $RESOLV_CONF           
                  echo nameserver "9.9.9.9" >> $RESOLV_CONF                   
          done                                                     
  fi

OpenWrt does not need any customizations to apply a route with the interface metric. Since you are using a customized version though, it is unknown what has been changed and you are not getting both default routes with different metrics. And I am referring to the metrics in interface configuration you posted earlier.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.