Linux中的火墙策略优化(iptables,firewalld)
一、火墙介绍
1.netfilter
2.iptables
3.iptables | firewalld
二、火墙管理工具切换
在rhel8中默认使用的是firewalldfirewalld----->iptablesdnf install iptables-services -y
systemctl stop firewalld
systemctl disable firewalld
systemctl mask firewalld
systemctl enable --now iptablesiptales -------> fiewalld
dnf install firewalld -y
systemctl stop iptables
systemctl disable iptables
systemctl mask iptables
systemctl enable --now firewalld
三、iptables 的使用
#火墙策略的永久保存#
/etc/sysconfig/iptables ##iptables 策略记录文件永久保存策略
iptales-save > /etc/sysconfig/iptables
service iptables save
四、火墙策略
input | ##输入 |
output | 输出 |
forward | 转发 |
postrouting | 路由之后 |
prerouting | 路由之前 |
filter | 经过本机内核的数据(input output forward) |
nat | 不经过内核的数据(postrouting,prerouting,input,output) |
mangle |
当filter和nat表不够用时使用(input output forward ,postrouting,prerouting,) |
-t | 指定表名称 |
-n | 不做解析 |
-L | 查看 |
-A | 添加策略 |
-p | 协议 |
--dport |
目的地端口 |
-s | 来源 |
-j | 动作 |
ACCEPT | 允许 |
DROP | 丢弃 |
REJECT | 拒绝 |
SNAT | 源地址转换 |
DNAT | 目的地地址转换 |
-N | 新建链 |
-E | 更改链地址 |
-X | 删除链 |
-D | 删除规则 |
-I | 插入规则 |
-R | 更改规则 |
-P | 更改默认规则 |
RELATED | 建立过连接的 |
ESTABLISHED | 正在连接的 |
NEW | 新的 |
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT ## 所有建立过连接的或者正在连接的数据包都被接受
iptables -A INPUT -m state --state NEW -i lo -j ACCEPT ##属于自身回环的新数据包都被接受
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT
iptables -A INPUT -m state --state NEW ! -s 192.168.0.10 -p tcp --dport 22 -j ACCEPT
ptables -A INPUT -m state --state NEW -j REJECT
service iptables save
nat表中的dnat snatsnat
iptables -t nat -A POSTROUTING -o enp1s0 -j SNAT --to-source 172.25.254.101dnat
iptables -t nat -A PREROUTING -i enp1s0 -j DNAT --to-dest 1.1.1.201
SNAT:局域网共享一个公网IP接入lnternel,好处如下
1、保护内网用户安全,因为公网地址总有一些人恶意扫描,而内网地址在公网没有路由所以无法被扫描,能被扫描的只有防火墙这一台,这样就减少了被攻击的可能。
2、Ipv4地址匮乏,很多公司只有一个ipv4地址,但是却有几百个用户需要上网,这个时候就需要使用SNAT。
3、省钱,公网地址付费,使用SNAT只需要一个公网ip就可以满足几百人同时上网。
DNAT:向internel发布内网服务器
在内网中有服务器,如果想让公网用户访问有有两种方法。
1.配置双网卡,一网卡对内,一网卡对外;一般是高访问量的web服务器,为了避免占用网关的流量才这样做,使用不是很广泛
2.内网web服务器,或是ftp服务器,为了用户在公网也可以访问,有不想买公网ip地址,采用DNAT方案。
SNAT
实验环境:
server:双网卡 172 网段 和1 网段
client:单网卡1.1.1段的
测试:
DNAT:
实验环境:网卡配置和上步实验相同
iptables -t nat -A PREROUTING -i enp1s0 -j DNAT --to-dest 1.1.1.201
测试:
使用真机ping 1网段
问题: 如果实现不了,试试重启一下网卡。
firewalld
## 1 firewalld的开启 ##
systemctl stop iptables
systemctl disable iptables
systemctl mask iptables systemctl unmask firewalld
systemctl enable --now 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 |
/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=work ##查看指定域的火墙策略
firewall-cmd --set-default-zone=trusted ##设定默认域firewall-cmd --get-services ##查看所有可以设定的服务
firewall-cmd --permanent --remove-service=cockpit ##移除服务
firewall-cmd --reload
firewall-cmd --permanent --add-source=172.25.254.0/24 --zone=block ##指定数据来源访问指定域
firewall-cmd --reload
firewall-cmd --permanent --remove-source=172.25.254.0/24 --zone=block ##删除自定域中的数据来源firewall-cmd --permanent --remove-interface=ens224 --zone=public ##删除指定域的网络接口
firewall-cmd --permanent --add-interface=ens224 --zone=block ##添加指定域的网络接口
firewall-cmd --permanent --change-interface=ens224 --zone=public ##更改网络接口到指定域
firewalld的高级规则
实验时要把http加到火墙服务里面
firewall-cmd --direct --get-all-rules ##查看高级规则
firewall-cmd --direct --add-rule ipv4 filter INPUT 1 ! -s 172.25.254.1 -p tcp --dport 80 -j REJECT #不能直接写允许,所以拒绝所有人的形式允许172.25.254.1一个
!除了
curl http://172.25.254.101
测试:只允许172.25.254.1访问,其他都拒绝
firewalld中的NAT
SNAT
firewall-cmd --permanent --add-masquerade
firewall-cmd --reloadDNAT
firewall-cmd --permanent --add-forward-port=port=22:proto=tcp:toaddr=1.1.1.201
firewall-cmd --reload
测试方式:和iptables 一样
Linux中的火墙策略优化(iptables,firewalld)相关推荐
- 详细总结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中的火墙策略设计优化
Linux中的火墙策略设计 一.关于火墙的基础知识 1.火墙介绍 2.火墙管理工具切换 二.iptables 1. iptables 的使用 2.火墙默认策略 三.firewalld 1.关于fire ...
- 第七章 LINUX中的火墙策略
火墙管理工具切换 firewalld----->iptables dnf install iptables-services -y systemctl stop firewalld system ...
- Linux中的火墙策略
1.火墙介绍 netfilter iptables iptables | firewalld 这个两个工具是用来管理火墙的 dnf install iptables-services -y 安装ip ...
- Linux系统中的火墙策略——firewalld、iptables
文章目录 一.基本介绍 二.火墙管理工具切换 1. firewalld切换为iptablds 2. iptables切换为firewalld 三.iptables的使用 四.火墙默认策略 1. 默认策 ...
- Linux中的火墙 - iptables
Linux中的火墙 - iptables 1.火墙介绍 2.火墙管理工具切换 3.iptables 的使用 4.火墙默认策略 5.iptables命令 1.火墙介绍 1.火墙技术 防火墙技术是通过有机 ...
- linux的火墙策略优化
目录 1.实验环境 2.火墙介绍 3.火墙管理切换 4.firewalld firewalld开启 关于firewalld的域 关于firewalld的设定原理及数据存储 firewalld的管理命令 ...
- Linux中的文件传输优化
Linux中的文件传输优化 1.scp远程传输命令 1.1把本地文件复制到远程主机 1.2把远程文件复制到本地 2.rsync远程同步命令 2.1 rsync和scp对比 2.2 rsync用法 3. ...
最新文章
- Python join()方法
- python二分法查找算法_顺序查找算法和折半(二分法)查找算法,C语言查找算法详解...
- android中设置控件获得焦点 (转)
- 关闭虚拟机提示“正在处理另一个任务”解决方法
- 科技论文新在哪里?-如何写好科技论文之我见(三)
- GAN 的推导、证明与实现。
- rtrim php,php rtrim() 格式化中文问题
- html5 实现波浪效果图,利用HTML5实现Canvas流动的波浪特效
- python编程输入三个数按大小输出_编程:输入3个数,按从小到大的顺序输出
- android ndk 头文件,笔记:Android源码和NDK目录及头文件
- 古人与古代(他们和他们的时代)
- html5从基础到入门,Html5从入门到精通系列2:Html5基础
- FR获取当前控件位置值并转换(或赋值可参考)
- 拓端tecdat|python对网络图networkx进行社区检测和彩色绘图
- mysql 拼音首字母_MySQL拼音首字母查询
- 故宫商业大跃进 逐渐失控的IP洪流
- 基于LabView开发的串口助手
- 数据预处理:自定义PDF格式批量转换TXT系统
- Ubuntu 14.04.2安装内核源码树以及编译
- 最后的晚餐--达.芬奇
热门文章
- python 树状图可视化_Python可视化25|seaborn矩阵图
- python提取txt中指定内容_提取视频中的音频——python三行程序搞定!
- html messagebox确定取消,Element MessageBox弹框的具体使用
- java启动时执行_java怎么实现项目启动时执行指定方法
- python日历提醒_python打印日历
- import tensorflow 报错 ImportError: DLL load failed: 找不到指定的模块。
- 十六、数据变换和数据离散化
- 二维绕任意点旋转_二维图形复合线性变换程序设计:三角形绕任意点旋转2wfhbh...
- mos管防倒灌电路_MOS管自举电路工作原理及升压自举电路结构图
- 来自Android客户端什么意思,如何通过回调函数中的Node.js来自Android客户端