The cart is empty

In today's digital world, managing network ports is a crucial part of securing and configuring servers. CentOS 7, a popular choice for server deployment, typically uses the FirewallD tool for firewall and port management. This article will guide you through the steps to open or close ports on your CentOS 7 system.

Preparation

Before starting, ensure you have administrative rights (root) on your system, as modifying the firewall requires elevated permissions. Opening a terminal and logging in as root or using the sudo command before each command will allow you to make the necessary changes.

Step 1: Check the Status of FirewallD

The first step involves checking whether the FirewallD service is running on your system. You can do this with the command: sudo systemctl status firewalld

If the service is not running, you can start it using: sudo systemctl start firewalld

And to set the service to start at system boot, use: sudo systemctl enable firewalld

Step 2: Opening a Port

To open a port, you first need to determine which firewall zone you want to add the port to. Zones allow you to define different levels of trust for your network interfaces and the rules that apply to them. To find out the available zones, use: sudo firewall-cmd --get-zones

Once you've chosen a zone (for example, public), you can open a port (e.g., TCP port 80) using the following command: sudo firewall-cmd --zone=public --add-port=80/tcp --permanent

To apply the changes and reload the firewall configuration, use: sudo firewall-cmd --reload

Step 3: Closing a Port

To close a port, use a very similar command as when opening it, but with the --remove-port option: sudo firewall-cmd --zone=public --remove-port=80/tcp --permanent

Remember to reload the firewall configuration to apply the changes: sudo firewall-cmd --reload

Managing ports in FirewallD on CentOS 7 is straightforward if you know the right commands. Opening or closing ports can enhance your system's security or allow communication for specific applications. Always ensure you have only the necessary ports open for your applications and services to minimize the risk of unauthorized access to your system.