Konfiguration von Tailscale als Exit Node mittels Script

Schritt 5 der Serie: Internetblockaden umgehen und Privatsphäre in öffentlichen WLANs schützen

In diesem Teil der Serie stelle ich dir ein Script vor, das die Netzwerkeinstellungen von Ubuntu Server für Tailscale vorbereitet.

Wenn du dich nicht mit den Details zur Konfiguration der Firewall und dem IP-Forwarding auseinandersetzen will, dann erstelle einfach nachfolgendes Script und führe es aus.

tailscale-exit-node-setup.sh
#!/bin/bash

set -e

# 1. Variables
IFACE=$(ip -o route get 8.8.8.8 | awk '{print $5}')
TAILSCALE_CONF="/etc/sysctl.d/90-tailscale.conf"

echo "[INFO] Detected external interface: $IFACE"

# 2. Enable forwarding in UFW
echo "[INFO] Setting DEFAULT_FORWARD_POLICY to ACCEPT"
sudo sed -i 's/^DEFAULT_FORWARD_POLICY=.*/DEFAULT_FORWARD_POLICY="ACCEPT"/' /etc/default/ufw

# 3. Insert NAT rules in before.rules
echo "[INFO] Adding NAT rules to /etc/ufw/before.rules (if not already present)"
NAT_RULE="-A POSTROUTING -s 100.64.0.0/10 -o $IFACE -j MASQUERADE"
if ! sudo grep -qF -- "$NAT_RULE" /etc/ufw/before.rules; then
  sudo sed -i "1i*nat\n:POSTROUTING ACCEPT [0:0]\n$NAT_RULE\nCOMMIT\n" /etc/ufw/before.rules
fi

# 4. Allow routed traffic from Tailscale to external interface
echo "[INFO] Allowing routed traffic from tailscale0 to $IFACE"
sudo ufw route allow in on tailscale0 out on $IFACE

# 5. Enable IP forwarding via sysctl
echo "[INFO] Writing sysctl settings to $TAILSCALE_CONF"
echo "net.ipv4.ip_forward = 1" | sudo tee $TAILSCALE_CONF
echo "net.ipv6.conf.all.forwarding = 1" | sudo tee -a $TAILSCALE_CONF
sudo sysctl -p $TAILSCALE_CONF

# 6. Enable GRO settings for performance (via ethtool)
echo "[INFO] Creating network-dispatcher script for ethtool optimization"
sudo mkdir -p /etc/networkd-dispatcher/routable.d
cat <<EOF | sudo tee /etc/networkd-dispatcher/routable.d/50-tailscale
#!/bin/sh
ethtool -K $IFACE rx-udp-gro-forwarding on rx-gro-list off
EOF
sudo chmod 755 /etc/networkd-dispatcher/routable.d/50-tailscale
sudo /etc/networkd-dispatcher/routable.d/50-tailscale

# 7. Reload UFW
echo "[INFO] Reloading UFW rules"
sudo ufw reload

# 8. Final message
echo
echo "[INFO] Exit node setup complete."
echo "You can now enable this server as a Tailscale exit node with:"
echo "  sudo tailscale down"
echo "  sudo tailscale up --advertise-exit-node"

Zuerst öffnest du nano.

Bash
nano tailscale-exit-node-setup.sh

Anschließend kopiere den Inhalt des Scripts und füge ihn im Terminal ein.

Mit CMD+x (Mac) bzw. CTRL+x (Windows, Linux) beendest du nano und zusätzlich musst du noch bestätigen dass du den Inhalt der Datei speichern willst.

Anschließend machst du die Datei mit dem Befehl chmod ausführbar.

Bash
sudo chmod +x ./tailscale-exit-node-setup.sh

Jetzt kannst du das Bash-Script ausführen.

Bash
./tailscale-exit-node-setup.sh

Kommentare

Schreibe einen Kommentar