LINUX学习------3.6 Linux中的火墙策略优化
3.6.1 火墙介绍和火墙管理工具切换
1.netfilter
2.1iptables
2.2firewalld2.1和2.2 都是为1服务 两者不可共存,有功能上的优劣
firewalld----->iptables
dnf install ipables-services -y
systemctl stop firewalld
systemctl disable firewalld
systemctl mask firewalld ##锁住firewalld服务
systemctl enable --now iptables
iptables----->firewalld
systemctl stop iptables
systemctl disable iptables
systemctl mask iptables
systemctl unmask firewalld ##解锁firewalld服务
systemctl enable --now firewalld
默认策略中的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.6.2 firewalld用法
1.firewalld的开启
dnf install firewall-config-0.8.0-4.e18.noarch -y ##火墙图形模式
firewall-config ##开启图形
2.关于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
3.关于firewalld的设定原理及数据存储
/etc/firewalld ##火墙配置目录
/lib/firewalld ##火墙模块目录
4. 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 ##更改网络接口到指定域
5. firewalld的高级规则
firewall-cmd --direct --get-all-rules ##查看规则
firewall-cmd --direct --add-rule ipv4 filter INPUT 1 ! -s 172.25.254.22 -p tcp --dport 80 -j REJECT ##除了22其他不可访问http添加规则 表 限制输入 除了 指定ip tcp协议 指定端口 拒绝firewall-cmd --direct --remove-rule ipv4 filter INPUT 1 '!' -s 172.25.254.22 -p tcp --dport 80 -j REJECT ##删除规则
6. firewalld中的NAT
SNAT (当用单网卡1.1.1.0网段连接双网卡,需给单网卡设置网关并在双网卡开启地址伪装)
单网卡:
vim/etc/sysconfig/network
GATEWAY=1.1.1.122
双网卡:
firewall-cmd --permanent --add-masquerade
firewall-cmd --reload
DNAT (主机a双网卡, 主机b 单网卡, 当有其他主机连接双网卡,会转接至222主机 ifconfig看到1.1.1.222)
firewall-cmd --permanent --add-forward-port=port=22:proto=tcp:toport=22:toaddr=1.1.1.222
firewall-cmd --reload
3.6.3 iptables 的使用
1.iptables命令
iptables-t ##指定表名称-n ##不做解析-L ##查看-A ##添加策略-p ##协议--dport ##目的地端口-s ##来源-j ##动作ACCEPT ##允许DROP ##丢弃REJECT ##拒绝SNAT ##源地址转换DNAT ##目的地地址转换-N ##新建链-E ##更改链名称-X ##删除链-D ##删除规则-I ##插入规则-R ##更改规则-P ##更改默认规则 (三张表的policy后的值 ACCEPT REJECT DROP)-F ##删除所有策略非永久
策略优化:
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT ##所有建立过连接的或者正在连接的数据包都被接受
iptables -A INPUT -m state --state NEW -i lo -j ACCEPT ##属于自身回环接口的新数据包都被接受
ptables -A INPUT -m state --state NEW -j REJECT ##其他所有新的数据包会被拒绝
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT ##tcp网络协议 80端口数据包都被接受
iptables -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT
service iptables save ##永久保存数据策略
2.nat表中的dnat snat
snat 输出
iptable -t nat -A POSTROUTING -o ens3 -j SNAT --to-source 172.25.254.122
sysctl -a | grep ip_forward
vim /etc/sysctl.conf ##刷新配置策略
sysctl -pless /etc/sevices ##查看端口号
cat /etc/services
dnat 主机a双网卡1, 主机b 单网卡, 当有其他主机连接双网卡,会转接至222主机 ifconfig看到1.1.1.222
iptables -t nat -A PREROUTING -i ens3 -j DNAT --to-dest 1.1.1.222
LINUX学习------3.6 Linux中的火墙策略优化相关推荐
- 详细总结Linux中的火墙策略优化
文章目录 前言 一.火墙介绍 二.火墙管理工具切换 三.iptables 1.火墙策略的永久保存 2.火墙默认策略 (1)iptables命令 (2)filter 表 (3)nat表 四.firewa ...
- Linux中的火墙策略优化(iptables,firewalld)
一.火墙介绍 1.netfilter 2.iptables 3.iptables | firewalld 二.火墙管理工具切换 在rhel8中默认使用的是firewalldfirewalld----- ...
- Linux中常用的文件目录,Linux学习笔记2——Linux中常用文件目录操作命令
ls 显示文件和目录列表 -l 列出文件的详细信息 -a 列出当前目录所有文件,包含隐藏文件 mkdir 创建目录 -p 父目录不存在情况下先生成父目录 cd 切换目录 touch 生成一个空文件 e ...
- 如何进行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学习笔记之——Linux系统内部相关介绍
Linux学习笔记之--Linux系统内部相关介绍 摘要:主要记录一些比较有用的能够帮助理解和使用Linux的知识.比如一些相关概念.没兴趣的看看就好.知道有这么个东西.注意事项.和一些常用目录的作用 ...
- 【Linux学习笔记】Linux服务器:配置与管理samba服务器
Linux系列文章目录 一.[linux学习笔记]红帽Linux 7.8系统在虚拟机上的安装 二.[Linux学习笔记]Linux系统的基本操作 三.[Linux学习笔记]管理Linux操作系统:用户 ...
- 【黑马程序员新版Linux学习笔记】Linux系统实用操作命令——操作演示
[黑马程序员新版Linux学习笔记]Linux 零基础快速入门: (一)Linux基本命令--操作演示 (二)Linux用户和权限 -- 操作演示 (三)Linux 小技巧快捷键 (四)Linux系统 ...
最新文章
- 资料验证的asp.net程序
- python回归建模_Python实现回归预测及模型优化
- Xposed框架实战
- 如何正确解码用户的“玄学需求”?
- [codevs 1917] 深海机器人问题
- php四则运算出题器_php实现简单四则运算器
- nemesis什么车_狂野飙车9TrionNemesis介绍 S级车Trion复仇女神属性详解
- jQuery 中 data 方法的实现原理
- Quartus破解成功,但出现不支持某些设备的问题解决
- H264解码之PES流解析
- NOIP 2016 年普及组初赛试题整理
- 我的iPad/iPhone App推荐列表
- 电脑蓝屏:缺少bootsafe64_ev.sys
- Automatic detection and segmentation of optic disc and fovea in retinal images
- ubuntu 禁用 guest 账户
- Python学习笔记--解析式
- 美国的非农数据一般会在几点发布
- Porotech 展示突破性的 MicroLED 显示器
- RabbitMQ 安装教程(CentOS版)
- Web返回结果和HTTP状态码详解