Linux中的火墙策略优化

本文详细介绍了Linux中的iptables和firewalld防火墙工具,包括它们之间的切换方法、策略设置、默认行为、高级规则以及NAT转换的使用。重点讲解了iptables的命令行操作和firewalld的域管理及地址伪装。
摘要由CSDN通过智能技术生成

目录

一、火墙介绍

二、火墙管理工具切换

1、firewalld —> iptables

2、iptables —> firewalld 

三、iptables的使用及火墙默认策略

1、火墙策略的永久保存

2、火墙默认策略

3、iptables的命令

4、数据包状态

5、NAT表中的SNAT和DNAT 

四、firewalld的使用

1、firewalld的开启

2、firewald的域

3、firewalld的设定原理及数据存储

4、firewalld的管理命令

5、firewalld的高级规则 

6、firewalld中的NAT


一、火墙介绍


在Linux中火墙策略是基于netfilter实现的。
1、netfilter:内核上有个安全插件netfilter(访问控制列表),这个列表里有许多详细的规则,当对这个规则允许或拒绝时,可以控制其他主机是否能访问,极大的提高了安全性。
2、iptables:管理netfilter的工具,通过iptables往netfilter表格里面写网络安全策略。
3、iptables | firewalld:对iptables进行管理,用iptables或firewalld手段来写网络安全策略。

二、火墙管理工具切换

在rhel8中默认使用的是firewalld

1、firewalld —> iptables

dnf install iptables-services -y
systemctl stop firewalld.service
systemctl disable firewalld.service
systemctl mask firewalld.service
systemctl enable --now iptables.service

 

2、iptables —> firewalld 

systemctl stop iptables.service
systemctl disable --now iptables.service 
systemctl mask iptables.service
systemctl unmask firewalld.service
systemctl enable --now firewalld.service

 

三、iptables的使用及火墙默认策略

1、火墙策略的永久保存

iptables策略记录文件:/etc/sysconfig/iptables

  • 永久保存策略:

iptables-save > /etc/sysconfig/iptables

service iptables save

2、火墙默认策略

默认策略中的5条链

input 输入(目的地址为本机)
output 输出(原地址为本地,向外发送)
forward 实现转发
postrouting 路由之后(发送到网卡之前)
prerouting 数据包进入路由之前

默认策略的3张表

filter           ## 经过本机内核的数据 input output forward
nat            ## 不经过内核的数据 postrouting prerouting,input,output
mangle     ## filter nat 表不够用时使用 input output forward postrouting prerouting,

3、iptables的命令

-F                清空iptables(如不保存,服务重启后,策略会恢复)
-t                 指定表名称(默认查看filter表)
-n                不做解析
-L                查看
-A                添加策略
-p                协议
--dport         目的地端口
--sport          来源端口
-s                来源
-j                 动作
                    ACCEPT:允许
                    DROP:丢弃
                    REJECT:拒绝
                    SNAT:源地址转换
                    DNAT:目的地地址转换
-N                新建链
-E                更改链名称
-X                删除链
-D                删除规则
-I                 插入规则
-R               更改规则
-P               更改默认规则

(1)清空iptables表

iptables -F

iptables -nL 

 

 (2)查看指定表

iptables -t nat -nL

 

(3)允许指定ip访问 

iptables -t filter -A INPUT -s 1.1.1.111 -j ACCEPT

iptables -nL

4)-I INPUT 2:插入指定次序规则(INPUT 默认第一行) 

iptables -t filter -A INPUT -s 1.1.1.112 -j ACCEPT
iptables -t filter -I INPUT 2  -s 198.168.1.25

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值