CentOS open port (the most efficient method)

1. Connect to CentOS server

View open ports:

`firewall-cmd --list-ports`

  
  
   
   
  • 1

2. View the status of the firewall:

input the command

`firewall-cmd --state`

  
  
   
   
  • 1

3. Turn on the firewall:

If the previous step is off, enter the command to enable the firewall:

`systemctl start firewalld.service`

  
  
   
   
  • 1

4. Open the port

Enter the command to open port 8000:

`firewall-cmd --zone=public --add-port=8000/tcp --permanent && firewall-cmd --reload`

  
  
   
   
  • 1

Close port 8000:

`firewall-cmd --zone=public --remove-port=8000/tcp --permanent`

  
  
   
   
  • 1

Let's explain the previous command:

  • --zone=public: Indicates that the scope is public;
  • --add-port=8080/tcp: Add port 8080 of the tcp protocol;
  • --permanent: Permanently effective; (If there is no such parameter, it can only be maintained within the current service life cycle, and it will be invalid after restarting;)

5. Enter the command to re-enter the configuration:

`firewall-cmd --reload`

  
  
   
   
  • 1

1. Connect to CentOS server

View open ports:

`firewall-cmd --list-ports`

  
  
   
   
  • 1

2. View the status of the firewall:

input the command

`firewall-cmd --state`

  
  
   
   
  • 1

3. Turn on the firewall:

If the previous step is off, enter the command to enable the firewall:

`systemctl start firewalld.service`

  
  
   
   
  • 1

4. Open the port

Enter the command to open port 8000:

`firewall-cmd --zone=public --add-port=8000/tcp --permanent && firewall-cmd --reload`

  
  
   
   
  • 1

Close port 8000:

`firewall-cmd --zone=public --remove-port=8000/tcp --permanent`

  
  
   
   
  • 1

Let's explain the previous command:

  • --zone=public: Indicates that the scope is public;
  • --add-port=8080/tcp: Add port 8080 of the tcp protocol;
  • --permanent: Permanently effective; (If there is no such parameter, it can only be maintained within the current service life cycle, and it will be invalid after restarting;)

5. Enter the command to re-enter the configuration:

`firewall-cmd --reload`

  
  
   
   
  • 1

Guess you like

Origin blog.csdn.net/M_TDM/article/details/124863842