【问题标题】:Alternatives for iptables?iptables 的替代品?
【发布时间】:2014-02-20 21:15:34
【问题描述】:

我正在开发一个应用程序,我在其中严重依赖 iptables 来路由流量。 我只是通过调用iptables 作为我的应用程序的外部进程来设置表格。

我想知道是否有一种方法可以直接与 iptables 所依赖的内核模块 (Netfilter) 对话,并避免为此而运行新进程的开销?

欢迎提出其他路由解决方案的建议。

【问题讨论】:

  • 我认为最好的研究地点是 iptables 资源。
  • 如果您一次执行多个规则,您可以通过管道将它们发送到iptables-restore
  • 自上一个 3.13 内核以来,nftables 是 iptables 用于配置 netfilter 的继承者。广告上写着NFTables promises to be more powerful, simpler, reduce code complication, improve error reporting, and provide more efficient handling of packet filter rules.,而技术上写着try it and make your own opinion

标签: c++ linux linux-kernel iptables


【解决方案1】:

我认为 netfilter 没有任何问题。您可以将回调绑定到任何 netfilter 钩子上,内核将在钩子事件上调用您的回调。您正在通过nf_register_hook 执行此操作。您甚至可以使用conntrack 跟踪连接

例如here

有关在official documentation 上破解 netfilter 的更多信息

【讨论】:

    【解决方案2】:

    如果我的理解是正确的,那么您要求的是用于配置 iptables 的编程接口。不幸的是,iptables (libiptc) 没有提供用于配置或查询它们的 API 接口,它在堆栈中的位置太低了。

    我可以建议的另一种选择是内核 IP 集。 ipset 实际上是 iptables 的扩展,它允许创建一次匹配整个地址集的规则。 IPtables 被线性遍历,其中 ip set 存储在索引数据结构中。这使它非常高效。

    https://packages.debian.org/sid/net/ipset
    

    这可能不是您问题的直接答案,但希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-08
      • 2012-01-25
      • 2015-08-05
      • 2011-01-01
      • 2011-10-24
      相关资源
      最近更新 更多