查看防火墙状态
[root@VM_0_3_centos /]# firewall-cmd --state
not running
[root@VM_0_3_centos /]# sudo systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
启动防火墙
[root@VM_0_3_centos /]# sudo systemctl start firewalld
[root@VM_0_3_centos /]# sudo systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: active (running) since Sun 2019-02-03 21:57:37 CST; 2s ago
Docs: man:firewalld(1)
Main PID: 20727 (firewalld)
CGroup: /system.slice/firewalld.service
└─20727 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Feb 03 21:57:36 VM_0_3_centos systemd[1]: Starting firewalld - dynamic firewall daemon...
Feb 03 21:57:37 VM_0_3_centos systemd[1]: Started firewalld - dynamic firewall daemon.
[root@VM_0_3_centos /]#
关闭防火墙
[root@VM_0_3_centos /]# systemctl stop firewalld.service
[root@VM_0_3_centos /]# sudo systemctl start firewalld
[root@VM_0_3_centos /]#
设置防火墙开机启动
root@VM_0_3_centos /]# systemctl enable firewalld.service
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/basic.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[root@VM_0_3_centos /]#
查看端口是否开放
[root@VM_0_3_centos /]# firewall-cmd --query-port=80/tcp
no
[root@VM_0_3_centos /]#
开放端口
[root@VM_0_3_centos /]# firewall-cmd --zone=public --add-port=80/tcp --permanent
success
[root@VM_0_3_centos /]#
重新加载防火墙
firewall-cmd --reload
查看所有开放的端口
[root@VM_0_3_centos services]# firewall-cmd --zone=public --list-ports
3306/tcp 80/tcp
[root@VM_0_3_centos services]#