Wireguard Connection Monitoring Script For Dynamic IP

To ensure healthy bi-directional connection, Wireguard comes with “persistent keep alive” function for peers to ping the server regularly such that the server can reach the peer sitting behind a firewall. However, problems arise when the server has a dynamic IP, and when the server IP changes the peer does not know to update the old IP by resolving the server domain name again. There needs a way for the peer to monitor the connection and update the resolved server IP as needed (not a built-in function currently in the official Wireguard release). The following Wireguard Connection Monitoring Script can be run as a scheduled cron job in Linux/Ubuntu environment to achieve the desired effect.

The script works by pinging the server’s internal address to determine if the connection is still valid. If the ping fails 3 times, the connection is considered failed and Wiregaurd interface will be restarted.

TLDR: This script automatically forces the peer client to restart so servers with dynamic IP can be updated as appropriate.

PS. For windows client, you can run scheduled batch script to do the same thing.

Continue Reading

How to Setup Wireguard VPN Server On Windows

wireguard server for windows tutorial

This tutorial goes through the process of setting up a Wireguard server on Windows. Most Wireguard tutorials on the internet only give you the choice of hosting a server in a Linux environment. However, it is very possible to setup a windows server.

After searching for a tutorial to no avail, I spent a couple days to figure out the best way to do it and how to automate the process. Ideally you would still want to run it in an Linux environment, but if you have a use case for a windows server like me, you would appreciate just how flexible Wireguard is!


  • Latest Wireguard Windows Client installed (Download here from official site)
  • Setup firewall rules (just as you would for a Linux server setup: open and forward ports 51820, configure ddns etc)

Using Wireguard on Windows as server is not officially supported. Use at your own risk.

Continue Reading