March 5, 2023

How To Configure A Firewall Port In CentOs 7

Abhishek Thakur


In CentoS 7 or any OS applications which implement common services often use port numbers to define it. The process applied is called listening . Which involves receiving and transferring requests for the communication of services. Ports allows a computer to easily distinguish between different types of network traffics. For example, email goes to a different port than web pages. Even though they both reach the same computer through the same Internet connection. In contrast this brings us to firewall, which is in fact a security system that blocks or allows network traffic based on a set of security rules. In brief a firewall often lie between trusted and untrusted networks. Often the unreliable network is the Internet. In this guide we will explain how to configure a firewall port in CentOS 7 and use networking tools to list and check open ports.

Requirements

Steps To Configure A Firewall Port If No Appropriate Service Is Available?

To add support for a particular application is by opening the ports it uses in the appropriate region(s). This is done by specifying the port or port range and associated protocol for the ports you need to open. For example, if our application runs on port 3445 and uses TCP, in addition we could add this to the “public” zone for this session using the –add-port= parameter. Protocols can be either tcp or udp:

# firewall-cmd –zone=public –add-port=3445/tcp

Next we can verify that the port is added by running the given query in terminal.

# firewall-cmd –zone=public –list-ports

Steps To Configure A Firewall Port With firewalld

The correct procedure for opening a port in CentOs 7 depends upon firewalld or the iptable utility. firewalld provides a dynamically managed firewall with support for network zones. i In addition it supports IPv4, IPv6 firewall settings, Ethernet bridges, and IP suites. Firewalld is available by default in all CentOS installations. However, there can be a case where it’s not installed. To check that you can run the given command in the terminal, this will verify the presence of firewalld.

# systemctl status firewalld

Configure Firewall Port

 

With 99RDP default installation firewalld service is installed and running. However if you need to install firewalld you can do it by running the given command.

# yum install firewalld

This will install the firewalld service on the system, next you need to enable and start the service, to do that run the given command in terminal.

# systemctl enable firewalld

# systemctl start firewalld

Once it is enabled we can check the current list of services that are added to the firewalld by running the given command.

# firewall-cmd –list-all

IThe output will show all the rules that are associated with the default zone.

Configure Firewall Port

 

To add a specific service to to the list of allowed ports you can run the given command and relaod the firewalld service for the changes to be applied. For example lets try port 56.

# firewall-cmd –zone=public –add-port=56/tcp –permanent

# firewall-cmd –reload

Open Firewall Port

 

Subsequently to block a TCP port, for example port 56, you can run the given command in terminal and again reload the firewall rule again.

# firewall-cmd –zone=public –remove-port=56/tcp –permanent

# firewall-cmd –reload

After that you can list the applied rules again by running the given command, you will see that the port 56 is added to the firewalld allowed ports list.

# firewall-cmd –list-all

 

Firewall Ports

In the output you can compare that the port 56 is removed from the allowed port lists.

Conclusion

In this tutorial we have learned how to enable port if there is no firewall service. Next, we saw how to use the firewall service to manage inbound and outbound traffic by proxying the port it listens on. Finally, we know how to remove any port number from the list of allowed ports. Thanks for the time you spent with me.


Buy Dedicated Server @ $9/m Only.

Popular Blog Posts