If you are using a Linux VPS (Virtual Private Server) with the CentOS 7 operating system, or even an AlmaLinux VPS, you may need to open ports to allow network traffic for a specific application. In this tutorial, we will guide you through the process of opening ports on a CentOS 7 VPS.
Step 1: Connect to the VPS
First, connect to your CentOS 7 server via SSH (Secure Shell). You can do this through your terminal or a remote access tool, such as PuTTY (for Windows users) or Terminal (for Mac OS or Linux users). Use your login credentials to access the server.
Step 2: Check the open ports
Before opening a new port, it is important to check which ports are already open on your server. To do this, run the following command:
sudo firewall-cmd --list-ports
This will list all the ports that are currently open on your CentOS 7 server.
Step 3: Add the new port
To open a new port on your server, you need to add a new rule to your firewall. CentOS 7 comes with a built-in firewall called firewalld. To open a port, you need to add a new rule in firewalld.
For example, if you want to open port 8000 to allow incoming traffic for a web application, run the following command:
sudo firewall-cmd --add-port=8000/tcp --permanent
The `--add-port` parameter adds a new rule to open a port, and the `--permanent` parameter ensures that the rule is saved permanently after the server restarts.
If you want to open a port for UDP traffic, change "tcp" to "udp" in the command.
Step 4: Reload the firewall
After adding a new rule, you need to reload the firewall for the rule to take effect. To do this, run the following command:
sudo firewall-cmd --reload
This will reload the firewall and apply the new rules.
Step 5: Verify the new open port
Finally, you can verify that the new port is open on the server. Run the following command to check all open ports:
sudo firewall-cmd --list-ports
This will list all the ports that are currently open on your CentOS 7 server, including the new port you just opened.
Conclusion
Opening ports on a CentOS 7 Linux VPS is a relatively simple task, but it is important to follow the correct steps to ensure the new port is opened properly. Make sure to check the open ports before adding a new rule and to reload the firewall after adding the new rule. With these steps, you can open ports on a CentOS 7 Linux VPS and allow network traffic for specific applications.
