firewall


8080-->缓存端口

一、Firewalld概述

动态防火墙后台程序firewalld提供了一个动态管理的防火墙,用以支持网络“zone”,以分配对一个网路及其相关连接和界面的支持。它支持以太网桥,
并有分离运行时间和永久性配置选择。它还具备一个通向服务或者应用程序以直接增加防火墙规则的接口。
系统提供了图形化的配置工具firewall-config,system-config-firewall,
提供命令行客户端运行时间的改变:它依次用iptables工具与执行数据包筛选的内核中的Netfilter通信。

二、firewalld 域

网络区名称默认配置
trusted(信任)可以接收所有的网络连接
home(家庭)用于家庭网络,仅接收ssh,mdns,ipp-client,samba-client,或dhcpv6-client服务连接。
internal(内部)用于内部网络,仅接收ssh,mdns,ipp-client,samba-client,dhcpv6-client服务连接。
work(工作)用于工作区,仅接收ssh,ipp-client或dhcpv6-client服务连接。
public(公共)在公共区域内使用,仅接收ssh或dhcpv6-client服务连接。
external(外部)出去的ipv4网络连接通过此区域伪装和转发,仅接收ssh服务连接。
dmz(非军事区)仅接收ssh服务连接。
block(限制)拒绝所有网络连接。
drop(丢弃)任何接收的网络数据包都被丢弃,没有任何回复。

 

三、firewalld 和 iptables service

firewalld 和 iptables service 之间最本质的不同是 :

  • iptables service 在 /etc/sysconfig/iptables 中储存配置
  • firewalld 将配置储存在 /usr/lib/firewalld/ 和/etc/firewalld/ 中的各种 XML 文件里 .
  • iptables更加专业操作详细
    firewall操作简便

 

四、firewalld

 

yum install -y firewalld firewall-config ##安装firewalld
systemctl start firewalld   ##启用
systemctl enable firewalld   ##开机自启动
systemctl disable firewalld  ##开机禁启动
systemctl stop firewalld     ##关闭

1.firewalld实验举例:
打开hppt服务

vim /etc/httpd/conf/httpd.conf
改变端口为:6666
systemctl restart httpd ##重启服务后会报错,因为http没有添加这个端口

semanange port -l  ##所有端口
semanage port -l | grep http ##过滤含有http的端口

semanage port -a -t http_port_t -p tcp 6666  ##给http添加一个6666端口,-a添加
systemctl restart httpd ##重启服务成功

删除端口:

vim /etc/httpd/conf/httpd.conf ##恢复原来的端口80
systemctl restart httpd
semanage port -d -t http_port_t -p tcp 6666 ##删除6666端口,-d删除

2.
实验环境:一台虚拟机设置两个网卡,一个设置一个网卡

iptables 一个数据包在系统内核上的汇总


编辑火墙策略的管理工具:
iptables:三张表,五条链
firewall
启用:iptables

yum install iptables-services -y
systemctl stop firewalld
systemctl disable firewalld
systemctl mask firewalld   ##锁定firewall

systemctl start iptables.service
systemctl enable iptables.service
iptables -nL

启用:firewall

systemctl stop iptables.service
systemctl disable iptables.service
systemctl mask iptables.service

systemctl unmask firewalld.service ##解锁
systemctl start firewalld.service
systemctl enable firewalld.service
firewall-cmd --list-all

3.使用命令行接口配置防火墙

firewall-cmd --state    ##查看火墙的状态
firewall-cmd --get-default-zone ##查看默认域 (默认的域为public)
firewall-cmd --get-active-zones
firewall-cmd --get-zones

firewall-cmd --list-all-zones  查看所有域
firewall-cmd --zone=public --list-all ##查看指定域的信息
firewall-cmd --set-default-zone=work ##设定默认域

firewall-cmd --zone=work --add-source=172.25.254.60
##域里添加来源,使他遵循这个域的设置  其他人不行,只有60可以

firewall-cmd --get-services  ##查看所有服务


 

firewall-cmd --add-service=dns
firewall-cmd --list-all

firewall-cmd --remove-service=dns ##删除服务
firewall-cmd --list-all

firewall-cmd --zone=public --list-ports ##查看指定域的接口
firewall-cmd --permanent --zone=public --add-port=8080/tcp  ##添加接口
firewall-cmd --permanent --zone=public --remove-port=8080/tcp  ##删除接口

#2#

firewall-cmd --permanent --remove-service=ssh
firewall-cmd --reload  ##不会断开之前连接的

firewall-cmd --complete-reload  ##立即中断现在主机对外连接的终端


250只能连接这台主机,这台主机只能被250连接

3.Direct Rules

通过 firewall-cmd 工具 , 可以使用 --direct 选项在运行时间里增加或者移除链。

如果不熟悉 iptables , 使用直接接口非常危险 , 因为您可能无意间导致防火墙被入侵。

直接端口模式适用于服务或者程序 , 以便在运行时间内增加特定的防火墙规则。
直接端口模式添加的规则优先应用


4.伪装和端口转发

iptables:三张表,五个链
表:filter(控制本机访问的表)   net(与内核无关)   mangle(5个链,不够用时启用mangle表)
链:input  output  forward  postrounting  prerounting

Snat:来源地址转换(路由后)postrounting  ##与路由无关
Dnat:目的地地址转换(路由前)prerounting  ##与路由无关

 

filter表:input output forward
net:


input 里设置:
读取时按顺序读取,只要匹配就会通过
-p端口类型 tcp接口 dport-->目的地接口 -s数据来源  -j动作
accept允许  reject拒绝  drop丢弃

ipv4

iptables -t filter -nL ##查看filter表
firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -p tcp --dport 22 -s 172.25.254.18 -j ACCEPT ##只有18主机能连,其他走默认。默认允许就可以连接
firewall-cmd --direct --get-all-rules  ##
ipv4 filter (访问ipv4的本机的服务)INPUT(进入本机的数据包) 1(input链的这个第一条规则) -p tcp --dport 22 -s 172.25.254.18 -j ACCEPT(动作是允许的)


firewall-cmd --direct --remove-rule ipv4 filter INPUT 1 -p tcp --dport 22 -s 172.25.254.18 -j ACCEPT  ##删除这个规则
firewall-cmd --direct --add-rule ipv4 filter INPUT 1 -p tcp --dport 22 ! -s 172.25.254.18 -j ACCEPT  ##只有18不能连

 

 

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

马克图布s

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值