实验环境为CentOS7.5
[root@localhost ~]# systemctl disable firewalld #禁用防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# systemctl enable firewalld #启用防火墙,开机启动
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@localhost ~]# systemctl stop firewalld #关闭防火墙
[root@localhost ~]# systemctl start firewalld#启动防火墙
[root@localhost ~]# systemctl restart firewalld#重启防火墙
[root@localhost ~]# systemctl status firewalld#查看防火墙状态
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since 一 2019-10-28 10:02:07 CST; 1min 13s ago
Docs: man:firewalld(1)
Main PID: 3101 (firewalld)
CGroup: /system.slice/firewalld.service
└─3101 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
10月 28 10:02:07 localhost.localdomain systemd[1]: Starting firewalld - dynamic firewall daemon...
10月 28 10:02:07 localhost.localdomain systemd[1]: Started firewalld - dynamic firewall daemon.
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent#允许80端口tcp协议通过防火墙
[root@localhost ~]# firewall-cmd –reload #更新防火墙规则
success
[root@localhost ~]# firewall-cmd --zone=public --query-port=80/tcp #查看80端口
yes
[root@localhost ~]# firewall-cmd --zone=public --list-ports #查看所有打开端口
80/tcp
[root@localhost ~]# firewall-cmd --zone=public --remove-port=80/tcp --permanent#删除端口
success