Open Ports in CentOS 7: Firewall & SELinux Guide

The typical method for opening ports on CentOS 7 usually involves configuring the firewall and SELinux.

  1. To open a port using the firewall-cmd command, the following command can be used:
sudo firewall-cmd --zone=public --add-port=PORT_NUMBER/tcp --permanent

PORT_NUMBER is the port number that needs to be opened. Then reload the firewall rules to apply the changes.

sudo firewall-cmd --reload
  1. To open a port in SELinux using the semanage command:
    If SELinux is enabled and blocking access to a port, you can use the following command to allow access to a specific port.
sudo semanage port -a -t PORT_TYPE -p tcp PORT_NUMBER

PORT_TYPE represents the type of port, typically http_port_t or other types; PORT_NUMBER is the port number to be opened.

  1. Restart services:
    After completing the above steps, a restart of the relevant services may be necessary to apply the changes.

Please be aware to refer to the CentOS documentation and related documents for more detailed guidance and the latest information.

bannerAds