Skip to content

Instantly share code, notes, and snippets.

@luckman212
Created January 25, 2026 20:20
Show Gist options
  • Select an option

  • Save luckman212/cc5ec3ba5c1e646b43eac705e51d7334 to your computer and use it in GitHub Desktop.

Select an option

Save luckman212/cc5ec3ba5c1e646b43eac705e51d7334 to your computer and use it in GitHub Desktop.
Healthcheck script for WireGuard running on pfSense
#!/bin/sh
QRY='some-hostname-in-your-tailnet.ts.net'
WANT='100.100.101.101' #expected IP address of that host
RESTART=0
if ! service tailscaled status | grep -q 'tailscaled is running' ; then
RESTART=1
logger -t tailscaled "Tailscale service is not running"
fi
res=$(dig +time=1 +tries=1 +short -t a $QRY @100.100.100.100)
if [ "$res" != "$WANT" ] ; then
RESTART=1
logger -t tailscaled "Quad100 invalid DNS response ($res)"
fi
if ! ifconfig -g Tailscale | grep -q tailscale0 ; then
RESTART=1
logger -t tailscaled "tailscale0 does not have interface group set"
fi
res=$(tailscale status --json | jq -r '.Health[] | contains("logged out")')
if [ "$res" = "true" ]; then
RESTART=1
logger -t tailscaled "tailscale is logged out"
sed -i.bak '/pfsense_tailscaled_authkey.*/d' /usr/local/etc/rc.conf.d/pfsense_tailscaled
fi
if [ "$RESTART" -eq 1 ] ; then
logger -t tailscaled "Restarting tailscale service"
pfSsh.php playback svc restart tailscale
fi
@luckman212
Copy link
Author

What

This is a simple healthcheck script that should have no noticable impact on your system. It runs a few quick sanity checks to keep WireGuard up and running.

Specifically, it:

  • Makes sure the Tailscale service is running
  • Makes sure Quad100 DNS lookups are working
  • Fixes a problem with stale auth keys causing a "Tailscale is not online" error after reboots
  • Makes sure the tailscale0 interface has its interface group set properly (firewall rule helper)
  • If any of these checks fail, the fix will be applied, a message will be logged to syslog, and the Tailscale service will be restarted

How

  1. Save the script above to your pfSense, e.g. as /root/tscheck.sh
  2. Make it executable with chmod +x /root/tscheck.sh
  3. Use the Cron package (install it if you need to) to run this script at a sensible interval (I suggest every 5 minutes):
*/5 * * * *  root  /root/tscheck.sh

This has been tested on pfSense+ 25.07.1, 25.11, and 26.03

Please report any issues you encounter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment