十二、Linux进阶——iptables和firewalld

本文介绍了Linux的Netfilter/IPTables防火墙机制,重点讲解了iptables的使用、默认策略、命令操作,以及firewalld的开启、域管理、设定原理和管理命令。内容包括iptables的链、表、数据包状态,firewalld的NAT规则和高级应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1. 火墙介绍

Netfilter/IPTables是Linux2.4.x之后新一代的Linux防火墙机制,是linux内核的一个子系统。Netfilter采用模块化设计,具有良好的可扩充性。其重要工具模块IPTables从用户态的iptables连接到内核态的Netfilter的架构中,Netfilter与IP协议栈是无缝契合的,并允许使用者对数据报进行过滤、地址转换、处理等操作。

管理方式iptables|firewalld

2. 火墙管理工具切换

在rhel8中默认为firewalld

2.1 将firewalld切换为iptables

##将firewalld服务关闭并冻结
systemctl stop firewalld  
systemctl disable firewalld
systemctl mask firewalld
##安装并启用iptables服务
dnf search iptables
dnf install iptables-services.x86_64 -y
systemctl enable --now iptables.service

2.2 将iptables切换为firewalld

##将iptables服务关闭,并开启firewalld服务
systemctl stop iptables
systemctl disable iptables
systemctl mask iptables
systemctl unmask firewalld
systemctl enable --now firewalld

3. iptables

3.1 iptables的使用

/etc/sysconfig/iptables ##iptables 策略记录文件
##永久保存策略 
iptales-save > /etc/sysconfig/iptables 
service iptables save

3.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.3 iptables的命令

命令 参数 作用
iptables -t 指定表名称
iptables -n 不做解析
iptables -L 查看
iptables -A 添加策略
iptables -p 协议
iptables –dport 目的地端口
iptables -s 来源
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值