[Solved] Wan stays up when disconnect cable from modem

Raspberry Pi 4 Model B Rev 1.2
Openwrt 21.02.3 r16554-1d4dea6d4f / LuCI openwrt-21.02 branch git-22.213.35964-87836ca

Setup with only using the one network connection and a manageable switch, so my wan and lan are both vlan’s and not physical ones.

My problem;
When I disconnect the wan cable from my modem, my router doesn’t see this and stays up. Offcourse with loss of the internet connection.

I do have a backup wwan that becomes my default wan (by vpn-policy-routing) thanks to @trendy See this threat but because my router doesn’t see the disconnect it doesn’t switch from wan to wwan,

When I manually stop the wan interface, it goes to wwan perfectly.

There is no way for the Pi to be aware that the link has gone down on your wired WAN if it is connected through a switch. There is nothing you can do about this since the Pi has no way to obtain the link-down information.

You will have to use a watchdog type script to determine when that link has gone down -- it is possible your switch can be queried about the status of that port -- check the switch documentation.

The best way to handle your situation would be to make a direct connection to the Pi -- you could do this using a USB-ethernet dongle for your WAN. This way the dongle can report directly to the Pi and you can trigger on ifup/ifdown/hotplug events.

1 Like

Thanks for your quick reply, I thought it was something like that.

I cannot use the usb dongle because of my high speed niet connection 1Gigabit. The dongle gives me a high latency.

So I’ll look into the switch documentation and else the watchdog (I think there is even een package watchman or something)

I have no vested interest in suggesting this particular adapter, but he TP-Link UE300 has been pretty well regarded in the OpenWrt + Pi4 setups because it can sustain 1Gbps and has drivers available in the OpenWrt repo. I cannot speak to latency, but certainly the overall bandwidth performance of this device is considered more that sufficient.

I have just that one. But still not so fast as the setup I have now, but thanks for the tip :wink:

Can someone help me with a watchdog script;

Something like this that starts at boot and loops


while false; do
if ping -c 1 &> /dev/null
Do nothing?
Ifdown wan 
sleep 900 && ifup wan (and if it succeeds) && sleep 10 && ifdown wwan && ifup wwan &

Not really a clu what I’m doing :wink:

But the idea is that there is a ping check on wan, if it is there, it’s ok. (Or a few pings)
If the ping is false than take the interface wan down (then my backup wwan kicks in, that allready works when I manually stop the wan interface)
After some time (say 15 minutes) ifup wan, if successful, restart wwan after 10 seconds (to reset my Wireguard vpn, otherwise it stays on my wwan, by a restart it goes back to the wan interface)
If not successful do nothing so wwan stays default.

Conceptually this is correct, but the syntax would need to be adjusted.

You might also look at mwan3 -- this is a multi-wan package that may also have some of these failover features already built-in.

I use vpn-policy-routing that does the same thing (for my purpose)

I had the same problem with mwan3. Then @trendy told me (in the other threat) that is does basically the same thing as vpn - pbr

An idea I have is to use the custom scripts in mwan3. When wan is detected as connected and switches over as primary to run a script to remove the static route for the wireguard endpoint and add it again via the wan interface.

Going to give that a try, the only thing that needs to work is that openwrt knows that wan isn't connected anymore and visa versa offcourse.

Can I simple do something with this?
It’s on all wan interfaces config page.

You can try it, but I don't think it will remove the static route.

Nope, it didn’t work :wink:

It works fine when there is a manual ifdown on wan. But when there is a disconnect (in mwan3) nothing happens. Mwan3 tells me that wan is offline and wwan is online, but there is no route.

Any idea what the cli command is to flush the default route. I assume that a ifup event on wwan makes a new one.

So flush default route on disconnect wan, then ifup wwan and flush default route on connect wan and then ifup wan.

You don't need to delete the default route and you probably won't achieve much like this.
Just to remove the route to the wireguard server is enough. Then wireguard will recreate it via the wan interface.

Ok, I’ll give that a try.

When I manually ifdown wan / ifup wan it works flawlessly, so I thought, It only does not work at disconnecting the wan cable. I noticed that 'disconnected' and 'connected' was logged.

So when I disconnected the cable, waiting for the disconnected moment and then manual 'restart' the wan interface in Luci it al worked.

So now I have this little script in place in /etc/mwan3.user. so just the ifup (restart in Luci) command


if [ "${ACTION}" = "disconnected" ] && [ "${INTERFACE}" = "wan" ] ; then
    ifup wan

I think because of the ifup, that offcourse is not working, because there is no connection, the routing goes through wwan.

maybe there is a better / cleaner way to do this, but it works. And it is not the case that my wan connection drops every 2 days. (but when it happens I'm not there offcourse) :wink:

Thanks for your help!

1 Like