CentOS7 [Manage firewall port command]

  1. Check the firewall status:
firewall-cmd --state
  1. Turn on the firewall:
systemctl start firewalld
  1. Stop the firewall:
systemctl stop firewalld
  1. Restart the firewall:
systemctl restart firewalld
  1. Set up the firewall at startup:
systemctl enable firewalld

6. Disable starting the firewall at boot:

systemctl disable firewalld
  1. Reload firewall rules:
firewall-cmd --reload
  1. Open ports:
firewall-cmd --zone=public --add-port=<端口号>/tcp --permanent
  1. Remove an open port:
firewall-cmd --zone=public --remove-port=<端口号>/tcp --permanent
  1. View open ports:
firewall-cmd --zone=public --list-ports

If the netstat command is not found on CentOS 7, it may be because the net-tools package is not installed on the system. In newer CentOS 7 distributions, the net-tools package may have been deprecated, so you can try using the ss command instead.

  1. View occupied ports:使用 ss 命令可以列出当前正在使用的端口和与之关联的进程。
ss -tuln
  1. If you just want to see if a specific port is occupied, you can use the following command:
ss -tuln | grep <端口号>

Please make sure that you have sufficient permissions when executing the above command, either using sudo or running the command as root.

Guess you like

Origin blog.csdn.net/Lance_welcome/article/details/130584924