What's new

Restart WireGuard client when fails

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

alisou

Occasional Visitor
Hello,

I'm using WireGuard client on my RT-AX88U. Sometimes when I lost Internet my WireGuard client doesn't reconnect automatically the connection.
I do it manually by accessing VPN -> VPN Client -> Wireguard and clicking on Apply.

I need your help to writing script to test connectivity under Wireguard VPN and restarting the WireGuard client if ping fails for example.
For example, i can't use ping under Wireguard VPN using the my VPN interface :
ping -I wgc1 google.com

Thank you.
 
Have you researched what is available already before you re-invent the wheel?

 
I'm testing "Wireguard Client VPN Failover Script" link. But I need to wait more than 120 seconds Wireguard to be restarted.
I need to reduce this time to 10 seconds. Check connectivity every 10 seconds.
 
I'm testing "Wireguard Client VPN Failover Script" link. But I need to wait more than 120 seconds Wireguard to be restarted.
I need to reduce this time to 10 seconds. Check connectivity every 10 seconds.
The script is probably based on crontab to run the check script every 2 min. The lowest time resolution for crontab is 1min so every 10s is not going to work.
Or it uses Wireguard latest-handshake timer that should reset every 2-3 min.

You may need to write your own script that runs continously and uses sleep 10 between checks.
But if it starts once and runs continuously, who checks the the check-script? You may need to write a check-script checker.

I wrote the attached script a long time ago when we used pre-compiled entware kernel modules and script files to make Wireguard run on our routers, so it won't work for you, but perhaps you can use parts of it to make your own?
 

Attachments

  • wg-watchdog.txt
    2.5 KB · Views: 16
For example, i can't use ping under Wireguard VPN using the my VPN interface :
ping -I wgc1 google.com
Reverse path filtering is blocking this from working. Try:
Code:
echo 2 > /proc/sys/net/ipv4/conf/wgc1/rp_filter
Then it should work. This sets rp_filter for wgc1 to loose instead of strict.
 

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top