赞
踩
CentOS5、CentOS6 => 防火墙 => iptables防火墙
CentOS7 => 防火墙 => firewalld防火墙
默认策略 | |
---|---|
trusted | 允许所有数据包 |
home | 拒绝流入的流量,除非与流出的流量相关,允许ssh,mdns,ippclient,amba-client,dhcpv6-client服务通过 |
internal | 等同于home |
work | 拒绝流入的流量,除非与流出的流量相关,允许ssh,ipp-client,dhcpv6-client服务通过 |
public | 拒绝流入的流量,除非与流出的流量相关,允许ssh,dhcpv6-client服务通过 |
external | 拒绝流入的流量,除非与流出的流量相关,允许ssh服务通过 |
dmz | 拒绝流入的流量,除非与流出的流量相关,允许ssh服务通过 |
block | 拒绝流入的流量,除非与流出的流量相关,非法流量采取拒绝操作 |
drop | 拒绝流入的流量,除非与流出的流量相关,非法流量采取丢弃操作 |
基本语法:
# firewall-cmd [选项1] [选项2] [...N]
查看防火墙默认的区域(zone)
[root@linux ~]# firewall-cmd --get-default-zone
public
查看所有支持的区域(zones)
[root@linux ~]# firewall-cmd --get-zones
block dmz drop external home internal public trusted work
查看当前区域的规则设置
[root@linux ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: ens33
sources:
services: dhcpv6-client ssh
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
查看所有区域的规则设置
[root@linux ~]# firewall-cmd --list-all-zones
block
target: %%REJECT%%
icmp-block-inversion: no
interfaces:
sources:
services:
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
① 通过服务的名称添加规则
# firewall-cmd --zone=public --add-service=服务的名称
备注:服务必须存储在/usr/lib/firewalld/services目录中
案例:
[root@linux ~]# firewall-cmd --zone=public --add-service=http success [root@linux ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client http ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
[root@linux ~]# firewall-cmd --zone=public --remove-service=http success [root@linux ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
② 通过服务的端口号添加规则
firewall-cmd --zone=public --add-port=端口号/tcp
[root@linux ~]# ss -naltp |grep httpd LISTEN 0 128 [::]:80 [::]:* 允许80端口通过firewalld防火墙 [root@linux ~]# firewall-cmd --zone=public --add-port=80/tcp success [root@linux ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: 80/tcp protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
[root@linux ~]# firewall-cmd --zone=public --remove-port=80/tcp success [root@linux ~]# firewall-cmd --list-all public (active) target: default icmp-block-inversion: no interfaces: ens33 sources: services: dhcpv6-client ssh ports: protocols: masquerade: no forward-ports: source-ports: icmp-blocks: rich rules:
在Linux的新版防火墙firewalld中,其模式一共分为两大类:运行模式(临时模式)+ 永久模式。
运行模式:不会把规则保存到防火墙的配置文件中,设置完成后立即生效
永久模式:会把规则写入到防火墙的配置文件中,但是其需要reload重载后才会立即生效
根据服务名称添加规则(永久)
firewall-cmd --zone=public --add-service=服务名称 --permanent
firewall-cmd --reload
根据端口号添加规则(永久)
firewall-cmd --zone=public --add-port=服务占用的端口号 --permanent
firewall-cmd --reload
案例:把80端口添加到firewalld防火墙规则中,要求永久生效
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload
firewall-cmd --list-all
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。