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.

Prerequisites

Step 1: Create the Shell Script

  1. Open a terminal on your pfSense box.

  2. Create a new shell script file using the vi editor:

    sh
    Copy code
    vi /usr/local/bin/ping_tailscale.sh
    
    
  3. 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
    
    
  4. Make the script executable:

    sh
    Copy code
    sudo chmod +x /usr/local/bin/ping_tailscale.sh
    
    

Step 2: Make the IP Configurable

To change the IP address to monitor, simply edit the script:

  1. Open the script again:

    sh
    Copy code
    vi /usr/local/bin/ping_tailscale.sh
    
  2. Modify the line IP="PUT IN YOUR IP HERE" to reflect the desired Tailscale client IP address.

  3. Save and exit by pressing Esc, typing :wq, and hitting Enter.

Step 3: Set Up the Cron Job

To run the script automatically every hour, set up a cron job:

  1. Install the Cron Package (if not already installed):
  2. Configure the Cron Job: