In this tutorial, you will learn how to create a shell script that pings a specified Tailscale client IP address. If the script cannot reach the IP, it will restart the Tailscale service. The IP address is configurable, allowing you to monitor different Tailscale clients as needed.
Open a terminal on your pfSense box.
Create a new shell script file using the vi
editor:
sh
Copy code
vi /usr/local/bin/ping_tailscale.sh
Insert the following script into the file:
sh
Copy code
#!/bin/sh
# Configurable Tailscale client IP address
IP="PUT IN YOUR IP HERE" # Change this to the IP of your desired Tailscale client
# Check if the specified IP is reachable
if ping -c 1 $IP > /dev/null 2>&1
then
echo "Ping successful. No action needed."
else
echo "Ping failed. Restarting Tailscale service."
service tailscaled restart
fi
Make the script executable:
sh
Copy code
sudo chmod +x /usr/local/bin/ping_tailscale.sh
To change the IP address to monitor, simply edit the script:
Open the script again:
sh
Copy code
vi /usr/local/bin/ping_tailscale.sh
Modify the line IP="PUT IN YOUR IP HERE"
to reflect the desired Tailscale client IP address.
Save and exit by pressing Esc
, typing :wq
, and hitting Enter
.
To run the script automatically every hour, set up a cron job:
Go to Services > Cron.
Click Add to create a new cron job.
Configure the fields as follows:
0
/1
(to run at the top of every hour)Command: Enter:
sh
Copy code
/usr/local/bin/ping_tailscale.sh
Click Save, then Apply Changes.