Many services and programs require you to allow external connections. The best way to do this is to set up a firewall.
In this guide, you’ll learn how to configure a firewall and allow these connections.
If a port is still unreachable despite a rule, the step-by-step checks below can help. They cover every point between the internet and your service, including the network firewall and DDoS protection in the ZapX dashboard.
To install the firewall, you need to connect to your server via SSH. If you’re not sure how to do that, check out our initial connection guide.
After connecting, you should update the server by running apt update and apt upgrade.
This guide covers the firewall on your server (UFW/IPTables). Your VPS also has an additional network firewall in the ZapX dashboard (the Network firewall tab), which sits in front of your server. By default, it is set to ACCEPT for inbound and outbound traffic, so it won’t affect the steps below. However, if you’ve set more restrictive rules there yourself (such as a DROP/REJECT policy or custom firewall rules), you’ll also need to allow the same ports there.
There are several firewall programs for Linux. In this guide, we’ll focus on the two most popular ones: UFW and IPTables.
We’ll start with UFW, as it’s easier to set up and manage.
You can easily install UFW via APT with sudo apt install ufw.
To avoid losing your SSH connection, don’t enable the firewall yet. Configure it properly first.
We recommend the following default policies:
sudo ufw default deny incoming
and
sudo ufw default allow outgoing
Now you should allow your SSH connection and any other ports you want to open:
sudo ufw allow 22 for SSH
sudo ufw allow 80 as an example for HTTP
sudo ufw allow 25565 as an example for a Minecraft game server
To enable UFW, run sudo ufw enable. You can open additional ports at any time with sudo ufw allow PORT.
To allow a port, you can simply use this command:
For TCP ports:
sudo ufw allow PORT/tcp – replace PORT with the port you want to use.
Example: sudo ufw allow 25565/tcp for a Minecraft game server
For UDP ports:
sudo ufw allow PORT/udp – replace PORT with the port you want to use.
Example: sudo ufw allow 9987/udp for a TeamSpeak 3 server
To view all port rules, use sudo ufw status numbered.
To delete a rule, run sudo ufw delete NUMBER, replacing NUMBER with the rule’s number in the list.
Most systems have IPTables installed by default, but to be safe, you can run sudo apt install iptables.
First, set the default policies and settings:
sudo iptables -P INPUT DROP – block all incoming connections
sudo iptables -P FORWARD DROP – block all forwarded connections
sudo iptables -P OUTPUT ACCEPT – allow all outgoing connections
sudo iptables -A INPUT -i lo -j ACCEPT – allow loopback traffic
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT – allow all existing connections
Now you should allow SSH and any other ports you want to open:
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT for SSH
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT as an example for HTTP
sudo iptables -A INPUT -p tcp --dport 25565 -j ACCEPT as an example for a Minecraft game server
To keep the rules after a restart, install the iptables-persistent package with sudo apt install iptables-persistent.
Save the rules with sudo netfilter-persistent save and enable autostart with sudo systemctl enable netfilter-persistent.
To allow a port, you can use this command:
For TCP ports:
sudo iptables -A INPUT -p tcp --dport PORT -j ACCEPT – replace PORT with the port you want to use.
Example: sudo iptables -A INPUT -p tcp --dport 25565 -j ACCEPT for a Minecraft game server
For UDP ports:
sudo iptables -A INPUT -p udp --dport PORT -j ACCEPT – replace PORT with the port you want to use.
Example: sudo iptables -A INPUT -p udp --dport 9987 -j ACCEPT for a TeamSpeak 3 server
You can view all rules with sudo iptables -L --line-numbers.
To delete a rule, use sudo iptables -D INPUT NUMBER, replacing NUMBER with the rule’s number in the list.
Automatically block attackers: With CrowdSec, you can detect brute-force attacks and scanners in your logs and automatically block them in the firewall.
There are several points between the internet and your service where connections can be blocked. A port is reachable only if each of them allows the traffic through. Follow the steps in order, replacing 25565 with your port.
- Check the service: Run
sudo ss -tulpn | grep 25565. If no line appears, the service isn’t running or is using a different port. If the line shows127.0.0.1:25565, the service is only reachable from the server itself. Change its configuration to0.0.0.0(all IPv4 addresses) or[::](IPv6). - Check the firewall on the server: Use
sudo ufw status numberedorsudo iptables -L INPUT -n --line-numbersto see whether a rule exists for the port. Make sure it uses the right protocol: many games need UDP, while web and database services use TCP. - Check the network firewall in the ZapX dashboard: Open your VPS and the Network firewall tab. If Default Inbound is set to DROP or REJECT, or one of your rules blocks the port, add a rule there with the ACCEPT action for the port and protocol.
- Test from outside: Check the port with our Port Checker. For TCP, the result is conclusive. An open UDP port often doesn’t respond to the test request, so only a “closed” result is conclusive. For this reason, it’s best to test UDP services directly with the game or program.
- Check DDoS protection: If the port is still unreachable, review the learned rules in the DDoS protection tab, as described in the next section.
You can find out which standard port each service uses, and see the corresponding firewall commands, in our Well-known Ports & Firewall Commands overview.
At our locations in Germany and the US, PletX DDoS protection filters incoming traffic before it reaches your VPS. The filter automatically detects the protocol for each port as soon as real traffic arrives and creates a rule for it, such as Minecraft on TCP 25565 or SSH on TCP 22. Traffic that doesn’t match this rule is filtered out.
Problems can occur in three main cases:
- A service is running on a custom port for which the filter doesn’t have a rule yet, such as an anti-cheat proxy or SFTP for Pterodactyl Wings on TCP 2022.
- A rule has identified the wrong service.
- An upstream proxy such as TCPShield or NeoProtect changes the traffic in a way that makes the game filter identify it as invalid.
Here’s what to do:
- Open the DDoS protection tab for your VPS and check Learned rules to see which service is listed for your port.
- If the rule is missing or the service is incorrect, click Request rule. Enter the Port, Protocol, and the Service on this port, and briefly describe what isn’t working while the filter is enabled. Your request creates a ticket, and we’ll let you know when the rule is active.
- If your VPS has its own IP address, you can temporarily turn off protection by clicking Disable protection to test the connection. If the port works then, the filter is causing the problem. Turn protection back on afterward.
While protection is disabled, your VPS isn’t protected against DDoS attacks, and bandwidth is limited to the port speed included in your plan. After an attack is detected, protection remains mandatory until the date shown in the tab.
You can’t create or delete rules yourself. The guide to PletX DDoS protection explains how the filter works and what information we need when you have a connection issue. The OVH DDoS protection applies instead at our London, Montreal, Singapore, and Sydney locations.
On newly ordered VPSs, outgoing connections on ports 25 and 465 are blocked until you verify a phone number in your account. This helps protect our network from spam sent by compromised servers. While the block is active, your VPS displays the notice Email sending blocked.
- Click Verify phone number in the notice. You’ll be taken directly to the phone number section in your account settings.
- Verify your phone number there using the code. The block will then be automatically lifted for all VPSs in your account.
- Open the Settings tab for your VPS, go to the Reverse DNS section, and enter your mail server’s hostname, for example,
mail.example.com. Add an A record for this hostname pointing to your VPS’s IP address with your domain provider. Many mail servers reject emails without a matching reverse DNS record.
Port 587 isn’t blocked. This means you can send emails through an external SMTP relay service on port 587 even without requesting an unblock. We don’t block incoming connections on port 25: if your mail server isn’t reachable from the outside, the checks above can help.
If the notice says that Support blocked the ports, verifying a phone number won’t lift the block. In this case, contact our Support team.
My IP address is on a blacklist (e.g., Spamhaus)
First, check check.spamhaus.org to see which list your IP address is on.
- Spamhaus PBL: This isn’t a penalty list. The PBL identifies address ranges that shouldn’t deliver email directly to other mail servers. If Spamhaus offers you the option to remove your IP, you can request it there. Otherwise, contact our Support team, and we’ll check whether your individual IP address can be delisted. In the meantime, you can use an external SMTP relay service on port 587.
- Other lists (for example, Spamhaus SBL/XBL, UCEPROTECT, Barracuda): These listings are usually caused by actual spam or malware. First, find and fix the cause, such as a hacked script, an open mail relay, or an open proxy. Then request removal from the list operator.
Getting a new IP address usually doesn’t help, because addresses in the same range often have the same listing. Security filters used by individual internet providers to block your server for their customers aren’t blacklists. Only the provider or its customers can remove these blocks in their own settings.
Players can’t connect to the server through TCPShield or NeoProtect
External proxies change how the connection is established. If the PletX filter detects a game such as Minecraft on your port, it may discard this traffic as invalid. In this case, request a suitable rule using Request rule in the DDoS protection tab, and include the proxy details. It isn’t possible to allow the proxy’s IP ranges for just one port.
Also check your own firewall: if you allow the port only for the proxy’s addresses, make sure the list is complete and up to date. Also note that your VPS can only send packets with its own IP address as the sender. Tunnels that use other sender addresses won’t work.
My ports are closed again after a restart
For UFW, check whether the firewall is active with sudo ufw status, and enable it if needed with sudo ufw enable. IPTables rules are lost on restart unless you install the iptables-persistent package. Save them after each change with sudo netfilter-persistent save.
I’ve locked myself out of SSH
Open the Console tab for your VPS in the ZapX dashboard and log in there. Reopen the SSH port with sudo ufw allow 22 or temporarily disable UFW with sudo ufw disable. If you’ve set a rule in the Network firewall tab that blocks SSH, remove it there.
I can’t disable DDoS protection
You can disable protection only if you have your own IP address. If your server shares an IP address with others, the toggle is disabled. Also, after an attack is detected, protection remains mandatory for a while; the date is shown in the DDoS protection tab.
