OpenVPN reconnection after an IP address change in wan


I am new here in the forum, but not in the IT world. I use the OpenWRT for awhile already but from some weeks now I´ve been facing issues since my ISP change his policies on IP address distribution over PPPoE. In the past they use to keep the same IP address for days or even weeks and this has been work fine. Now they are changing the IP address frantically, each 10 or 15 minutes... sometimes less, sometimes took 12 hours... Absolutelly random...

Everytime the IP address changes the OpenVPN loses connection to the server and I need to restart its interface (tun0).

I read some threads from colleagues with the same problem, From one of this threads I got an workaround with Watchcat by reatrting the tun0 with ping, What happens is the interface is restarting too frequently (each 4 or 5 minutes), even when the IP Address on wan has not change. I did several tests with several settings on the Ping periods and I could not find a perfect setting. The "optimal" setting, lets say, I am using now, is that who gave me the more stable working condition.

I´ve been thinking if is it possible to add some rule on the Watchcat to restart the tun0 in case of IP Address change in the wan or to write a script or similar to force a restart on the tun0 when there is an IP adress change on wan.

Can anyone suugest me some solution?

I am using OpenWRT 22.03 and my router is a Xiaomi RedMI 2100.

Best regards.


It is best to restart the service on an upstream network event:

You can also try to solve the issue by using PBR:

Set up routing rules to use a separate table for all traffic except the VPN endpoint.


Thank you... I did exactly as show here:

and it worked as I wanted...

I just need to install Hotplug extra package...

Best regards.


1 Like

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