On Linux the firewall depends on the distribution: ufw on Ubuntu and Debian, firewalld on AlmaLinux and Rocky. Both do the same job, the commands differ.
First of all: if you are enabling the firewall for the first time, allow port 22 (SSH) before turning it on. It is the fastest and silliest way to lock yourself out of your own server. If it happens, you can still get in through the panel's VNC tab.
Ubuntu and Debian (ufw)
# First, ALWAYS
ufw allow 22/tcp
# Your port, on both protocols
ufw allow 30120/tcp
ufw allow 30120/udp
# A range
ufw allow 7777:7778/udp
# Enable (if it was off) and see the result
ufw enable
ufw status numbered
To remove a rule, find its number in ufw status numbered and delete it with ufw delete 3. ufw delete allow 30120/udp works too.
AlmaLinux and Rocky (firewalld)
# First, ALWAYS
firewall-cmd --permanent --add-service=ssh
# Your port, on both protocols
firewall-cmd --permanent --add-port=30120/tcp
firewall-cmd --permanent --add-port=30120/udp
# A range
firewall-cmd --permanent --add-port=7777-7778/udp
# Apply and check
firewall-cmd --reload
firewall-cmd --list-all
--permanent is what makes the rule survive a reboot; without it, it is lost. And --reload is what applies it: without reloading, nothing happens. To remove it, same command with --remove-port.
Checking your server is listening
With the game server running:
ss -lntup | grep 30120
You should see a line with LISTEN (for TCP) or UNCONN (for UDP, which is normal). If nothing comes back, the firewall is not your problem: the server is not running, or listens on another port.
Check the address too: if it says 127.0.0.1:30120 instead of 0.0.0.0:30120, your server only accepts local connections and no firewall rule in the world will let anyone in. That is fixed in the game's config, not the firewall.
Ports you should NOT open
- Your database (3306 for MySQL, 5432 for PostgreSQL). If the game and the database are on the same machine they talk over
localhostand there is nothing to open. A MySQL exposed to the world is an invitation. - Admin panels such as txAdmin. Use an SSH tunnel instead:
ssh -L 40120:localhost:40120 root@YOUR_IP, then openlocalhost:40120in your browser. - RCON, unless you genuinely need it from outside. And if you open it, make the password long and unique.
If it still does not work
- Is the server listening, and on
0.0.0.0? Thesscommand above. - Right protocol? Many games are UDP; open both and remove the doubt.
- Are you testing from outside? From the server itself it always works.
- Check the filters on your service's Security tab in the panel: that is the network AntiDDoS filtering, a separate layer from the system firewall.