RHEL7支持的防火墙:
IPTABLES
IP6TABLES
FIREWALL
EBTABLES

命令模式:
firewall-cmd

图形化界面:

firewall-config

Firewall的区域zone:
Drop 任何流入网络的包都被丢弃,并且不给出任何响应
Block 任何进入的网络都被拒绝,会给出响应。
Public 系统默认zone,允许指定的规则。
External 用在路由器等启用伪装的外部网络
Dmz 允许隔离区dmz中的电脑有限地被外界网络访问
Work 工作网络,允许受信任的计算机被限制的进入连接,类似workgroup
Home 家庭网络,同上,类似homegroup
Internal 内部网络,同上,针对所有互联网用户。
Trusted 允许所有网络连接。

一些常用的基本操作命令
#systemctl state/status/start/stop firewalld
#systemctl mask iptables    ---RHEL7中建议使用firewalld,把其它三个防火墙mask掉
#systemctl mask ip6tables
#systemctl mask ebtables
#firewall-cmd --help
#firewall-cmd --list-all     --列出默认zone-public中的防火墙规则

[root@rhel1 ~]# firewall-cmd --list-all
public (active)
   target: default
   icmp-block-inversion: no
   interfaces: enp0s3 enp0s8
   sources:
   services: ssh dhcpv6-client mysql ftp dns smtp samba nfs rpc-bind mountd
   ports: 139/tcp 445/tcp 20048/tcp 20049/tcp 6666/tcp 8888/tcp 12345/tcp 12345/udp 6666/udp 3260/tcp 123/udp 80/tcp
   protocols:
   masquerade: no
   forward-ports:
   source-ports:
   icmp-blocks:
   rich rules:

#firewall-cmd --get-active-zones --列出活动有zone,也就是配置过防火墙策略的zone

[root@rhel1 ~]# firewall-cmd --get-active-zones
public
   interfaces: enp0s3 enp0s8
block
   sources: 192.168.100.0/24

#firewall-cmd --zone=block --add-source=192.168.100.2     --来自这个IP的数据包全部被拒绝了。

从RHEL2客户机ping RHEL1测试:

[root@rhel2 ~]# ping 192.168.100.1
PING 192.168.100.1 (192.168.100.1) 56(84) bytes of data.
From 192.168.100.1 icmp_seq=1 Destination Host Prohibited   --提示被拒绝。
From 192.168.100.1 icmp_seq=2 Destination Host Prohibited

# firewall-cmd --zone=block --remove-source=192.168.100.2  --删除防火墙策略

# firewall-cmd --zone=drop --add-source=192.168.100.2   --来自source网络的数据包全部被丢弃了。从rhel2 ping rhel1 测试时,没任何提示。从这可以看出block和drob的区别。生产环境一般用drop,就是直接丢弃数据包,不返回任何提示,这样更安全。

#firewall-cmd --zone=work --list-all   --列出指定zone中已配置的防火墙规则

[root@rhel1 ~]# firewall-cmd --zone=block --list-all
block (active)
   target: %%REJECT%%
   icmp-block-inversion: no
   interfaces:
   sources: 192.168.100.2
   services:
   ports:
   protocols:
   masquerade: no
   forward-ports:
   source-ports:
   icmp-blocks:
   rich rules:

#firewall-cmd --get-default-zone   --查看默认zone

[root@rhel1 ~]# firewall-cmd --get-default-zone
public

#firewall-cmd --set-default-zone=public    --设置默认zone,添加防火墙策略时,如果不指定zone参数,则默认添加到public区域中
#firewall-cmd --add-service=http   --添加服务
#firewall-cmd --remove-service=http  --删除服务
#firewall-cmd --add-port=8080/tcp   --添加端口
#firewall-cmd --remove-port=8080/tcp --删除端口
#firewall-cmd --add-source=192.168.100.0/24  --添加源地址
#firewall-cmd --remove-source=192.168.100.0/24
#firewall-cmd --add-icmp-block=echo-request     --添加echo-request屏蔽
#firewall-cmd --remove-icmp-block=echo-request
#firewall-cmd --zone=work --add-service=http    ---指定zone添加服务
#firewall-cmd --permanent --zone=work --add-service=http   --加permanent参数,表示永久生效,即,将防火墙策略写入到配置文件/etc/firewalld下。否则重启防火墙或重启服务器之后,防火墙策略就不生效了。
#firewall-cmd –reload   --重读配置文件

# firewall-cmd --get-zone-of-interface=enp0s3 --查看指定接口的Zone信息
public
#firewall-cmd --zone=public --list-interfaces   --查看指定级别的接口
enp0s3

# firewall-cmd --zone=public --list-all   --查看指定zone的所有信息

# firewall-cmd --zone=public --add-interface=eth0 --添加某接口到指定zone

===============

配置public zone端口转发

# firewall-cmd --zone=public --add-masquerade  --打开端口转发

# firewall-cmd --zone=public --add-forward-port=port=12345:proto=tcp:toport=80  --将tcp12345转发到80端口

转发 22 端口数据至另一个 ip 的相同端口上
# firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toaddr=192.168.1.100

转发 22 端口数据至另一ip的 2055 端口上
# firewall-cmd --zone=public --add-forward-port=port=22:proto=tcp:toport=2055:toaddr=192.168.1.100

富规则端口转发

把80端口转向8899:

# firewall-cmd –permanent --add-rich-rule="rule family="ipv4" forward-port port="80" protocol="tcp" to-port="8899""
#firewall-cmd --reload

其它富规则例子(拒绝192.168.100.111通过ssh方式连接进来):

[root@localhost ~]# firewall-cmd --permanent --add-rich-rule="rule family=ipv4 source address=192.168.100.111/24 service name=ssh reject"
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules: [root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --list-all
public (active)
target: default
icmp-block-inversion: no
interfaces: enp0s3
sources:
services: ssh dhcpv6-client
ports:
protocols:
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
rule family="ipv4" source address="192.168.100.111/24" service name="ssh" reject
[root@localhost ~]#
firewall-cmd --permanent --add-rich-rule="这里面的内容也可以不加引号,系统会自动添加引号“

防火墙 Firewalld的更多相关文章

  1. Centos 7防火墙firewalld开放80端口(转)

    开启80端口 firewall-cmd --zone=public --add-port=80/tcp --permanent 出现success表明添加成功 命令含义: --zone #作用域 -- ...

  2. fedora/centos7防火墙FirewallD详解

    1 使用 FirewallD 构建动态防火墙 1.1 “守护进程” 1.2 静态防火墙(system-config-firewall/lokkit) 1.3 使用 iptables 和 ip6tabl ...

  3. 第一篇:动态防火墙firewalld和静态防火墙iptables

    动态防火墙firewalld firewalld提供了一个动态管理的防火墙,它支持网络(network)/防火墙区域(firewall zones )来定义网络连接( network connecti ...

  4. 防火墙firewalld的基础操作

    防火墙Firewalld.iptables 1.systemctl模式 systemctl status firewalld #查看状态 2 systemctl start firewalld #启动 ...

  5. centos 7.0 修改ssh默认连接22端口 和 添加防火墙firewalld 通过端口

    首先 先做的就是 修改ssh的默认端口22 需要修改文件 /etc/ssh/sshd_config 使用命令 vi /etc/ssh/sshd_config [root@localhost ~]# v ...

  6. Centos 7防火墙firewalld开放80端口

    开启80端口 1.firewall-cmd --zone=public --add-port=80/tcp --permanent  出现success表明添加成功 命令含义: --zone #作用域 ...

  7. linux 防火墙--firewalld学习

    firewalld是centos7默认的防火墙,相比于iptables重要的优势: 1 支持动态更新: 2 不用重启服务: 同时增加了防火墙的“zone”概念,具体差异没做过多了解,这篇文章只记录fi ...

  8. 【Centos7】5分钟理解防火墙firewalld

    Centos7中默认将原来的防火墙iptables升级为了firewalld,firewalld跟iptables比起来至少有两大好处: 1.firewalld可以动态修改单条规则,而不需要像ipta ...

  9. Centos 7 防火墙firewalld命令

    今天自己在Hyper-v下搭建三台Linux服务器集群,用于学习ELKstack(即大数据日志解决技术栈Elasticsearch,Logstash,Kibana的简称),下载的Linux版本为cen ...

  10. CentOS7 防火墙firewalld详细操作

    1.firewalld的基本使用 启动: systemctl start firewalld 查看状态: systemctl status firewalld  停止: systemctl disab ...

随机推荐

  1. cannot ignore cache if it is not cached [ArcGIS Catalog 10]

    由于我把缓存重命名,重启地图服务,再Caching中不再显示地图缓存了,我直接创建新的地图缓存,没想到出现了: 不知道怎么回事. 只好,把缓存 重新改名成原来的名字,然后,删除缓存,再建立缓存.

  2. swift3.0:CoreData的使用

    一.介绍 CoreData不像slqite3那样编写代码繁琐,同时避免了使用了SQL语句的麻烦,也可以回避使用C语言的语法,降低了iOS开发的技术门槛. CoreData可降低开发成本,提高代码质量. ...

  3. B样条

    在数学的子学科数值分析里,B-样条是样条曲线一种特殊的表示形式.它是B-样条基曲线的线性组合.B-样条是贝兹(贝塞尔)曲线的一种一般化,可以进一步推广为非均匀有理B样条(NURBS),使得我们能给更多 ...

  4. C#操作json类型数据

    将对象序列化为 JavaScript 对象表示法 (JSON),并将 JSON 数据反序列化为对象. 此类不能继承. // msdn 例子: namespace SL_DataContractJson ...

  5. 绝对定位常见误区:position:absolute相对于谁定位、及当溢出时怎么隐藏

    1.绝对定位元素溢出父元素,怎么隐藏问题? 通常,为了让DIV子元素超出部分隐藏,都是在父元素设置overflow:hidden,这样即可防止子元素撑开父元素,使子元素能够溢出隐藏! 但是,对于pos ...

  6. 操作系统重点双语阅读 - 上下文切换 Context Switch

    The context is represented in the PCB of the process. It includes the value of the CPU registers, th ...

  7. Linq-Contains查询

    customers.Where(c => c.Name.Contains("john"));

  8. linux运维需要掌握的基础知识

    踏入linux运维工程师这一职业,其实有很多工具技能需要掌握,下面我来给大家一一介绍. 1.shell脚本和另一个脚本语言,shell是运维人员必须具备的,不懂这个连入职都不行,至少也要写出一些系统管 ...

  9. Direct2D教程IV——笔刷(Brush)对象

    目前博客园中成系列的Direct2D的教程有 1.万一的 Direct2D 系列,用的是Delphi 2009 2.zdd的 Direct2D 系列,用的是VS中的C++ 3.本文所在的 Direct ...

  10. Horizon Is Easy, Horizon Is Complex

    本文出自我的同事兼基友@monsterxx03 之手,本人稍作润色 Horizon Is Easy, Horizon Is Complex 如果要用一句话来概括Openstack Dashboard项 ...