Centos7 view open port command and open port number

Time:2020-11-17

1. View the open ports

firewall-cmd --list-ports

2. Open a single port(the firewall needs to be restarted after opening)

firewall-cmd --zone=public --add-port=8080/tcp --permanent

3. Open multiple ports(the firewall needs to be restarted after opening)

firewall-cmd --zone=public --add-port=20000-29999/tcp --permanent

(– permanent refers to permanent effect, not to single validity (restart failure))

4. Close the port(the firewall needs to be restarted to take effect after shutting down)

firewall-cmd --zone=public --remove-port=8080/tcp --permanent

5. Check whether the port is open

firewall-cmd --zone= public --query-port=80/tcp

6. Check firewall status (two ways)

firewall-cmd --state

systemctl status firewalld

7. Turn on the firewall

systemctl start firewalld

8. Restart the firewall(Two ways)

firewall-cmd --reload

systemctl restart firewalld

9. Set boot upfirewall

systemctl enable firewalld

10. Check whether the firewall setting is successful

systemctl is-enabled firewalld;echo $?

11. ProhibitionfirewallBoot up

systemctl disable firewalld

12. Stopfirewall

systemctl stop firewalld