🇩🇪 DE 🇬🇧 EN
NexoraHost / Docs home
Popular searches:Minecraft won't startCreate Minecraft serverFiveM txAdminInstall WordPressSet up subdomainVPS GermanySSL errorOpen port 25565Discord bot hostingDNS troubleshooting

UFW Firewall – Open Ports Without Locking SSH (Minecraft, Web, SSH)

Quick answer: With UFW you open ports in 2 minutes – but always allow SSH (port 22) first or you'll lock yourself out. Then open game or web ports.

If you landed here: Your game server isn't reachable or you want to enable UFW for the first time.

This guide shows you how to open and close ports on your server – both on Linux and Windows. This protects your server from unwanted access and only makes those services accessible that really need to be reached.

Note: Detailed subpages on security and network can be found in the left navigation.

Linux: UFW (Uncomplicated Firewall)

UFW is pre-installed on Ubuntu and Debian. It's the easiest way to manage ports.

Installation and activation

# Installation (usually pre-installed)
sudo apt install ufw

# Important: Allow SSH first, then enable!
sudo ufw allow 22/tcp
sudo ufw enable

Show status

# Shows all rules with numbers
sudo ufw status numbered

# Detailed view
sudo ufw status verbose

Opening ports

# Single port
sudo ufw allow 80/tcp

# Port range
sudo ufw allow 27000:27100/tcp

# Allow for a specific IP
sudo ufw allow from 192.168.1.100 to any port 22

Closing ports

# By port number
sudo ufw deny 3306/tcp

# By number from "ufw status numbered"
sudo ufw delete 3

# Delete complete rule
sudo ufw delete allow 80/tcp

Default rules

# Block all incoming
sudo ufw default deny incoming

# Allow all outgoing
sudo ufw default allow outgoing

Important ports for game servers

Game Port(s) Protocol Command
Minecraft 25565 TCP sudo ufw allow 25565/tcp
FiveM 30120 TCP + UDP sudo ufw allow 30120
CS2 27015 TCP + UDP sudo ufw allow 27015
ARK 7777, 27015 UDP sudo ufw allow 7777/udp
Rust 28015 TCP + UDP sudo ufw allow 28015
Teamspeak 3 9987, 10011, 30033 UDP + TCP sudo ufw allow 9987/udp

Linux: Firewalld (CentOS/RHEL)

# Show status
sudo firewall-cmd --list-all

# Open port
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload

# Close port
sudo firewall-cmd --permanent --remove-port=80/tcp
sudo firewall-cmd --reload

Windows: Windows Firewall

Via GUI (graphical)

  1. Open Windows Settings → Update & Security → Windows Security
  2. Click Firewall & Network Protection → Advanced Settings
  3. Select Inbound Rules or Outbound Rules on the left
  4. Click New Rule on the right
  5. Select Port → TCP or UDP → Enter specific ports
  6. Choose action: Allow the connection or Block the connection
  7. Select profile (Domain, Private, Public)
  8. Give it a name and click Finish

Via PowerShell (faster)

# Open port (TCP)
New-NetFirewallRule -DisplayName "Minecraft Server" -Direction Inbound -Protocol TCP -LocalPort 25565 -Action Allow

# Open port (UDP)
New-NetFirewallRule -DisplayName "Minecraft Server" -Direction Inbound -Protocol UDP -LocalPort 25565 -Action Allow

# Close port / delete rule
Remove-NetFirewallRule -DisplayName "Minecraft Server"

# Show all rules
Get-NetFirewallRule | Where-Object { $_.Enabled -eq 'True' }

Via Command Prompt (CMD)

# Open port
netsh advfirewall firewall add rule name="Minecraft" dir=in action=allow protocol=TCP localport=25565

# Close port / delete rule
netsh advfirewall firewall delete rule name="Minecraft"

Check ports – which ones are open?

Linux

# Show running services with ports
sudo ss -tlnp

# Even more details
sudo netstat -tlnp

Windows

# Show all open ports
netstat -an

# Only listening ports
netstat -an | findstr LISTENING

Avoid common mistakes

Detailed guides on security and network can be found in the articles in the left navigation.

Frequently asked questions (FAQ)

Can UFW lock me out?
Yes – if you ufw enable without allowing SSH (port 22) first. Always: ufw allow 22/tcp → then ufw enable.
Which ports for Minecraft?
25565 TCP and UDP: sudo ufw allow 25565/tcp && sudo ufw allow 25565/udp
UFW or iptables?
UFW is the simple frontend for iptables on Ubuntu/Debian – recommended for beginners.

NexoraHost

Root & VPS servers

Ryzen power at Maincubes FRA01 – full root access, NVMe, DDoS protection included.

nexorahost.com · Maincubes FRA01 · 1 Tbit/s DDoS · 99,9 % Uptime