Firewall configuration
Set up UFW on Ubuntu/Debian — allow SSH first, open only the ports you need, and check the rules.
1 min read
On this page
A firewall should allow only what you actually use.
Set up UFW#
bash
sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH # or: sudo ufw allow 2222/tcp if you moved SSH
sudo ufw enableOpen ports for your services#
bash
# Web server
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
# Minecraft Java
sudo ufw allow 25565/tcp
# Minecraft Bedrock / Geyser (NetherNet needs TCP for signaling + UDP for gameplay)
sudo ufw allow 19132/tcp
sudo ufw allow 19132/udpCheck and remove rules#
bash
sudo ufw status numbered
sudo ufw delete 3 # removes rule number 3Restrict a port to one IP#
For example, allow a database only from your app server:
bash
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcpDocker warning#
Docker writes its own iptables rules, and published container ports can bypass UFW. Bind containers to localhost (-p 127.0.0.1:8080:80) and put a reverse proxy in front, or use Docker-aware firewall configuration.
Windows VPS#
Use Windows Defender Firewall with Advanced Security → Inbound Rules → New Rule, and only open the ports you need.
Was this page helpful?
