防火墙的配置--firewalld与iptables

author author     2022-10-04     534

关键词:

管理防火墙的两种方式:firewalldiptables

(1)firewalld ?管理火墙的工具,相对简单 -->windows

(2)iptables ?复杂,功能强大 ?-->route

(1)、(2)不能同时起作用

一、firewalld相关配置

(一)图形化管理

打开图形化管理火墙界面,并打入后台不影响终端使用

[[email protected] ~]# firewall-config &

##runtime 临时生效,立即生效

##permanent 更改配置文件,永久的,重新加载生效

动态监控配置火墙时的动态情况

[[email protected] ~]# watch -n 1 firewall-cmd --list-all

临时更改:在runtime下是临时生效,并且是立刻生效

(1)可以看到初始化支持的服务有dhcpv6-client ssh

?(2)在public区域下勾选http服务,可以看到已经立即生效

永久更改:permanent下,更改配置文件,重新加载后永久生效

(1)在public区域下勾选http服务,可以看到并没有生效

技术分享图片

更改默认指定区域:修改默认区域

(1)一般情况下,默认的区域是public

(2)选择Change Default Zone


开启httpd

[[email protected] ~]# systemctl start httpd


开启httpd

[[email protected] ~]# systemctl start httpd

测试:在浏览器中可以看到无法连接

?技术分享图片

查看防火墙状态:发现没有服务中httpd

?技术分享图片

可通过编写火墙默认的public区域配置文件,来永久开启服务

[[email protected] ~]# vim /etc/firewalld/zones/public.xml

在第行加入http服务: <service name="http"/>

?技术分享图片

重启火墙

[[email protected] ~]# systemctl restart firewalld

再测试

在浏览器中可以看到已经成功访问


(二)命令行管理firewalld

关于网络区域的配置:

?技术分享图片

安装软件

[[email protected] ~]# yum install firewalld firewall-config -y

(1)常用命令

开启防火墙

[[email protected] ~]# systemctl start firewalld

开机自启防火墙

[[email protected] ~]# systemctl enable firewalld

关闭防火墙

[[email protected] ~]# systemctl stop firewalld

开机自动关闭防火墙

[[email protected] ~]# systemctl disable firewalld

查看防火墙状态

[[email protected] ~]# firewall-cmd --state

查看防火墙管理的设备

[[email protected] ~]# firewall-cmd --get-active-zones

查看防火墙生效的区域

[[email protected] ~]# firewall-cmd --get-default-zone

查看防火墙所有的区域

[[email protected] ~]# firewall-cmd --get-zones

列出关于public区域的服务设置

[[email protected] ~]# firewall-cmd --zone=public --list-all

列出关于trusted区域的服务设置

[[email protected] ~]# firewall-cmd --zone=trusted --list-all

列出可使用的服务

[[email protected] ~]# firewall-cmd --get-services

修改默认区域为trusted

[[email protected] ~]# firewall-cmd --set-default-zone=trusted

修改默认区域为public

[[email protected] ~]# firewall-cmd --set-default-zone=public

举例演示:

技术分享图片

?

(2)高级配置

临时添加服务(默认的区域)

[root[email protected] ~]# firewall-cmd --add-service=https

临时删除服务(默认的区域)

[[email protected] ~]# firewall-cmd --remove-service=https ?

?

永久添加服务(默认的区域)

[[email protected] ~]# firewall-cmd --add-service=https ?--permanent

永久删除服务(默认的区域)

[[email protected] ~]# firewall-cmd --remove-service=https ?--permanent

?

临时添加端口(默认的区域)

[[email protected] ~]# firewall-cmd --add-port=8080/tcp

临时删除端口(默认的区域)

[[email protected] ~]# firewall-cmd --remove-port=8080/tcp

?

永久添加端口(默认的区域)

[[email protected] ~]# firewall-cmd --add-port=8080/tcp ?--permanent

永久删除端口(默认的区域)

[[email protected] ~]# firewall-cmd --remove-port=8080/tcp ?--permanent

?

添加接口(默认的区域)

[[email protected] ~]# firewall-cmd --add-interface=eth1

删除接口(默认的区域)

[[email protected] ~]# firewall-cmd --remove-interface=eth1

?

临时拒绝主机172.25.254.86的所有网络连接

[[email protected] ~]# firewall-cmd --add-source=172.25.254.86 --zone=block

永久拒绝主机172.25.254.86的所有网络连接

[[email protected] ~]# firewall-cmd --add-source=172.25.254.86 --zone=block --permanent

不中断连接,重启防火墙策略

[[email protected] ~]# firewall-cmd --reload

中断连接,重启防火墙策略

[[email protected] ~]# firewall-cmd --complete-reload

关闭上述

[[email protected] ~]# firewall-cmd --remove-source=172.25.254.86 --zone=block

[[email protected] ~]# firewall-cmd --remove-source=172.25.254.86 --zone=block --permanent

?

查看firewalld的服务相关配置文件

[[email protected] ~]# cd /usr/lib/firewalld/services/

?技术分享图片

查看firewalld的区域相关配置文件

[[email protected] ~]# cd /etc/firewalld/zones/

技术分享图片

?

二、iptables的相关配置

(1)iptables的常用命令

[[email protected] ~]# yum install iptables-services.x86_64 -y

[[email protected] ~]# systemctl start iptables

[[email protected] ~]# systemctl enable iptables

[[email protected] ~]# systemctl stop iptables

[[email protected] ~]# systemctl disable iptables


(2)iptables的高级配置

关闭firewalld并且开机自动关闭

[[email protected] ~]# systemctl stop firewalld

[[email protected] ~]# systemctl disable firewalld

[[email protected] ~]# systemctl mask firewalld

开启iptables,并且开机自启动

[[email protected] ~]# yum install iptables -y

[[email protected] ~]# systemctl start iptables.service

[[email protected] ~]# systemctl enable iptables.service

列出指定filter表信息


[[email protected] ~]# iptables -t filter -nL

查看配置文件

[[email protected] ~]# vim /etc/sysconfig/iptables

刷新清空iptables

[[email protected] ~]# iptables -F

保存状态

[[email protected] ~]# service iptables save

列出默认表信息

[[email protected] ~]# iptables -nL

所有INPUT服务都丢弃并且不回应

[[email protected] ~]# iptables -P INPUT DROP

技术分享图片

添加接受来自回环地址的

[[email protected] ~]# iptables -A INPUT -i lo -j ACCEPT

添加接受tcp协议80端口的服务

[[email protected] ~]# iptables -A INPUT -p tcp --dport 80 ?-j ACCEPT

添加接受tcp协议22端口的服务

[[email protected] ~]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT

拒绝全部的INPUT链服务

[[email protected] ~]# iptables -A INPUT -j REJECT

查看之,

[[email protected] ~]# iptables -nL

?技术分享图片


?

3、防火墙策略优化

若是第一次访问可以,则第二次访问就不会再问 ,这就是优化状态。

注:系统重启会改变状态的数据包

状态:第一次连接:NEW 连接中:ESTABLISHED ?连接过的:RELATED

[[email protected] ~]# iptables -F ? ? ? ? ? ? ? ? ? ? ?##刷新清空策略

[[email protected] ~]# service iptables ?save ? ? ##保存

[[email protected] ~]# iptables -nL ? ? ? ? ? ? ? ? ? ?##查看

技术分享图片

关于iptables的参数:

-t 指定表

-L 列出表

-A ?永远加在最后一条

-D ?删除某一条链里面的策略

-i ??输入 ?(-i lo 表示是从回环地址进来的)

-o ?输出

-I ??插入到某一条,默认第一条(-I INPUT 3?插入到第三行,不写3的话默认添加到第一个)

-m ?状态

-j ??动作(ACCEPT | REJECT)

-s ?资源(无,则所有)

-P ?策略

-p ?协议

-R ?更改

--dport 端口

-N ?新建一个链

-E ?修改链名称

-X ?删除链

?


第8章iptables与firewalld防火墙(代码片段)

...章分别使用iptables、firewall-cmd、firewall-config和TCPWrappers等防火墙策略配置服务iptables服务把用于处理或过滤流量的策略条目称之为规则,多条规则可以组成一个规则链,而规则链则依据数据包处理位置的不同进行分类,具体如下:... 查看详情

linux防火墙设置firewalld

entos从7.0开始将原先的防火墙iptables换成了FirewallD。FirewallD支持IPv4,IPv6防火墙设置以及以太网桥接,并且拥有运行时配置和永久配置选项,被称作动态管理防火墙,也就是说不需要重启整个防火墙便可应用更改。centos7... 查看详情

防火墙&iptables&firewalld

1.几个概念防火墙策略可以基于流量的原/目标地址、端口号、协议、应用等信息来定制防火墙功能防火墙虽然有硬件/软件之分,但主要功能都是依据策略对穿越防火墙自身的流量进行过滤,如果流量与某一条策略规则相匹配,... 查看详情

iptables与firewalld防火墙

首先Linux系统中配置IP地址方式:1、命令vim/etc/sysconfig/network-scripts/ifcfg-eno16777728下,修改网络属性,保存并退出即可。2、nmtui(类似DOS编辑器)中修改网络属性。3、命令nm-connection-editor(图形化界面)中编辑网络属性通过以上3种... 查看详情

firewalld介绍

(1).什么是firewalld?  firewalld是提供了支持网络/防火墙区域(zone)定义网络链接以及接口安全等级的动态防火墙管理工具。(2).firewalld与iptables之间的关系  firewalld提供了一个daemon和service,还有命令行和图形界面配置工具,... 查看详情

使用firewalld限制网络通信

...前写过iptables的文章-Linux的netfilter/iptables简介。netfilter是防火墙安全框架,允许内核模块对遍历系统的每个数据包进行检查。在红帽7之前,iptables是与内核netfilter交互的主要方法,红帽7之之后交互的新方法是firewalld,是一个配置... 查看详情

iptables与firewalld防火墙

...安全性是继保障数据的可用性之后最为重要的一项工作。防火墙作为公网与内网之间的保护屏障,在保障数据的安全性方面起着至关重要的作用。1.防火墙管理工具相较于企业内网,外部的公网环境更加恶劣,罪恶丛生。在公网... 查看详情

centos配置iptables作为防火墙来替代默认的firewalld(代码片段)

...tables3.禁用firewalld服务4.编辑/etc/sysconfig/iptables文件来修改防火墙信息1.更新软件包sudoyumupdate出现如下信息代表已经更新到最新版,确保软件包更新到最新已加载插件:fastestmirror,langpacksLoadingmirrorspeedsfromcachedhostfileNopackagesm... 查看详情

第八章iptables与firewalld防火墙第8天7月27日

iptables实际上也只是防火墙的配置工具而已。实际上,一个服务,如果可以称的上分析过滤流量,那么就可以称的上为防火墙。 iptables和内核的netfilter网络过滤器来进行处理。基于的甄别信息?源目地址端口号协议应用firewalld... 查看详情

rhel7--第八章

Iptables与Firewalld防火墙防火墙管理工具依据策略对穿越防火墙自身的流量进行过滤;利用预先定制的策略来监控出入的流量;防火墙策略可以基于流量的源目的地址,端口号,协议,应用等信息来定制;firewalld与iptables1:RHEL7系... 查看详情

centos配置iptables作为防火墙来替代默认的firewalld(代码片段)

...tables3.禁用firewalld服务4.编辑/etc/sysconfig/iptables文件来修改防火墙信息1.更新软件包sudoyumupdate出现如下信息代表已经更新到最新版,确保软件包更新到最新已加载插件:fastestmirror,langpacksLoadingmirrorspeedsfromcachedhostfi 查看详情

firewall详解与操作(代码片段)

...ld的底层是通过iptables来实现的,,firewalld和iptables都不是防火墙,它们只是防火墙的管理程序,真正的防火墙是内核的netfilter。CentOs6中使用iptables来管理防火墙,到了CentOs7默认使用firewalld来管理防火墙,firewalld的底层还是调用 查看详情

红帽7iptables与firewalld防火墙(代码片段)

1、防火墙管理工具防火墙作为公网与内网之间的保护屏障,在保障数据的安全性方面起着至关重要的作用。相较于企业内网,外部的公网环境更加恶劣,罪恶丛生。在公网与企业内网之间充当保护屏障的防火墙虽然有软件或硬... 查看详情

firewalld防火墙的配置及应用

       防火墙(centos7)的配置及应用1:防火墙有基本的三类iptables、firewalld、ip6tablesSystemctl  status  {firewalld,iptables,ip6tables} 查看三类的状态,这里主要介绍firewalld防火墙 查看详情

centos7配置iptables禁用firewalld

centos7默认防火墙不是iptables,而是firewlld安装iptables;yuminstalliptables-y yumupdateiptablesyuminstalliptables-services----------------------------------禁用/停止自带的firewalld服务systemctlstopfirewalld   查看详情

centos7配置iptables规则(代码片段)

 iptables,是Linux下自带的一款免费的基于包过滤的防火墙工具,可以对流入、流出、流经服务的数据包进行精细的控制,而在centos7中将iptables给取消掉了,我们需要自行安装,下面介绍iptables的安装及使用。    一、安装ipt... 查看详情

firewalld入门手册(代码片段)

...禁用:sudosystemctlstopfirewalldsudosystemctldisablefirewalld2、检查防火墙状态。输出应该是 running或者  查看详情

firewalld入门手册(代码片段)

...禁用:sudosystemctlstopfirewalldsudosystemctldisablefirewalld2、检查防火墙状态。输出应该是 running或者 no 查看详情