1、系统环境
[root@wrx ~]# uname -sir Linux 3.10.0-693.el7.x86_64 x86_64 [root@wrx ~]# cat /proc/version Linux version 3.10.0-693.el7.x86_64
2、查看是否已经安装firewalld
[root@wrx ~]# rpm -qa | grep firewall firewalld-filesystem-0.4.4.4-6.el7.noarch python-firewall-0.4.4.4-6.el7.noarch firewalld-0.4.4.4-6.el7.noarch
3、firewall基本使用
#查看firewall状态 [root@wrx ~]# systemctl status firewalld #开启 [root@wrx ~]# systemctl start firewalld #关闭 [root@wrx ~]# systemctl stop firewalld #重启 [root@wrx ~]# systemctl restart firewalld #查看是否加入开机启动 [root@wrx ~]# systemctl list-unit-files | grep firewalld firewalld.service enabled #开启开机启动 [root@wrx ~]# systemctl enable firewalld #禁止开机启动 [root@wrx ~]# 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@wrx ~]# systemctl list-unit-files | grep firewalld firewalld.service disabled
4、配置防火墙
#查看帮助 [root@wrx ~]# firewall-cmd --help #查看状态 [root@wrx ~]# firewall-cmd --state #查看版本 [root@wrx ~]# firewall-cmd --version #查看所有打开的端口 [root@wrx ~]# firewall-cmd --zone=public --list-port #更新防火墙规则 [root@wrx ~]# firewall-cmd --reload #查看区域信息 [root@wrx ~]# firewall-cmd --get-active-zones #查看指定接口所属区域 [root@wrx ~]# firewall-cmd --get-zone-of-interface=eth0 #拒绝所有包 [root@wrx ~]# firewall-cmd --panic-on #取消拒绝所有包 [root@wrx ~]# firewall-cmd --panic-off #查看是否拒绝 [root@wrx ~]# firewall-cmd --query-panic #添加开放端口 #永久开放22端口,parmanent表示永久 [root@wrx ~]# firewall-cmd --add-port=22/tcp --permanent #查看 [root@wrx ~]# firewall-cmd --zone=public --query-port=22/tcp #删除 [root@wrx ~]# firewall-cmd --zone=public --remove-port=22/tcp --permanent
5、22端口开放与关闭操作
#开放22端口、永久、tcp [root@wrx ~]# firewall-cmd --zone=public --query-port=22/tcp no [root@wrx ~]# firewall-cmd --add-port=22/tcp --permanent success [root@wrx ~]# firewall-cmd --reload success [root@wrx ~]# firewall-cmd --zone=public --query-port=22/tcp yes #移除 [root@wrx ~]# firewall-cmd --zone=public --query-port=22/tcp yes [root@wrx ~]# firewall-cmd --remove-port=22/tcp --permanent success [root@wrx ~]# firewall-cmd --reload success [root@wrx ~]# firewall-cmd --zone=public --query-port=22/tcp no