linux的火墙策略优化
目录
1.实验环境
2.火墙介绍
3.火墙管理切换
4.firewalld
firewalld开启
关于firewalld的域
关于firewalld的设定原理及数据存储
firewalld的管理命令
域
服务与端口
网络接口,来源
firewalld的高级规则
firewalld中的NAT
SNAT
DNAT
5.iptables
iptables 的使用
火墙默认策略
iptables命令
nat表中的dnat snat
1.实验环境
主机client :网段:1.1.1.212
主机sever:双网卡,
网段1:172.25.254.112 网段2:1.1.1.112
真机:172.25.254.29
2.火墙介绍
在内核上安装的一个数据过滤插件——netfilter,管理与内核进行数据交流的服务
管理iptables插件的策略为firewall和iptables
3.火墙管理切换
- 由于在rhel8中默认使用的是firewalld,故:由firewalld切换到iptables
dnf install iptables-services -y :安装iptables
systemctl stop firewalld :暂停firewalld
systemctl disable firewalld :关闭firewalld
systemctl mask firewalld :加锁firewalld
systemctl enable --now iptables :立刻开启iptables
- 由iptables切换到firewalld
dnf install firewalld -y :安装firewalld
systemctl stop iptables :暂停iptables
systemctl disable iptables :关闭iptables
systemctl mask iptables :枷锁iptables
systemctl unmask firewalld :解封firewalld
systemctl enable --now firewalld :立刻开启firewalld
4.firewalld
firewalld开启
systemctl stop iptables :暂停iptables
systemctl disable iptables :关闭iptables
systemctl mask iptables :枷锁iptables
systemctl unmask firewalld :解封firewalld
systemctl enable --now firewalld :立刻开启firewalld
关于firewalld的域
trusted | 接受所有的网络连接 |
home | 用于家庭网络,允许接受ssh mdns ipp-client samba-client dhcp-client |
work | 工作网络 ssh ipp-client dhcp-client |
public | 公共网络 ssh dhcp-client |
dmz | 军级网络 ssh |
block | 拒绝所有 |
drop | 丢弃(所有数据全部丢弃无任何回复) |
internal | 内部网络 ssh mdns ipp-client samba-client dhcp-client |
external | ##ipv4网络地址伪装转发sshd |
关于firewalld的设定原理及数据存储
火墙配置目录:/etc/firewalld
火墙模块目录:/lib/firewalld
firewalld的管理命令
域
firewall-cmd --state :查看火墙状态
firewall-cmd --get-active-zones :查看当前火墙中生效的域
firewall-cmd --get-default-zone :查看默认域
firewall-cmd --list-all :查看默认域中的火墙策略
firewall-cmd --list-all --zone=xxx :查看指定域(xxx)的火墙策略
firewall-cmd --set-default-zone=xxx :设定默认域为:(xxx)
服务与端口
firewall-cmd --get-services :查看所有可以设定的服务
firewall-cmd --permanent --add-service=xxx :添加服务xxx
firewall-cmd --permanent --remove-service=xxx :移除服务xxx
firewall-cmd --reload :加载生效
firewall-cmd --permanent --add-port=xxx/tcp :添加端口
firewall-cmd --permanent --add-port=xxx/tcp :移除端口
网络接口,来源
firewall-cmd --permanent --remove-interface=ensxxx --zone=xxx :删除指定域的网络接口
firewall-cmd --permanent --add-interface=ensxxx --zone=xxx :添加指定域的网络接口
firewall-cmd --permanent --change-interface=ensxxx --zone=xxx :更改网络接口到指定域
firewall-cmd --permanent --add-source=172.25.254.xxx/24 --zone=xxx :指定数据来源访问指定域
firewall-cmd --reload
irewall-cmd --permanent --remove-source=172.25.254.xxx/24 --zone=xxx :删除自定域中的数
据来源
firewalld的高级规则
firewall-cmd --direct --get-all-rules :查看高级规则firewall-cmd --direct --add-rule ipv4 filter INPUT 0 ! -s 172.25.254.250 -p tcp --
dport 22 -j REJECT :编写文件,添加ssh策略,并拒绝目的地22端口的访问
firewall-cmd --reload :加载生效
firewalld中的NAT
SNAT
主机server:
路由伪装,NAT方式
firewall-cmd --permanent --add-masquerade :路由开启masquerade地址伪装服务
firewall-cmd --reload
路由功能:
sysctl -a | grep ip_forward :查看路由功能的状态若:net.ipv4.ip_forward =1 :表示功能开启
若:net.ipv4.ip_forward =0:表示路由功能未开启
路由功能未开启的解决方案:
- vim /etc/sysctl.conf ,内容:net.ipv4.ip_forward =1
- 编辑完成后,sysctl -p :生效/etc/sysctl.conf文件
主机client:
ip route add default via 11.1.1.112 :临时设定网关(此网关为主机server的另一网段ip)
route -n测试:
ping 172.25.254.12
ssh root@172.25.254.12 ,可在真机中查看伪装效果:w -i
DNAT
主机server:
firewall-cmd --permanent --add-forward-port=port=22:proto=tcp:toaddr=1.1.1.212:将ssh服务的22端口的接受数据ip地址转移到1.1.1.212网段
firewall-cmd --reload测试(真机):
ssh root@172.25.254.112,ifconfig可查看效果
5.iptables
iptables 的使用
火墙策略的永久保存:
/etc/sysconfig/iptables iptables 策略记录文件
永久保存策略:
- iptales-save > /etc/sysconfig/iptables
- service iptables save
火墙默认策略
默认策略中的5条链 | |
---|---|
input | 输入 |
output | 输出 |
forward | 转发 |
postrouting | 路由之后 |
prerouting | 路由之前 |
默认的3张表 |
||
---|---|---|
表名 | 含义 | 内容 |
filter | 经过本机内核的数据 | (input ,output ,forward) |
nat | 不经过内核的数据 | (postrouting,prerouting,input,output) |
mangle | 当filter和nat表不够用时使 | (input, output, forward,postrouting,prerouting,) |
iptables命令
iptables -t | 指定表名称 | iptables -L | 查看 | iptables -N | 新建链 |
iptables -n | 不做解析 | iptables -j ACCEPT | 允许 | iptables -E | 更改链名称 |
iptables -A | 添加策略 | iptables -j DROP | 丢弃 | iptables -X | 删除链 |
iptables -p | 协议 | iptables -j REJECT | 拒绝 | iptables -D | 删除规则 |
iptables -s | 来源 | iptables -j SNAT | 源地址转换 | iptables -I | 插入规则 |
iptables -dport | 目的地端口 | iptables -j DNAT | 目的地地址转换 | iptables -R/-P | 更改规则/更改默认规则 |
数据包状态
数据包状
RELATED 建立过连接的
ESTABLISHED 正在连接的
NEW 新的
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT :接受RELATED,ESTABLISHED的数据包状态
iptables -A INPUT -m state --state NEW -i lo -j ACCEPT :接受插入规则:本地回环
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT :接受80端口的httpd
iptables -A INPUT -m state --state NEW ! -s 172.25.254.112 -p tcp --dport 22 -j ACCEPT :拒绝172.25.254.11访问22端口
service iptables save :永久保存
nat表中的dnat snat
snat
主机server:
iptables -t nat -A POSTROUTING -o ens3 -j SNAT --to-source 172.25.254.112 :源目的地址转换(从ens3网卡出去的数据,IP地址伪装成172.25.254.112)
iptables -t nat -nL :查看nat表,不做解析
iptables -t nat -D POSTROUTING 1 :删除POSTROUTING
dnat
主机server:
iptables -t nat -A PREROUTING -i ens3 -j DNAT --to-dest 1.1.1.212(目的地址转换)
iptables -t nat -nL
linux的火墙策略优化相关推荐
- 详细总结Linux中的火墙策略优化
文章目录 前言 一.火墙介绍 二.火墙管理工具切换 三.iptables 1.火墙策略的永久保存 2.火墙默认策略 (1)iptables命令 (2)filter 表 (3)nat表 四.firewa ...
- LINUX学习------3.6 Linux中的火墙策略优化
3.6.1 火墙介绍和火墙管理工具切换 1.netfilter 2.1iptables 2.2firewalld 2.1和2.2 都是为1服务 两者不可共存,有功能上的优劣 firewalld---- ...
- Linux中的火墙策略优化(iptables,firewalld)
一.火墙介绍 1.netfilter 2.iptables 3.iptables | firewalld 二.火墙管理工具切换 在rhel8中默认使用的是firewalldfirewalld----- ...
- 如何进行Linux中的火墙策略设计优化
Linux中的火墙策略设计 一.关于火墙的基础知识 1.火墙介绍 2.火墙管理工具切换 二.iptables 1. iptables 的使用 2.火墙默认策略 三.firewalld 1.关于fire ...
- Linux火墙策略的管理以及火墙的介绍
文章目录 前言 一.火墙介绍以及实验环境设定 1.火墙介绍 2.实验环境设定 3.火墙管理工具的切换 二.firewalld对火墙的管理方式以及设定 1.firewalld基础管理命令 2.火墙中的三 ...
- Linux进阶(10)--防火墙策略优化
一.火墙介绍 从RHEL7以后,iptables服务的启动脚本已被忽略.请使用firewalld来取代iptables服务. 防火墙是一组规则.当数据包进出受保护的网络区域时,进出内容(特别是关于其来 ...
- 第七章 LINUX中的火墙策略
火墙管理工具切换 firewalld----->iptables dnf install iptables-services -y systemctl stop firewalld system ...
- Linux系统中的火墙策略——firewalld、iptables
文章目录 一.基本介绍 二.火墙管理工具切换 1. firewalld切换为iptablds 2. iptables切换为firewalld 三.iptables的使用 四.火墙默认策略 1. 默认策 ...
- Linux中的火墙策略
1.火墙介绍 netfilter iptables iptables | firewalld 这个两个工具是用来管理火墙的 dnf install iptables-services -y 安装ip ...
最新文章
- m个足球放入n个篮子中或者放苹果问题
- InputFlinger崩溃问题分析报告
- FLEX中Sequence实例教程. 顺序执行的效果.
- 系统详细设计说明书_人工砂石骨料加工系统5个生产环节详细解读,设计要点、生产工艺...
- python程序实例教程基础-Python程序设计实例教程
- 移动端HTML5性能优化
- facelets_Java EE 8中的MVC 1.0:使用Facelets入门
- 【随感】tomorrow ,new semester ,finally i have time to read some books~
- 安兔兔2月Android手机性价比榜出炉:Redmi包揽前三
- 来谈谈Spring构造函数注入的循环依赖问题
- hive分桶表join_Hive知识梳理
- EurekaServer高可用的注册中心集群搭建
- python3.6---之f'{}'
- html5 progress css,CSS内容:HTML5进度上的attr()不起作用
- Flash Builder4与Flash cs4 协同工作
- STM32 IIC协议详解
- 企业SOA平台 JBoss SOA
- 数值代数中的数学原理及其证明(一)
- Android Netd
- 计算机考试怎么调整字号,WPS文字如何调节字体大小突破字号72的限制实现大小随意调...