Script to make WAN go down when 4G tethering is and visa versa

I'm using a WRT3200ACM with OpenWrt SNAPSHOT r16798-8cc4e87a2f

I sometimes need do disconnect my ISP modem, and in this cases I connect my iPhone on tethering, then stop my normal wan and restart vpn-policy-routing and my firewall manually.

I'm looking for a script (in hotplug.d maybe?) That makes the following automatic.

When I plugin my tethering phone, stop wan and restart firewall and vpn-policy-routing
(or stop vpn and stop vpn-policy-routing)
When I disconnect my tethering phone start wan and restart firewall and vpn-policy-routing
(or start vpn and start vpn-policy-routing)
(this way I don't need to login on my router and someone else can do this, without the need of router acces)

When I connect my phone, the tetheringwan is up instant and goes down when disconnecting.

The script below is offcourse not working, I'm a noob in scripting, but maybe someone knows what to put in the script and where to put it in hotplug.d somewhere.

#!/bin/sh

/sbin/ifstatus TETHERINGWAN | grep '"up": true,' ; echo $? # 0 = true 1 = false

if
	/bin/true
then
		/sbin/ifdown wan
		sleep 5 && /etc/init.d/vpn-policy-routing restart
else
		/sbin/ifup wan 
		sleep 5 && /etc/init.d/vpn-policy-routing restart
fi
exit 0

looked at the mwan3 package ?

2 Likes

That is an option to, but the phone is not always connected. I did look at it a few days ago, seems a bit challenging to config.
In combination with openvpn.

and how is that an issue ?

Uuh I don’t know now that you ask. I think I just made that up for myself. I’ll look into it.

1 Like

Ok, I installed mwan3 again, and poked around in it. But I'm a bit lost. Maybe I'm even lost in a very big forrest.. :wink:

I've got wan and tetheringwan as mwan interfaces;

Do I set the metric of my tetheringwan higher, so when it comes up, it is the main route?

After that you have members / policies / rules, somehow I understand what this is, but no idea how to config this at the moment.

I think there is a steep learling curve coming up...

Have you already found

1 Like

I think mwan3 is overkill for what I need. Because mwan3 is not working nicely with vpn-policy-routing and openvpn.

Or is there a simple config possible with mwan3 that can do;
-Connect tethering phone -> tetheringwan up -> wan down -> stop vpn-policy-routing
-Disconnect tethering phone -> tetheringwan down -> wan up ->start vpn-policy-routing

If you want to prefer tethering when it is available, then increase metric on the WAN:
https://openwrt.org/docs/guide-user/services/vpn/wireguard/extras#dynamic_connection

2 Likes

It works :wink:

Used mwan3 and metric of my cellphone is higher. So if I connect my phone it routes everything over my cellphone now.

I added some scripting in /etc/mwan3.user to stop openvpn and vpn-policy-routing and start it again when I disconnect my phone and everthing is routed through my " normal" lan.

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