Skip to content

πŸ”₯ GameShield Firewall Setup Guide ​

This guide will help you secure your server by configuring a firewall that only allows GameShield traffic and blocks all other sources on specified ports.

πŸ›‘οΈ The first and the last step. ​

Here’s how to close your ports to all IPs except GameShield. Copy this script, enter the ports you want to firewall into the PROTECTED_PORTS and run it on your linux machine.

bash
#!/bin/bash

# Replace with the ports you want to protect (space-separated)
PROTECTED_PORTS=(25565 25577)
GAMESHIELD_ADDRESSES_URL="https://rest.gameshield.io/v1/servers/plain"

echo "Resetting UFW rules (optional)..."
sudo ufw --force reset

echo "Allowing SSH to prevent lockout..."
sudo ufw allow ssh

# Deny all traffic to specified ports
for PORT in "${PROTECTED_PORTS[@]}"; do
  echo "Blocking port $PORT from all sources..."
  sudo ufw deny from any to any port "$PORT"
done

echo "Fetching GameShield addresses..."
GAMESHIELD_ADDRESSES=$(curl -s "$GAMESHIELD_ADDRESSES_URL")

if [[ -z "$GAMESHIELD_ADDRESSES" ]]; then
  echo "❌ Failed to fetch GameShield addresses. Exiting."
  exit 1
fi

echo "Allowing GameShield addresses..."
while IFS= read -r ip; do
  [[ -z "$ip" ]] && continue
  for PORT in "${PROTECTED_PORTS[@]}"; do
    echo "Allowing $ip on port $PORT"
    sudo ufw allow from "$ip" to any port "$PORT"
  done
done <<< "$GAMESHIELD_ADDRESSES"

echo "Enabling firewall..."
sudo ufw --force enable

echo "βœ… Firewall configured successfully!"