In this guide, you’ll learn how to open a port in firewalld, either by specifying a port number or enabling a premade service. Then you’ll be able to to verify which ports and services are currently active, ensuring your configuration is correct.
Opening ports in firewalld is essential for securing your VPS and the applications you run. It’s often one of the first tasks when managing your VPS, helping to prevent unauthorised access whilst allowing legitimate traffic. For example, you’ll need to open specific ports when you install MERN stack on AlmaLinux or connect to PostgreSQL remotely.
Access Your Server via SSH
Begin by logging into your Linux server using SSH with sufficient privileges:
user@your-server-ip
Before adding a port manually, it’s best to see if firewalld already recognises the port as a named service. This makes configuration more readable and easier to manage:
firewall-cmd --get-services
Look for a service name that corresponds to your application.
http and https for web servers.ssh for SSH connections.mysql and postgresql for database servers. mongodb for MongoDB databases.Enable it using this command:
sudo firewall-cmd --permanent --add-service=SERVICE
Replace service with the appropriate name for example: httpd, mysql.
Manually open the port by specifying the port number and protocol:
sudo firewall-cmd --permanent --add-port=3080/tcp
Replace 3080 and tcp with the port you need opened and the protocol its on.
Reload firewalld to apply changes
To make your changes active, reload the Firewalld configuration:
sudo firewall-cmd --reload
This applies all permanent changes and resets any temporary runtime rules.
After updating your firewall, it’s essential to confirm the correct services and ports are enabled.
sudo firewall-cmd --list-services
sudo firewall-cmd --list-ports
There are a few different firewall options to choose from another great choice would be ufw or uncomplicated firewall, learn how to configure UFW firewall.
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