服务状态

systemctl status firewalld.service
$ systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 四 2019-11-28 12:49:13 HKT; 2h 20min ago
     Docs: man:firewalld(1)
 Main PID: 1315 (firewalld)
    Tasks: 2
   CGroup: /system.slice/firewalld.service
           └─1315 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

11月 28 12:49:13 mgr230 systemd[1]: Starting firewalld - dynamic firewall daemon...
11月 28 12:49:13 mgr230 systemd[1]: Started firewalld - dynamic firewall daemon.

启停

systemctl stop firewalld.service
systemctl start firewalld.service
systemctl restart firewalld.service

查看防火墙规则

$ sudo firewall-cmd --list-all 
[sudo] ec 的密码:
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens12
  sources: 
  services: dhcpv6-client ssh
  ports: 15900/tcp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

查询、开放、关闭端口

# 查询端口是否开放
firewall-cmd --query-port=8080/tcp
# 开放80端口
# --get-services
# firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-port=80/tcp
# 移除端口
firewall-cmd --permanent --remove-port=8080/tcp

重启防火墙

# 重启防火墙(修改配置后要重启防火墙)
firewall-cmd --reload


【Tips】通过配置文件来配置 Firewalld
系统本身已经内置了一些常用服务的防火墙规则,/usr/lib/firewalld/services/

注意!请勿编辑/usr/lib/firewalld/services/ ,只有 /etc/firewalld/services 的用户文件可以被编辑。