Centos looks at port occupancy and the open port command for details

  • 2020-05-17 07:30:12
  • OfStack

The Centos command to view port occupancy, such as port 80, USES the following command:


lsof -i tcp:80

List all ports


netstat -ntlp

1. Open port (take port 80 as an example)

Method 1:


/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT   Write to modify 


/etc/init.d/iptables save   Save the changes 


service iptables restart   Restart the firewall and the changes take effect 

Method 2:

vi /etc/sysconfig/iptables open the configuration file and add the following statements:


 
Copy the code The following code :
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT Restart the firewall and the modification is complete

2. Close the port

Method 1:


 /sbin/iptables -I INPUT -p tcp --dport 80 -j DROP   Write to modify 
 
 /etc/init.d/iptables save   Save the changes 
 
 service iptables restart   Restart the firewall and the changes take effect 

Method 2:

vi /etc/sysconfig/iptables open the configuration file and add the following statements:


Copy the code The following code :
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j DROP Restart the firewall and the modification is complete

3. Check port status


 /etc/init.d/iptables status

Related articles: