AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1135268
Accepted
Nikk
Nikk
Asked: 2023-06-30 17:27:34 +0800 CST2023-06-30 17:27:34 +0800 CST 2023-06-30 17:27:34 +0800 CST

nftables 链优先级不起作用

  • 772

所以我有两个输入链,input并且dyn是动态生成的。

然而,由于 的原因,规则dyn不起作用input。我尝试过设置inputto的优先级1,甚至设置todyn的优先级。依然没有。0-200

当我刷新input规则时,然后就dyn可以了。

我在这里做错了什么?

sudo nft list ruleset
table inet filter {
chain input {
    type filter hook input priority filter + 1; policy accept;
    iif "lo" accept
    ct state established,related accept
    tcp dport 299 ip saddr 3x.xx.xx.xx accept
    icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, echo-request, echo-reply, nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, 148, 149 } accept
    ip6 saddr fe80::/10 icmpv6 type { mld-listener-query, mld-listener-report, mld-listener-done, mld2-listener-report, 151, 152, 153 } accept
    counter packets 10 bytes 5255 drop
}

chain dyn {
    type filter hook input priority filter; policy accept;
    iif "lo" accept
    ct state established,related accept
    ip saddr 2x.xx.xx.xx udp dport 8999 log prefix "dyn" accept
    ip6 saddr xxx:xxxx:xxxx:xxxx::9999 udp dport 8999 log prefix "dyn" accept
    ip saddr 2x.xx.xx.xx tcp dport 7999 log prefix "dyn" accept
    ip6 saddr xxx:xxxx:xxxx:xxxx::9999 tcp dport 7999 log prefix "dyn" accept
    ip saddr 2x.xx.xx.xx icmp type echo-request log prefix "dyn" accept
    ip6 saddr xxx:xxxx:xxxx:xxxx::9999 icmp type echo-request log prefix "dyn"
    ip saddr 2x.xx.xx.xx tcp dport 6999 log prefix "dyn" accept
    ip6 saddr xxx:xxxx:xxxx:xxxx::aaaa tcp dport 6999 log prefix "dyn" accept
}
}
ubuntu
  • 1 1 个回答
  • 35 Views

1 个回答

  • Voted
  1. Best Answer
    A.B
    2023-07-01T00:49:54+08:002023-07-01T00:49:54+08:00

    每个链都挂钩到Netfilter:只要有数据包存在,Netfilter就会调用当前阶段(例如:输入)的所有链挂钩。

    这意味着每个链都提供了丢弃数据包的机会。一旦数据包被丢弃,它就不再存在:剩余的链不会被调用进行遍历,因为没有任何东西可用于遍历:数据包已经消失了。

    因此,无论两个链的优先级顺序如何,当每个链都有自己的规则来接受或丢弃数据包,独立于另一个链时,最终结果是每个结果之间的逻辑“与”,其中drop表示false,accept 表示true:

    drop   AND drop   = drop
    drop   AND accept = drop
    accept AND drop   = drop
    accept AND accept = accept
    

    nft(8)这在以下部分中有所提醒VERDICT STATEMENT:

    accept

    终止规则集评估并接受数据包。数据包仍然可以稍后被另一个钩子丢弃,例如,前向钩子中的接受仍然允许稍后在后路由钩子中丢弃数据包,或者另一个具有更高优先级编号并随后在处理管道中进行评估的前向基本链。

    drop

    终止规则集评估并丢弃数据包。掉落立即发生,不再评估进一步的链条或钩子。不可能再次接受稍后链中的数据包,因为不再对数据包进行评估。

    如果想避免这种情况,那么评估就一定不能是独立的。例如,您可以使用防火墙标记在第一条链和第二条链之间传递消息(按照钩子和钩子的优先级顺序),将其解释为“已做出决定,接受此数据包”。这需要双方的合作,因此不能使用不知情的工具(例如:无论作为消息创建者还是作为消息消费者,如果不修改firewalld来解决此问题,都无法将其添加到firewalld处理的规则集中。

    对于您的情况,您可以将规则集替换为以下内容:

    table inet filter {
    
    chain markandaccept {
        meta mark set 0x900d accept
    }
    
    chain input {
        type filter hook input priority filter + 1; policy accept;
        meta mark 0x900d accept
        iif "lo" accept
        ct state established,related accept
        tcp dport 299 ip saddr 3x.xx.xx.xx accept
        icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, echo-request, echo-reply, nd-router-solicit, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, 148, 149 } accept
        ip6 saddr fe80::/10 icmpv6 type { mld-listener-query, mld-listener-report, mld-listener-done, mld2-listener-report, 151, 152, 153 } accept
        counter drop
    }
    
    chain dyn {
        type filter hook input priority filter; policy accept;
        iif "lo" goto markandaccept
        ct state established,related goto markandaccept
        ip saddr 2x.xx.xx.xx udp dport 8999 log prefix "dyn" goto markandaccept
        ip6 saddr xxx:xxxx:xxxx:xxxx::9999 udp dport 8999 log prefix "dyn" goto markandaccept
        ip saddr 2x.xx.xx.xx tcp dport 7999 log prefix "dyn" goto markandaccept
        ip6 saddr xxx:xxxx:xxxx:xxxx::9999 tcp dport 7999 log prefix "dyn" goto markandaccept
        ip saddr 2x.xx.xx.xx icmp type echo-request log prefix "dyn" goto markandaccept
        ip6 saddr xxx:xxxx:xxxx:xxxx::9999 icmp type echo-request log prefix "dyn"
        ip saddr 2x.xx.xx.xx tcp dport 6999 log prefix "dyn" goto markandaccept
        ip6 saddr xxx:xxxx:xxxx:xxxx::aaaa tcp dport 6999 log prefix "dyn" goto markandaccept
    }
    }
    

    这是一个没有任何简化的例子,我相信可以做得更好。

    因此,每当动态链认为数据包应该保持被接受时,数据包就会被标记(在内部,仅在当前网络堆栈中)。更改后的输入链中的第一个测试是检查此标记:如果存在,则立即接受数据包,无需进一步处理:第一个链中所做的决定将在第二个链中得到遵守。

    • 1

相关问题

  • 无法通过 Ubuntu VPN 访问外部网络

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

  • VirtualBox 上 Ubuntu 的访客优化技巧 [关闭]

  • 外部硬盘上的 virtualbox 虚拟硬盘驱动器(Vista 主机上的 ubuntu 客户机)

  • 如何在 Ubuntu 上挂载 LVM 分区?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve