Files
Minecraft-Server/portforward
Paul Kloppers ad654d145a Initial commit: minecraft server setup
Tracks docker-compose config, server scripts, and server properties.
Runtime data (world, libraries, versions, logs, jar), credentials, and
backup snapshots are gitignored.
2026-04-21 20:33:22 +02:00

25 lines
673 B
Bash
Executable File

#!/bin/bash
# Get the first parameter as LOCAL_PORT (default to 25565 for Minecraft)
LOCAL_PORT=${1:-25565}
# Get the second parameter as OFFSET (default to 0 so public port == local port)
OFFSET=${2:-0}
# Calculate the PUBLICPORT by adding the OFFSET to the LOCAL_PORT
PUBLICPORT=$(($LOCAL_PORT + OFFSET))
# SSH host alias (defined in ~/.ssh/config)
SSH_HOST="spotbot"
echo " $SSH_HOST:$PUBLICPORT --> localhost : $LOCAL_PORT "
# Run SSH command to create a reverse tunnel from the server
while true; do
autossh -M 0 -N \
-R 0.0.0.0:$PUBLICPORT:localhost:$LOCAL_PORT \
-o "ServerAliveInterval 20" -o "ServerAliveCountMax 3" \
$SSH_HOST
sleep 5
done