CentOS firewall instructions

Time:2020-4-4

CentOS firewall instruction


1. View firewalld status

  • To view the firewalld service status instruction:
systemctl status firewalld

CentOS firewall instructions

  • To view the firewalld status command:
firewall-cmd --state

CentOS firewall instructions


2. Turn on, restart and turn off the firewalld service

  • Opening:
service firewalld start
  • Close:
service firewalld stop
  • Restart:
service firewalld restart

CentOS firewall instructions


3. Query, open and close the firewalld port

  • Query all open ports:
firewall-cmd --list-all

CentOS firewall instructions

  • Query whether a port is open:
Firewall CMD -- Query port = [port] / TCP

CentOS firewall instructions

  • Open port:
Firewall CMD -- permanent -- add port = [port] / TCP
  • Close port:
Firewall CMD -- permanent -- remove port = [port] / TCP
  • Refresh service (refresh is required after opening and closing ports):
firewall-cmd --reload

CentOS firewall instructions


PS:Error reporting modulenotfounderror: no module named ‘GI’
Execute command:sudo vim /usr/bin/firewall-cmd, open the file and change the first line of Python to python2
Refer to: centos7 firewall CMD command error modulenotfounderror: no module named ‘GI’