确保 Nftables 的基本链存在,并为环回流量设置 nftables 配置

确保 Nftables 的基本链存在,并为环回流量设置 nftables 配置

我已禁用 ufw 并启用 nftables,但usg audit cis_level1_server仍持续标记Ensure Base Chains Exist for NftablesSet nftables configuration for loopback traffic

/etc/nftables.conf的如下。

类似的问题是在 /r/Ubuntu 上提问

我特别想看到一个指向任何 /etc/nftables.conf过去了usg audit cis_level1_server

#!/usr/sbin/nft -f

flush ruleset

table inet filter {

    chain inbound_ipv4 {
    }

    chain inbound_ipv6 {
        icmpv6 type { nd-neighbor-solicit, nd-router-advert, nd-neighbor-advert } accept
    }

    chain input {
        type filter hook input priority 0; policy drop;

        ct state vmap { established : accept, related : accept, invalid : drop }

        iif "lo" accept
        ip  saddr 127.0.0.0/8 counter drop
        ip6 saddr ::1         counter drop

        meta protocol vmap { ip : jump inbound_ipv4, ip6 : jump inbound_ipv6 }

        tcp dport { 22 } accept
    }

    chain output {
        type filter hook output priority 0; policy accept;
        ip protocol tcp ct state established,related,new accept
        ip protocol udp ct state established,related,new accept
        ip protocol icmp ct state established,related,new accept
    }

    chain forward {
        type filter hook forward priority 0; policy drop;
    }
}

答案1

我在尝试配置 Server_Level_2 时遇到了这个问题。我查看了基准测试文档,发现以下内容被用作审计命令

nft 列表规则集 | awk'/hook input/,/}/'| iif“lo”接受

我的问题是,我的配置中有一个逗号,即 ct state { established, related } ...,这导致 awk 管道在到达我的环回配置之前就被切断了。将这些内容移到配置上方,并使用逗号,这样就通过了。

看起来您可能遇到了同样的问题,其中“ ct state vmap { established : accept, related : accept, invalid : drop }”比基准测试预期更早结束 awk 输出。

尝试应用此配置(语义相同,但应通过环回基准):

#!/usr/sbin/nft -f

flush ruleset

table inet filter {

    chain inbound_ipv4 {
    }

    chain inbound_ipv6 {
        icmpv6 type { nd-neighbor-solicit, nd-router-advert, nd-neighbor-advert } accept
    }

    chain input {
        type filter hook input priority 0; policy drop;
        
        iif "lo" accept
        ip  saddr 127.0.0.0/8 counter drop
        ip6 saddr ::1         counter drop
        
        ct state vmap { established : accept, related : accept, invalid : drop }

        

        meta protocol vmap { ip : jump inbound_ipv4, ip6 : jump inbound_ipv6 }

        tcp dport { 22 } accept
    }

    chain output {
        type filter hook output priority 0; policy accept;
        ip protocol tcp ct state established,related,new accept
        ip protocol udp ct state established,related,new accept
        ip protocol icmp ct state established,related,new accept
    }

    chain forward {
        type filter hook forward priority 0; policy drop;
    }
}

相关内容