概况
Linux系统中,防火墙(Firewall),网址转换(NAT),数据包(package)记录,流量统计,这些功能是由Netfilter子系统所提供
Netfilter
|
Firewall NAT Package
Netfilter和iptables
Linux提供的所有包过滤和包修改设施的官方项目称为Netfilter;Netfilter是一个框架,用于在不同阶段将函数hook进网络栈,iptables在它之上建立了防火墙功能;
同时,iptables还是同名的用户层工具,将防火墙策略传递给内核,表table、链chain、匹配match、目标target只在iptables上下文中有意义。
iptables结构和应用场景


以本地为目的地址的数据包
数据包经过的表和链,按step顺序:

以本地为源地址的数据包

被转发的数据包

iptables应用场景

表
按处理优先级:raw>mangle>nat>filter
链
iptables中filter表的INPUT/FORWARD/OUTPUT链,nat表的PREROUTING/POSTROUTING链

匹配
每个iptables规则都包含一组匹配以及一个目标
--source(-s) 匹配源ip地址或网络
--destination(-d) 匹配目标ip地址或网络
--protocol(-p) 匹配ip值
--in-interface(-i) 流入接口
--out-interface(-o) 流出接口
--state 匹配一组连接状态
--string 匹配应用层数据字节序列
--comment 注释数据
目标
ACCEPT 允许数据包通过
DROP 丢弃数据包
LOG 将数据包信息记录到syslog
REJECT 拒绝数据包,丢弃
RETURN 在调用链中继续处理数据包
网友评论