Firewalld防火墙

一、防火墙

1、netfilter和防火墙管理工具

1)netfilter

防火墙内核模块

判断Linux是否支持防火墙功能检查内核是否有netfilter模块

2)防火墙管理工具

iptables:Centos6以前的防火墙管理工具

firewalld:Centos7以后使用,配置简单方便灵活

2、防火墙配置模式

1)运行配置模式

防火墙服务重新启动规则丢失

2)永久配置模式

服务重新启动不影响规则

3、Firewalld数据流处理的方式

1)源地址关联到区域

执行区域中的规则

2)源地址没有关联到区域

执行接口所在区域规则

3)接口没有关联到区域

执行默认所在区域规则

firewalld默认区域是public

4、firewalld区域类型

1)trusted区域

信任区域

允许所有流量

一般内部区域使用

2)internal

内部区域

内部网网络

3)public

默认区域

允许所有数据通过

4)external

拒绝所有流量进入当前区域

非信任网络

互联网接口划分在external区域

5)dmz

非军事化区域

拒绝所有流量进入区域

保存服务器对外提供服务

6)work

工作区域

拒绝流量进入允许ssh、dhcp

7)home

允许ssh、mdns、ipp-client

8)blook

允许所有流量通过

9)drop

拒绝所有通信

二、防火墙的基本应用

1、查看区域和配置默认区域

1)查看区域

[root@centos04 ~]# firewall-cmd --get-zones

2)查看防火墙默认区域

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

3)查看防火墙激活区域

[root@centos04 ~]# firewall-cmd --get-active-zones

4)修改默认区域

[root@centos04 ~]# firewall-cmd --set-default-zone=trusted

2、将防火墙接口划分到区域中

1)将ens32接口划分到trusted区域

[root@centos04 ~]# firewall-cmd --add-interface=ens32 --zone=trusted

2)查看接口所在区域

[root@centos04 ~]# firewall-cmd --get-zone-of-interface=ens32

3)将ens32接口修改到dmz区域

[root@centos04 ~]# firewall-cmd --change-interface=ens32 --zone=dmz

4)将ens32接口从truseted区域移除

[root@centos04 ~]# firewall-cmd --remove-interface=ens32 --zone=trusted

3、区域添加访问规则

1)允许外部区域使用ftp

[root@centos04 ~]# firewall-cmd --add-service=ftp --zone=external

2)查看外部区域的规则

[root@centos04 ~]# firewall-cmd --list-services --zone=external

3)显示外部区域规则详细信息

[root@centos04 ~]# firewall-cmd --list-all --zone=external

4)不允许外部区域使用ssh服务

[root@centos04 ~]# firewall-cmd --remove-service=ssh --zone=external

5)允许外部区域的443端口通信

[root@centos04 ~]# firewall-cmd --add-port=443/tcp --zone=external

6)不允许外部区域使用443端口

[root@centos04 ~]# firewall-cmd --remove-port=443/tcp --zone=external

7)查看添加的端口号规则

[root@centos04 ~]# firewall-cmd --list-ports --zone=external

4、配置阻止使用ping

1)查看是否添加规则

[root@centos04 ~]# firewall-cmd --list-icmp-blocks

2)不允许发送icmp请求

[root@centos04 ~]# firewall-cmd --add-icmp-block=echo-request --zone=trusted

3)允许发送icmp响应

[root@centos04 ~]# firewall-cmd --add-icmp-block=echo-reply --zone=trusted

4)添加永久规则

[root@centos04 ~]# firewall-cmd --add-icmp-block=echo-request --zone=trusted --permanent

实验环境

网关

[root@localhost ~]# hostname gateway-server

[root@localhost ~]# bash

[root@gateway-server ~]# ifconfig

[root@gateway-server ~]# cd /etc/sysconfig/network-scripts/

[root@gateway-server network-scripts]# ls

[root@gateway-server network-scripts]# cp ifcfg-ens33 ifcfg-ens36

[root@gateway-server network-scripts]# cp ifcfg-ens33 ifcfg-ens37

[root@gateway-server network-scripts]# vim ifcfg-ens36

[root@gateway-server network-scripts]# vim ifcfg-ens37

[root@gateway-server network-scripts]# systemctl restart network

[root@gateway-server network-scripts]# cd

[root@gateway-server ~]# ifconfig

[root@gateway-server ~]# vim /etc/sysctl.conf

net.ipv4.ip_forward = 1

[root@gateway-server ~]# sysctl -p

Web服务

[root@ltsw ~]# hostname web

[root@ltsw ~]# bash

[root@ltsw ~]#vim /etc/sysconfig/network-scripts/ifcfg-ens32

[root@web ~]# mount /dev/cdrom /mnt

[root@web ~]# yum -y install httpd mod_ssl

[root@web ~]# systemctl enable httpd

[root@web ~]# systemctl start httpd

[root@web ~]# vim /var/www/html/index.html

this is a test web

[root@web ~]# vim /etc/ssh/sshd_config

在Port 22下面一行加Port 12345

[root@web ~]# setenforce 0

[root@web ~]# systemctl restart sshd

[root@web ~]# systemctl status firewalld

[root@web ~]# firewall-cmd --set-default-zone=dmz

[root@web ~]# firewall-cmd --zone=dmz --add-service=https --permanent

[root@web ~]# firewall-cmd --zone=dmz --add-port=12345/tcp --permanent

[root@web ~]# firewall-cmd --add-icmp-block=echo-request --zone=dmz --permanent

[root@web ~]# firewall-cmd --zone=dmz --remove-service=ssh --permanent

[root@web ~]# firewall-cmd --reload

[root@web ~]# firewall-cmd --list-all --zone=dmz

[root@web ~]# firewall-cmd --zone=dmz --add-service=http --permanent

[root@web ~]# firewall-cmd --reload

4.4

[root@gateway-server ~]# firewall-cmd --state

[root@gateway-server ~]# firewall-cmd --set-default-zone=external

[root@gateway-server ~]# firewall-cmd --list-all

[root@gateway-server ~]# firewall-cmd --change-interface=ens35 --zone=trusted

[root@gateway-server ~]# firewall-cmd --change-interface=ens34 --zone=dmz

[root@gateway-server ~]# firewall-cmd --get-active-zones

本机vm2地址2网段

[root@gateway-server ~]# firewall-cmd --zone=external --add-port=12345/tcp --permanent

[root@gateway-server ~]# firewall-cmd --zone=external --remove-service=ssh --permanent

[root@gateway-server ~]# firewall-cmd --zone=external --add-icmp-block=echo-request --permanent

[root@gateway-server ~]# firewall-cmd --reload

[root@gateway-server ~]# vim /etc/ssh/sshd_config

Port 12345

[root@gateway-server ~]# setenforce 0

[root@gateway-server ~]# systemctl restart sshd

第一台

[root@local ~]# ssh -p 12345 192.168.4.4

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值