OverviewFilesCommitsIssuesDocsReleasesPeers

wirecore / scripts / setup-port-forwarding.sh

72 lines · bash ref:
#!/bin/bash
#
# Port Forwarding Setup for TURN Server
# Run this on 7rnx.net gateway (7rntst)
#
# Usage: sudo bash setup-port-forwarding.sh
#

set -e

if [ "$EUID" -ne 0 ]; then
  echo "Please run as root: sudo bash setup-port-forwarding.sh"
  exit 1
fi

PUBLIC_IP="71.234.195.83"
TABERTRON_IP="10.22.0.1"

echo "🔧 Setting up port forwarding for TURN server"
echo "   Public IP: $PUBLIC_IP"
echo "   Tabertron: $TABERTRON_IP"
echo ""

# Enable IP forwarding
echo "1. Enabling IP forwarding..."
sysctl -w net.ipv4.ip_forward=1
echo 'net.ipv4.ip_forward=1' >> /etc/sysctl.conf

# TURN main port UDP
echo "2. Forwarding TURN UDP (3478)..."
iptables -t nat -A PREROUTING -d $PUBLIC_IP -p udp --dport 3478 -j DNAT --to-destination $TABERTRON_IP:3478

# TURN main port TCP
echo "3. Forwarding TURN TCP (3478)..."
iptables -t nat -A PREROUTING -d $PUBLIC_IP -p tcp --dport 3478 -j DNAT --to-destination $TABERTRON_IP:3478

# TURN TLS
echo "4. Forwarding TURN TLS (5349)..."
iptables -t nat -A PREROUTING -d $PUBLIC_IP -p tcp --dport 5349 -j DNAT --to-destination $TABERTRON_IP:5349

# TURN relay range UDP
echo "5. Forwarding TURN relay range (49152-65535 UDP)..."
iptables -t nat -A PREROUTING -d $PUBLIC_IP -p udp --dport 49152:65535 -j DNAT --to-destination $TABERTRON_IP:49152-65535

# Enable MASQUERADE for outbound connections
echo "6. Enabling NAT masquerading..."
iptables -t nat -A POSTROUTING -j MASQUERADE

# Save rules
echo "7. Saving iptables rules..."
mkdir -p /etc/iptables
iptables-save > /etc/iptables/rules.v4

echo ""
echo "✅ Port forwarding configured!"
echo ""
echo "Forwarded ports:"
echo "  $PUBLIC_IP:3478 (UDP) → $TABERTRON_IP:3478"
echo "  $PUBLIC_IP:3478 (TCP) → $TABERTRON_IP:3478"
echo "  $PUBLIC_IP:5349 (TCP) → $TABERTRON_IP:5349"
echo "  $PUBLIC_IP:49152-65535 (UDP) → $TABERTRON_IP:49152-65535"
echo ""
echo "📋 Next steps:"
echo "1. On Tabertron, run:"
echo "   cd /storage/projects/code/hypercore-kb/hyper-fleeky/repos/wirecore"
echo "   bash update-turn-config.sh 71.234.195.83 wirecore8261a6a559ce533c"
echo ""
echo "2. Hard refresh both browsers (Ctrl+Shift+R)"
echo "3. Wait 60 seconds"
echo "4. Check console for: Trystero: 1 peers connected"
echo ""