firewalld 介绍

防火墙守护 firewalld 服务引入了一个信任级别的概念来管理与之相关联的连接与接口。它支持 ipv4 与 ipv6,并支持网桥,采用 firewall-cmd (command) 或 firewall-config (gui) 来动态的管理 kernel netfilter 的临时或永久的接口规则,并实时生效而无需重启服务。

Firewall 能将不同的网络连接归类到不同的信任级别,Zone 提供了以下几个级别
drop: 丢弃所有进入的包,而不给出任何响应
block: 拒绝所有外部发起的连接,允许内部发起的连接
public: 允许指定的进入连接
external: 同上,对伪装的进入连接,一般用于路由转发
dmz: 允许受限制的进入连接
work: 允许受信任的计算机被限制的进入连接,类似 workgroup
home: 同上,类似 homegroup
internal: 同上,范围针对所有互联网用户
trusted: 信任所有连接

firewall-cmd命令需要firewalld进程处于运行状态。我们可以使用systemctl status/start/stop/restart firewalld来控制这个守护进程。firewalld进程为防火墙提供服务。
当我们修改了某些配置之后(尤其是配置文件的修改),firewall并不会立即生效。可以通过两种方式来激活最新配置systemctl restart firewalld和firewall-cmd --reload两种方式,前一种是重启firewalld服务,建议使用后一种“重载配置文件”。重载配置文件之后不会断掉正在连接的tcp会话,而重启服务则会断开tcp会话。

1.1 服务使用

systemctl start firewalld    # 启动,
systemctl enable firewalld   # 开机启动
systemctl stop firewalld     # 关闭
systemctl disable firewalld  # 取消开机启动

1.2 查看防火墙配置

[root@linux-node1 ~]# firewall-cmd --list-all
public
target: default
icmp-block-inversion: no
interfaces:
sources:
services: dhcpv6-client ssh
ports: /tcp /tcp /tcp /tcp /tcp /tcp /tcp /tcp /tcp #开放的端口
protocols:
masquerade: yes #端口转发,必须开启这个
forward-ports: port=:proto=tcp:toport=:toaddr=172.16.221.0 #端口转发设置
port=:proto=tcp:toport=:toaddr=172.16.220.252
source-ports:
icmp-blocks:
rich rules:
rule family=" protocol="tcp" accept
rule family=" protocol="tcp" accept

1.3 开启端口&关闭端口

firewall-cmd --remove-port=/tcp --permanent # 阻止通过tcp访问80
firewall-cmd --add-port=/udp --permanent    # 开放通过udp访问80

1.4 查看开放的端口

[root@linux-node1 ~]# firewall-cmd --list-ports  # 查看开放的端口
/tcp /tcp /tcp /tcp /tcp /tcp /tcp /tcp /tcp

1.5 永久修改

firewall-cmd --add-port=/tcp --permanent ##如果需要修改后,必须添加--permanent

1.6 重载服务

所有防火墙配置完毕后,需要重载服务

firewall-cmd --reload

1.7 伪装IP

防火墙可以实现伪装IP的功能,端口转发就会用到这个功能。

firewall-cmd --query-masquerade              # 检查是否允许伪装IP
firewall-cmd --add-masquerade --permanent    # 允许防火墙伪装IP
firewall-cmd --remove-masquerade --permanent # 禁止防火墙伪装IP

1.8 端口转发

端口转发可以将指定地址访问指定的端口时,将流量转发至指定地址的指定端口。

转发的目的如果不指定ip的话就默认为本机,如果指定了ip却没指定端口,则默认使用来源端口。
如果配置好端口转发之后不能用,可以检查下面两个问题:
- 比如我将80端口转发至8080端口,首先检查本地的80端口和目标的8080端口是否开放监听了
- 其次检查是否允许伪装IP,没允许的话要开启伪装IP
# 将80端口的转发至本机8080

firewall-cmd --add-forward-port=port=:proto=tcp:toport= --permanent

# 将80端口转发至192.168.0.1的8080端口

firewall-cmd --add-forward-port=port=:proto=tcp:toaddr= --permanent

1.9 移除端口转发

firewall-cmd --remove-forward-port=port=:proto=tcp:toaddr= --permanent
firewall-cmd --reload

防火墙系列之firewall的更多相关文章

  1. CentOS 7 下 安装Webmin 启动防火墙失败----Applying firewall rules:iptables-restore:line 2 failed

    最近学习CentOS 7 系统管理,使用的是<CentOS 6.X系统管理实战宝典>一书------因为网购的CentOS 7 的书还没有送到 O(‘  ’!!)O~ (1)先使用yum方 ...

  2. linux防火墙查看状态firewall、iptable

    一.iptables防火墙1.基本操作 # 查看防火墙状态 service iptables status # 停止防火墙 service iptables stop # 启动防火墙 service ...

  3. 【Linux】- CentOS 防火墙iptables和firewall

    1 iptables防火墙 1.1 基本操作 # 查看防火墙状态 service iptables status   # 停止防火墙 service iptables stop   # 启动防火墙 s ...

  4. 【Redhat系列linux防火墙工具】firewalld与iptables防火墙工具的激烈碰撞

    前言 iptables与firewalld防火墙管理工具在linux发行版Redhat7系列使用较为广泛. UFW则是在linux发行版Ubuntu下进行管理防火墙的一款管理工具. 在选用防火墙工具的 ...

  5. 如何将centos7自带的firewall防火墙更换为iptables防火墙

    用惯了centos6的iptables防火墙,对firewall太无感了,那么如何改回原来熟悉的iptables防火墙呢? 1.关闭firewall防火墙 [root@centos7 html]# s ...

  6. CentOS7 firewall与iptables防火墙的使用与开放端口

    如何关闭firewall并开启iptables防火墙 如何使用firewall防火墙 如何关闭firewall并开启iptables防火墙 1.停止firewall systemctl stop fi ...

  7. centOS服务器-firewall防火墙开放端口

    前言 日常开发中,我们常常会因为服务器各种端口未开放出现各种问题,下面我们就来简单了解下服务器上的端口开放!!! 作为一个后台开发,日常接触最多的除了代码就是服务器了: 产品:谁谁, 线上有个功能报错 ...

  8. 【Azure API 管理】APIM集成内网虚拟网络后,启用自定义路由管理外出流量经过防火墙(Firewall),遇见APIs加载不出来问题

    问题描述 使用 Azure 虚拟网络,Azure APIM 可以管理无法通过 Internet 访问的 API,达到以保护企业内部的后端API的目的.在虚拟网络中,启用网络安全组(NSG:Networ ...

  9. WAF(Web Appliction Firewall) Bypass Technology Research

    catalog . What is Firewall . Detecting the WAF . Different Types of Encoding Bypass . Bypass本质 1. Wh ...

随机推荐

  1. tomcat环境部署

    环境说明 系统版本     CentOS 7.2 x86_64 软件版本     jdk-8u171 tomcat-8.0.27 1.tomcat介绍及软件包准备 Tomcat是Apache软件基金会 ...

  2. 访问vector元素方法的效率比较(转)

    LInux下: gcc 4.47,red hat6 #include<iostream> #include<vector> #include<time.h> usi ...

  3. POJ 3221 Diamond Puzzle(BFS)

    Description A diamond puzzle is played on a tessellated hexagon like the one shown in Figure 1 below ...

  4. 关于Java异常java.lang.OutOfMemoryError: PermGen space

    内容来源: http://blog.csdn.net/fengyie007/article/details/1780375 PermGen space的全称是Permanent Generation ...

  5. wireshark过滤语法总结 (转载)

    做应用识别这一块经常要对应用产生的数据流量进行分析. 抓包采用wireshark,提取特征时,要对session进行过滤,找到关键的stream,这里总结了wireshark过滤的基本语法,供自己以后 ...

  6. mongoDB id 导出,dump,sed,count,mysql import等用法示例

    #count collectiondb.news.count({"lpublishtime":{"$gte":1358697600000}}); #mongo导 ...

  7. charles抓包工具使用指南

    前言 移动APP抓包 PC端抓包 查看模式 其他功能 问题汇总 1. 前言: Charles是一款抓包修改工具,相比起burp,charles具有界面简单直观,易于上手,数据请求控制容易,修改简单,抓 ...

  8. Linux Tools

    WinSCP  http://winscp.net/eng/download.php Xshell 5

  9. 88. Merge Sorted Array【easy】

    88. Merge Sorted Array[easy] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 ...

  10. C++ Primer(第五版)读书笔记 & 习题解答 --- Chapter 2

    Chapter 2.1 1. 数据类型决定了程序中数据和操作的意义. 2. C++定义了一套基本数据类型,其中包括算术类型和一个名为void的特殊类型.算术类型包含了字符.整型.布尔值以及浮点数.vo ...