Skip to content

Instantly share code, notes, and snippets.

@Daniel-VDM
Created January 24, 2026 07:07
Show Gist options
  • Select an option

  • Save Daniel-VDM/93b6cb8cbfa2b39c92d102b0b83747ba to your computer and use it in GitHub Desktop.

Select an option

Save Daniel-VDM/93b6cb8cbfa2b39c92d102b0b83747ba to your computer and use it in GitHub Desktop.
Script to setup tailscale port forwards on a ubiquity UDM after a firmware update.
set -euo pipefail
LAN_CIDR="192.168.1.0/24"
TS_CIDR="100.64.0.0/10"
HOSTNAME="gg-home-udm"
# Install Tailscale (post-firmware update it won't exist)
if ! command -v tailscale >/dev/null 2>&1; then
curl -fsSL https://tailscale.com/install.sh | sh
fi
# Ensure daemon is running (start only; no restart)
systemctl start tailscaled || true
# Bring Tailscale up (will print login URL if needed)
tailscale up --hostname="$HOSTNAME"
# Enable IPv4 forwarding
sysctl -w net.ipv4.ip_forward=1
# Remove old rules (ignore if they don't exist)
iptables -t nat -D POSTROUTING -s "$LAN_CIDR" -d "$TS_CIDR" -o tailscale0 -j MASQUERADE 2>/dev/null || true
iptables -D FORWARD -s "$LAN_CIDR" -d "$TS_CIDR" -j ACCEPT 2>/dev/null || true
iptables -D FORWARD -s "$TS_CIDR" -d "$LAN_CIDR" -j ACCEPT 2>/dev/null || true
# Add rules (LAN -> Tailscale SNAT + allow forward)
iptables -t nat -A POSTROUTING -s "$LAN_CIDR" -d "$TS_CIDR" -o tailscale0 -j MASQUERADE
iptables -A FORWARD -s "$LAN_CIDR" -d "$TS_CIDR" -j ACCEPT
iptables -A FORWARD -s "$TS_CIDR" -d "$LAN_CIDR" -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment