#!/bin/bash # ============================================================================== # Tailscale Exit Node Automated Setup # ============================================================================== # This script provisions a fresh Debian/Ubuntu VPS as a Tailscale exit node. # It enables IP forwarding, installs Tailscale, and securely authenticates # the machine to your Tailnet without manual intervention. # # EXECUTION COMMAND: # curl -s https://node.momo.dev.br | sudo bash -s -- tskey-auth-YOUR_KEY_HERE # ============================================================================== # Exit immediately if any command fails set -e # Ensure the script is run as root if [ "$EUID" -ne 0 ]; then echo "--- Error: Please run this script as root (or using sudo) ---" exit 1 fi # Ensure the Tailscale auth key was passed as an argument if [ -z "$1" ]; then echo "--- Error: Missing Tailscale Auth Key! ---" echo "Usage: curl -s https://node.momo.dev.br | sudo bash -s -- tskey-auth-..." exit 1 fi echo "--- 1. Updating package list and prerequisites ---" apt-get update -y apt-get install -y curl echo "--- 2. Enabling IP Forwarding ---" # Linux requires this to route traffic from other devices echo 'net.ipv4.ip_forward = 1' > /etc/sysctl.d/99-tailscale.conf echo 'net.ipv6.conf.all.forwarding = 1' >> /etc/sysctl.d/99-tailscale.conf sysctl -p /etc/sysctl.d/99-tailscale.conf echo "--- 3. Installing Tailscale ---" # Runs Tailscale's official automated install script curl -fsSL https://tailscale.com/install.sh | sh echo "--- 4. Starting Tailscale and Advertising Exit Node ---" # Uses the auth key passed as the first argument ($1) tailscale up --authkey="$1" --advertise-exit-node echo "--- Setup Complete! ---" echo "Your VPS is now configured, authenticated, and routing traffic."