On Ubuntu or Debian, run sudo ufw allow ssh before sudo ufw enable, so starting Uncomplicated Firewall (UFW) does not lock you out. Open a port with sudo ufw allow followed by the port number, adding /tcp to limit the rule to one protocol. Running sudo ufw status lists the active rules. Close a port again with sudo ufw delete allow followed by its number.
Services running on Ubuntu or Debian need specific ports opened in the firewall before they can receive traffic. SSH connections, web servers and custom applications all require their ports to be accessible.
You will install UFW (Uncomplicated Firewall), configure SSH access to prevent lockouts and open the ports your services need. UFW provides a simpler interface than working directly with iptables.
UFW may already be installed on your system. You will check for an existing installation before attempting to install it.
sudo ufw statussudo apt update && sudo apt upgrade && sudo apt install ufwUFW is now installed and ready to configure. You will enable it and open your required ports in the next section.
You must allow SSH access before enabling UFW. This prevents you from being locked out of your server when the firewall starts blocking traffic.
sudo ufw allow sshsudo ufw enabley and press Enter to confirm. Your SSH rule from the previous step keeps your current connection active.2087 with your port number:sudo ufw allow 2087sudo ufw allow 2087/tcpsudo ufw statusYour port is now open and accepting traffic. Services listening on this port can receive connections from external sources.
You can delete rules when you no longer need a port open. This closes the port and blocks traffic that was previously allowed.
2087 with the port number you want to close:sudo ufw delete allow 2087sudo ufw statusThe port is now closed and will reject incoming connections.
Your Ubuntu or Debian server now has UFW configured with the ports your services need. You installed the firewall, protected SSH access and opened specific ports for incoming traffic. Services listening on these ports can now receive connections.
Did this guide solve your problem?
Our UK support team answers tickets and live chat every day. Send us the guide you were following and where it stopped working.
Related guides
Get scalable resources with our VPS hosting with root access and optional software.
Get VPS HostingPerfect for websites and small businesses unlimited bandwidth with cPanel hosting.
Get cPanel Hosting