Linux网络之Netfilter简述
Linux网络之Netfilter简述
简介
The netfilter project is a community-driven collaborative FOSS project that provides packet filtering software for the Linux 2.4.x and later kernel series. The netfilter project is commonly associated with iptables and its successor nftables.
The netfilter project enables packet filtering, network address [and port] translation (NA[P]T), packet logging, userspace packet queueing and other packet mangling.
The netfilter hooks are a framework inside the Linux kernel that allows kernel modules to register callback functions at different locations of the Linux network stack. The registered callback function is then called back for every packet that traverses the respective hook within the Linux network stack.
iptables is a generic firewalling software that allows you to define rulesets. Each rule within an IP table consists of a number of classifiers (iptables matches) and one connected action (iptables target).
nftables is the successor of iptables, it allows for much more flexible, scalable and performance packet classification. This is where all the fancy new features are developed.
Netfilter 项目是一个由社区驱动的合作自由/开源软件(FOSS)项目,为 Linux 2.4.x 及更高版本的内核系列提供数据包过滤软件。Netfilter 项目通常与 iptables 及其继任者 nftables 相关联。
Netfilter 项目支持数据包过滤、网络地址 [和端口] 转换(NA[P]T)、数据包日志记录、用户空间数据包排队以及其他数据包处理操作。
Netfilter 钩子是 Linux 内核中的一个框架,允许内核模块在 Linux 网络协议栈的不同位置注册回调函数。每当数据包通过 Linux 网络协议栈中相应的钩子时,就会调用已注册的回调函数。
iptables 是一种通用防火墙软件,允许你定义规则集。每个 IP 表中的规则由多个分类器(iptables 匹配)和一个关联的操作(iptables 目标)组成。
nftables 是 iptables 的继任者,它提供了更加灵活、可扩展且性能更高的数据包分类功能。所有新的高级功能都在这里开发。
主要特性
- 无状态数据包过滤(IPv4 和 IPv6)
无状态过滤规则不跟踪连接的状态,只根据预定义的规则对每个单独的数据包进行处理。 - 有状态数据包过滤(IPv4 和 IPv6)
有状态过滤会跟踪连接的状态,并基于连接的状态来决定是否允许数据包通过。 - 各种网络地址和端口转换,例如 NAT/NAPT(IPv4 和 IPv6)
这些功能可以用于隐藏内部网络结构、共享公共 IP 地址、负载均衡等场景。 - 提供了灵活且可扩展的基础设施
使得开发者可以根据需要添加新的功能或修改现有功能,以满足特定需求。 - 多层 API 支持第三方扩展
提供了多层 API,允许第三方开发者在其基础上进行扩展和集成,从而增强其功能并适应不同的应用场景。
能用Netfilter做什么
基于无状态和有状态数据包过滤构建互联网防火墙
Netfilter 可以帮助你基于无状态和有状态数据包过滤来构建互联网防火墙。无状态过滤适用于简单的规则设置,而有状态过滤则可以跟踪连接的状态,提供更高级的安全功能。部署高可用性的无状态和有状态防火墙集群
通过 Netfilter,你可以部署高可用性的无状态和有状态防火墙集群,确保即使在单个节点故障的情况下,防火墙仍然能够正常运行,保障网络安全。如果没有足够的公共 IP 地址,使用 NAT 和伪装来共享互联网访问
如果你没有足够的公共 IP 地址,可以通过 NAT(网络地址转换)和伪装(masquerading)技术来共享互联网访问。这使得内部网络中的设备可以通过一个或少量公共 IP 地址访问外部网络。使用 NAT 实现透明代理
Netfilter 支持使用 NAT 来实现透明代理,使得流量可以在用户不知情的情况下被重定向到代理服务器,从而提高安全性和性能。辅助 tc 和 iproute2 系统,用于构建复杂的 QoS 和策略路由器
Netfilter 可以与 tc(流量控制)和 iproute2 系统结合使用,帮助构建复杂的 QoS(服务质量)和策略路由器,从而更好地管理和优化网络流量。进行进一步的数据包处理(如修改 IP 头中的 TOS/DSCP/ECN 位)
Netfilter 允许你进行进一步的数据包处理(如修改 IP 头中的 TOS(服务类型)、DSCP(差分服务代码点)和 ECN(显式拥塞通知)位),以便对网络流量进行更细致的控制和管理。