This script addresses an issue where WireGuard peers fail to re-resolve the domain of their endpoint when the IP address changes.
This script was created to address this limitation by:
- Checking the last handshake time: If the last handshake is older than a specified threshold (150 seconds in this case), the script triggers a re-resolution of the domain.
- Re-resolving the domain: It extracts the domain and port from the WireGuard peer configuration and forces WireGuard to update the peer's endpoint with the new resolved IP address.
This ensures that the WireGuard connection remains functional even if the endpoint's IP address changes.
The wireguard_watchdog script that comes with OpenWrt is incompatible with GL.iNet firmware. Specifically, GL.iNet firmware has certain customizations that prevent the wireguard_watchdog
from functioning as expected. To solve this problem, I created this script to provide similar functionality in a way that works reliably on GL.iNet devices, ensuring the WireGuard connection stays active by automatically updating the endpoint whenever the handshake is stale.
This script is intended to be used on OpenWrt-based systems, especially GL.iNet devices, and can be scheduled to run periodically (via cron or the LuCi System -> Scheduled Tasks page).
-
Upload the script to your OpenWrt system (eg under
/usr/bin/wireguard_checker
. -
Make the script executable:
chmod +x /usr/bin/wireguard_checker
-
Add the script to your OpenWrt crontab or schedule it under LuCi -> System -> Scheduled Tasks. For example, to run the script every minute, you can add the following line to your crontab:
* * * * * /usr/bin/wireguard_checker
If you have a glinet router, the interface currently for the wireguard client is wgclient
. I have uploaded a new version (wireguard_checker_glinet
) that does not iterate all the wireguard interfaces.
This script is licensed under the MIT License. You are free to use, modify, and distribute it, provided that you give appropriate credit to the original author (Iannis Spiropoulos).