Reprinted from: https://linux.cn/article-4243-1.html
If you want to provide services on the server, Enterprise Linux distributions such as CentOS or Rhel contain built-in powerful firewalls, which are strictly the default firewall rules. Therefore, if you install any custom services (such as Web servers, NFS, and Samba), then their traffic is likely to be blocked by firewall rules. So you need to open the necessary ports on the firewall to allow traffic to pass through.
On Centos/rhel 6 or earlier, the Iptables service allows users to interact with NetFilter kernel modules to configure firewall rules in user space. However, starting with Centos/rhel 7, a new user space interface called FIREWALLD was introduced to replace the Iptables service.
Use this command to view the current firewall rules:
Now, let's see how to modify the firewall on Centos/rhel to open a port.
Open port on Centos/rhel 7
After you start Centos/rhel 7, the firewall rule settings are managed by the FIREWALLD service process by default. A command line client called Firewall-cmd supports communication with this daemon to permanently modify firewall rules.
Use these commands to permanently open a new port (such as TCP/80).
If you do not use the "--permanent" flag, the firewall rules will fail after the reboot.
Open port on Centos/rhel 6
On Centos/rhel 6 or earlier systems, the Iptables service is responsible for maintaining firewall rules.
Use the first command of Iptables to open a new TCP/UDP port through the firewall. A second command is required to permanently save the modified rule.
Another approach is through a firewall client named System-config-firewall-tui, a command-line user interface (TUI).
$ sudo system-config-firewall-tui
Select the "Customize" button in the middle and press the ENTER key.
If you want to modify the firewall for any known service (such as a Web server), simply tick the service and then close the tool. If you want to open any of the TCP/UDP ports, select the "Forward" button and go to the next screen.
Select the "Add" button to add a new rule.
Specify a port (such as 80) or a port range (such as 3000-3030) and a protocol (such as TCP or UDP).
Finally, save the modified configuration and close the tool. In this way, the firewall is permanently saved.
Compiled from: http://ask.xmodulo.com/open-port-firewall-centos-rhel.html
Original: LCTT https://linux.cn/article-4243-1.html
Translator: Kayguowhu
Open ports on the CentOS or Rhel firewall