- Check the firewall status:
firewall-cmd --state
- Turn on the firewall:
systemctl start firewalld
- Stop the firewall:
systemctl stop firewalld
- Restart the firewall:
systemctl restart firewalld
- Set up the firewall at startup:
systemctl enable firewalld
6. Disable starting the firewall at boot:
systemctl disable firewalld
- Reload firewall rules:
firewall-cmd --reload
- Open ports:
firewall-cmd --zone=public --add-port=<端口号>/tcp --permanent
- Remove an open port:
firewall-cmd --zone=public --remove-port=<端口号>/tcp --permanent
- 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.
- View occupied ports:
使用 ss 命令可以列出当前正在使用的端口和与之关联的进程。
ss -tuln
- 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.