width margin 安全区 停止 一道 roman cto 端口转发 失效
防火墙策略管理(firewall)
作用:隔离
局域网和外网之间
阻止入站,允许出站
软件防火墙
系统服务:firewalld
管理工具:firewall-cmd(命令工具、 Linux7),firewell-config(图形工具)
查看防火墙服务状态
Active: active (running) since 三 2017-11-01 11:37:48 CST; 4h 6min ago
[root@server0 ~]# systemctl status firewalld.service
firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled)
└─477 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
Main PID: 477 (firewalld)
CGroup: /system.slice/firewalld.service
11 月 01 11:37:49 localhost systemd[1]: Started firewalld - dynamic firewall....
Hint: Some lines were ellipsized, use -l to show in full.
预设安全区域
根据所在的网络场所区分,预设保护规则集
public: 仅允许访问本机的 sshd 等少数几个服务(默认进入的区域)
trusted:允许任何访问
block:拒绝任何来访请求
drop:丢弃任何来访的数据包
例:
防火墙判断的规则:(匹配及停止)
[root@server0 ~]# firewall-cmd --get-default-zone
public
[root@server0 ~]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0 eth1 eth2 team0
sources:
services: dhcpv6-client ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
1. 首先看请求(客户端)当中的源 IP 地址,所有区域中是否有对于该 IP 地址的策略,如果有则该请求进入该区域
2. 如果没有,进入默认区
[root@server0 ~]# firewall-cmd --zone=public --add-
--add-forward-port= --add-masquerade --add-service=
--add-icmp-block= --add-port= --add-source=
--permanent 选项 :永久生效,没有此参数重启后失效
--add-interface= --add-rich-rule
[root@server0 ~]# firewall-cmd --zone=public --add-service=http #开启 http 服务
success
[root@server0 ~]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0 eth1 eth2 team0
sources:
services: dhcpv6-client http ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
[root@server0 ~]# firewall-cmd --zone=public --add-service=ftp #开启 ftp 服务
success
[root@server0 ~]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0 eth1 eth2 team0
sources:
services: dhcpv6-client ftp http ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
[root@server0 ~]# firewall-cmd --reload #重新加载配置
success
[root@server0 ~]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0 eth1 eth2 team0
sources:
services: dhcpv6-client ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
修改默认区域
[root@server0 ~]# firewall-cmd --permanent --zone=public --add-service=ftp #开启永久 ftp 服务
success
[root@server0 ~]# firewall-cmd --permanent --zone=public --add-service=http #开启永久 http 服务
success
[root@server0 ~]# firewall-cmd --reload #重新加载配置
success
[root@server0 ~]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0 eth1 eth2 team0
sources:
services: dhcpv6-client ftp http ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
firewall-cmd --set-default-zone = 区域名
例:
开网段
[root@localhost ~]# ping 172.25.0.11
PING 172.25.0.11 (172.25.0.11) 56(84) bytes of data.
64 bytes from 172.25.0.11: icmp_seq=1 ttl=64 time=0.174 ms
[root@server0 ~]# firewall-cmd --set-default-zone=block
success
[root@localhost ~]# ping 172.25.0.11
PING 172.25.0.11 (172.25.0.11) 56(84) bytes of data.
From 172.25.0.11 icmp_seq=1 Destination Host Prohibited
[root@server0 ~]# firewall-cmd --set-default-zone=drop
success
[root@localhost ~]# ping 172.25.0.11
PING 172.25.0.11 (172.25.0.11) 56(84) bytes of data.
实现本机的端口映射
[root@server0 ~]# firewall-cmd --permanent --zone=public --add-source=172.25.0.10
success
[root@server0 ~]# firewall-cmd --reload
success
[root@server0 ~]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0 eth1 eth2 team0
sources: 172.25.0.10
services: dhcpv6-client ftp http ssh
ports:
masquerade: no
forward-ports:
icmp-blocks:
rich rules:
本地应用的端口重定向(端口 1--> 端口 2)
从客户机访问端口 1 的请求,自动映射到本机端口 2
比如, 访问以下两个地址可以看到相同的页面:
例:
http://server0.example.com:5423/
http://server0.example.com/
防火墙应对方法
[root@server0 ~]# firewall-cmd --permanent --zone=public --add-forward-port=port=5423:proto=tcp:toport=80
success
[root@server0 ~]# firewall-cmd --reload
success
[root@server0 ~]# firewall-cmd --zone=public --list-all
public (default, active)
interfaces: eth0 eth1 eth2 team0
sources: 172.25.0.10
services: dhcpv6-client ftp http ssh
ports:
masquerade: no
forward-ports: port=5423:proto=tcp:toport=80:toaddr=
icmp-blocks:
rich rules:
方式 1:默认区域 block,允许的放入 trusted
方式 2:默认区域 trusted, 拒绝的放入 block
在 RHCE 的考试中会涉及到各种服务的配置 为了是考试变的简单
可以将防火墙的应对方法设置为 默认区域 trusted, 拒绝的放入 block
在两台虚拟机上执行如下操作
# firewall-cmd --set-default-zone=trusted
在 RHCE 的考试中有一道题目是:
在 RCHE7 的考试中有一道考试题目是:
配置 SSH 访问
按以下要求配置 SSH 访问:
用户能够从域 example.com(这个域名考试会改变) 内的客户端 SSH 远程访问您的两个虚拟机系统
在域 my133t.org (这个域名考试会改变) 内的客户端不能访问您的两个虚拟机系统
这道题也可以用通过配置防火墙策略 将这个网段放入 block 区域
例如 my133t.org 对应的网段为 172.34.0.0 在两台虚拟机上执行如下操作
# firewall-cmd --permanent --add-source=172.34.0.0/24 --zone=block
* 如果想要通过配置 SSH 服务来完成这道题 可以访问 http://blog.51cto.com/13558754/2058361
在 RCHE7 的考试中有一道考试题目是:
配置防火墙端口转发
在系统 server 0 上配置端口转发,要求如下:
在 172.25.0.0/24 网络中的系统,访问 server0 的本地端口 5423 将被转发到 80
此设置必须永久有效
# firewall-cmd --permanent --zone=trusted --add-forward- port=port=5423:proto=tcp:toport=80
注意 凡是执行配置防火墙策略中 带有 --permanent 选项的命令时 都要执行如下操作
# firewall-cmd --reload #重新加载配置
全面分析 RHCE7(红帽认证工程师)考试题目之 ---Firewall(防火墙) 篇
来源: http://www.bubuko.com/infodetail-2453422.html