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 / 问题

问题[nftables](server)

Martin Hope
wolfsden3
Asked: 2024-03-19 08:06:57 +0800 CST

nftables + Almalinux (CPanel):帮助创建规则

  • 5

我需要帮助创建规则。根据 CPanel 的说法,firewall-d 破坏了从 CentOS > Alma Linux 的迁移。他们不再支持 CentOS,所以我最终硬着头皮迁移了。一切都进行得很顺利,直到我发现了firewall-d,因为我所有的ipsets以及我将新的罪犯添加到我的阻止列表中的过程都中断了。他们建议我转向 nftables。在研究并尝试了一些事情之后,我无法确切地弄清楚我在寻找什么。

我想添加超时元素(1 天),就像 CPanel 对 cphulk 所做的那样。

我做了一些实验:

nft add table inet filter
nft add set inet filter jerk_ips { type ipv4_addr \; }
nft add chain inet filter jerk_ips '{ type filter hook input priority 0 ; }'
nft add rule inet filter jerk_ips ip saddr xxx.xxx.xxx.xxx drop
  • xxx.xxx.xxx.xxx = 某些有问题的 IP 地址

我只是非常困惑这一切是如何运作的。我在网上阅读了很多内容,但它假设您知道所有这些嵌套的东西都是有效的,这就是我读到的有关“集合”的地方,并且在“集合”中您可以放置​​一个名为“超时”的标志。

我的最终结果是像往常一样简单地解析我的日志文件,找到违规者,阻止他们,但由于我正在重做所有事情,我认为我会添加 24 小时/1 天自动删除,因为我相信这样做更容易nftables 现在比在firewall-d 中使用fireall-cmd 更好。

任何帮助,将不胜感激。

谢谢。

nftables
  • 1 个回答
  • 46 Views
Martin Hope
avi9526
Asked: 2023-12-14 09:57:21 +0800 CST

如何使用 nftables dnat 和重定向而不需要前面的匹配

  • 6

我有

table ip nat {
    chain Redirect_to_local {
            limit rate 3/minute burst 10 packets log prefix "[nft.ip.dnat.8080]: "
            redirect to :8080
    }
    chain PREROUTING {
            type nat hook prerouting priority dstnat; policy accept;
            iifname != { "lo", "ISP*" } fib daddr type != { local, multicast, broadcast } udp dport == 8000 counter jump Redirect_to_local
    }
}

这是不正确的,因为transport protocol mapping is only valid after transport protocol match. 但为什么?它确实匹配,但不是直接匹配。

如果我udp dport == 8000在重定向之前添加,它将被认为是正确的,尽管规则重复(这很烦人)。

有办法克服这个问题吗?还是我误解了这一点?

nftables
  • 1 个回答
  • 48 Views
Martin Hope
avi9526
Asked: 2023-12-12 04:44:49 +0800 CST

我可以提高 nftables 规则集语法的可读性吗?它会影响其功能吗?

  • 6

从手册中我不清楚这些命令的功能是否相同:

meta skuid == "root" counter accept
skuid 0 counter accept

还

ct state == { established,  related } counter accept
ct state established,related counter accept

我关于语法的问题是:

  1. 我可以跳过单词meta(似乎在使用 item 时必须跳过它log flags)?
  2. 我可以在任何匹配某些内容的命令中添加 == 符号(为了可读性)吗?
  3. 我可以将列表(项目集)写为item1,item2或不写{ item1, item2 },或者仅用于ct命令吗?
nftables
  • 1 个回答
  • 24 Views
Martin Hope
Christopher Causer
Asked: 2023-10-07 00:14:16 +0800 CST

nftables:引用另一个表中的集合

  • 6

通过以下设置:

#!/usr/sbin/nft -f
add table ip filter
add chain ip filter input { type filter hook input priority 0; }
add set   ip filter nat-group-1 { type ipv4_addr; }
add set   ip filter nat-group-2 { type ipv4_addr; }
add set   ip filter nat-group-3 { type ipv4_addr; }
add set   ip filter nat-group-4 { type ipv4_addr; }
add set   ip filter nat-group-5 { type ipv4_addr; }
add rule  ip filter input ip saddr @nat-group-1 tcp dport 22 drop
add table ip nat
add chain ip nat postrouting {type nat hook postrouting priority srcnat; policy accept; }
add rule  ip nat postrouting ip saddr @nat-group-1 snat to 192.168.1.0/24 persistent
add rule  ip nat postrouting ip saddr @nat-group-2 snat to 192.168.2.0/24 persistent

我收到错误消息

Error: No such file or directory; did you mean set ‘nat-group-1’ in table ip ‘filter’?

我不知道如何引用另一个表中的集合。这可能吗?怀疑可以通过复制两个表中的集合来解决这个问题,但错误消息让我希望有一些我不知道的语法。

我将引用两个表中的集合。

nftables
  • 1 个回答
  • 25 Views
Martin Hope
FurretUber
Asked: 2023-03-20 10:50:18 +0800 CST

nftables 限制似乎不适用于某些 STUN 请求

  • 6

我正在使用 coturn 设置服务器,仅使用 STUN(TURN 被禁用)。似乎 STUN UDP 可以用于 DDoS,所以我试图设置nftables规则使其更难,但规则似乎并不总是有效。有时,我可以使用以下方式看到类似的内容tcpdump:

21:16:08.006842 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.007091 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.258386 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.258613 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.278988 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.279229 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.475423 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.475734 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.481217 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.481416 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.484939 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.485211 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.490332 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.490545 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.505617 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.505901 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.529745 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.530020 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72
21:16:08.819766 IP 5.39.71.183.25565 > A.B.C.D.3478: UDP, length 20
21:16:08.820048 IP A.B.C.D.3478 > 5.39.71.183.25565: UDP, length 72

这高于 . 上指定的 3/秒限制nft。规则nft是:

#!/usr/sbin/nft -f
flush ruleset

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

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

        iifname lo accept

        tcp dport 1935 ct state new log prefix "[RTMP]: " accept
        tcp dport 443 ct state new log prefix "[HTTPS]: " accept
        tcp dport 3478 ct state new log prefix "[STUN TCP]: " limit rate 5/second accept
        tcp dport 5349 ct state new log prefix "[STUN TLS]: " limit rate 5/second accept
        ########################################################################
        ####### These two rules are where it is not behaving as intended #######
        udp dport 3478 log prefix "[STUN UDP]: " limit rate 3/second accept
        udp dport 3478 log prefix "[STUN UDP THIS RULE]: " limit rate over 3/second drop
        ########################################################################
        ip saddr E.F.G.H ct state new log prefix "[Some server that is allowed]: " accept
        udp dport 5060 ct state new log prefix "[SIP UDP]: " accept
        tcp dport 5060 ct state new log prefix "[SIP TCP]: " accept
        tcp dport 5061 ct state new log prefix "[SIP TLS]: " accept
        udp dport { 5000-31000 } ct state new log prefix "[RTP]: " accept
        ip saddr 0.0.0.0 ip daddr 255.255.255.255 udp dport { 67, 68 } ct state new drop

    }
    chain forward {
        type filter hook forward priority 0;
    }
    chain output {
        type filter hook output priority 0;
    }
}

还有一些额外的规则,因为有一些其他服务正在运行,但即使使用其他端口的其他服务已停止,我也遇到了这个问题。

对我来说最奇怪的是,关于这些数据包只有一个提及dmesg:

[4151543.207466] [STUN UDP]: IN=eth0 OUT= MAC=00:00:00:00:00:00:d4:c1:9e:0b:4d:c0:08:00 SRC=5.39.71.183 DST=A.B.C.D LEN=48 TOS=0x00 PREC=0x00 TTL=241 ID=31022 PROTO=UDP SPT=25565 DPT=3478 LEN=28

很可能我不理解某些东西,无论是关于nftables、STUN、两者还是其他东西。问题:

  1. 规则的顺序错了吗?比如,STUN UDP 规则应该在行之前ct state vmap?

  2. 规则nftables设置为 3/秒限制,不考虑数据包的状态,难道不应该对端口 3478 上收到的每个数据包进行处理吗?

或者可能是我尚未确定的其他原因导致nftables未应用限制。

系统信息:

OS: Debian 11
coturn version: 4.5.2-3 from the Debian repository.
nftables version: v0.9.8 (E.D.S.) from the Debian repository.
nftables
  • 1 个回答
  • 38 Views
Martin Hope
HenkH
Asked: 2023-02-21 22:17:39 +0800 CST

AlmaLinux 9/RHEL 和 nftables:在链中不断获取“类型过滤器钩子输入优先级过滤器”

  • 6

大家好!

首先,我不得不说我是 Linux 新手,也是 StackExchange 的新手,所以我希望我问的问题是正确的。

我想在新的 AlmaLinux 安装(v9.1,最小安装,无头管理和安全工具)上使用 nftables 作为防火墙。为了避免妨碍 firewalld,我禁用了 firewalld:

'''

    # systemctl disable firewalld
    # systemctl stop firewalld
    # systemctl mask firewalld

'''

然后安装并更新 nfs 包到 1.0.4-2-el9 并启动服务:

'''

    # systemctl enable nftables
    # systemctl start nftables

'''

我的意图是为 ip(v4) 和 ip6 创建单独的表(而不是使用 inet),因为我不想使用 ip6。当创建一个单独的 ip6 表时,我可以使用它来丢弃所有 ip6 流量并专注于管理它自己的 ip 表中的 ip(v4)。设置有 2 个接口,一个用于传入 WAN 流量(在它通过防火墙/路由器之后),另一个面向 LAN,包括。服务器的管理。目前接口都在 10.0.0.0/24 上,但是当我想创建一个 DMZ 时,我只需要为 DMZ 配置 WAN 接口。

所以,我创建了表:

'''

    # nft add table ip firewall4
    # nft add table ip6 firewall6
    # nft list tables

'''

确认两个表的存在。

我添加了一个新链并检查了它的内容:

'''

    # nft add chain ip6 firewall6 input { type filter hook input priority 0\; }
    # nft list table ip6 firewall6

'''

我不断得到的输出(无论我做什么或改变)是:

'''

     table ip6 firewall6 {
        chain input {
                type filter hook input priority filter; policy accept;
        }
}

'''

当我尝试另一个优先级(例如 1)时,我得到“type filter hook input priority filter +1; policy。通过键入完整命令(不仅仅是向上)再次删除和插入链

无处不在,在所有示例/操作方法/文档中,我都看到“优先级 0”。我不确定“优先过滤器”是否正确,并且担心要添加的链和规则可能会被忽略,因为显然“过滤器”不同于“0”而且我不明白“过滤器”将如何被优先化同一张表中的其他链。

所以我的问题是:

  1. “优先过滤器”可以吗,或者当我向表中添加更多时它会改变吗?
  2. 如果不行,我可以/应该怎么做才能获得优先价值?

非常感谢大家!

nftables
  • 1 个回答
  • 32 Views
Martin Hope
Arany Péter
Asked: 2022-10-26 03:09:21 +0800 CST

带有端口的 Nft 列表规则集

  • 6

列出规则时有没有办法列出实际端口?

我是说:

nft list ruleset

table ip filter {
    chain INPUT {
        type filter hook input priority 0; policy drop;
        iifname "lo" counter packets 114 bytes 316154 accept
        ct state established,related counter packets 415 bytes 70571 accept
        tcp dport http counter packets 13 bytes 728 accept
        tcp dport http-alt counter packets 0 bytes 0 accept
        tcp dport tproxy counter packets 0 bytes 0 accept
        tcp dport https counter packets 0 bytes 0 accept

http 是 80 我认为 https 是 443 我认为

有没有办法列出端口而不是名称?

nftables
  • 1 个回答
  • 26 Views
Martin Hope
phonon112358
Asked: 2022-04-04 16:53:52 +0800 CST

IPv6 无法在带有 nftables/nginx 的 Debian 11 上运行

  • -1

我正在使用 nftables 0.9.8 的 Debian 11 系统上运行网络服务器(nginx 1.21.6)。我的 nftables 配置是:

table inet filter {
chain input {
  type filter hook input priority filter; policy drop;
            ip saddr @spamhaus4 counter packets 0 bytes 0 drop
            ip6 saddr @spamhaus6 counter packets 0 bytes 0 drop
            meta l4proto tcp meta nfproto ipv4 ip saddr @abused counter packets 0 bytes 0 drop
            ip daddr 46.38.148.0-46.38.151.255 drop
            iif "lo" log group 2 accept
            iif != "lo" ip daddr 127.0.0.0/8 counter packets 0 bytes 0 drop comment "drop connections to loopback not coming from loopback"
            iif != "lo" ip6 daddr ::1 counter packets 0 bytes 0 drop comment "drop connections to loopback not coming from loopback"
            ct state established,related log group 2 accept
            ct state invalid counter packets 47 bytes 2572 drop
            tcp dport { 25, 80, 143, 443, 587, 2772, 9980, 45907 } log group 2 accept
            ip protocol icmp icmp type { echo-reply, destination-unreachable, echo-request, router-advertisement, router-solicitation, time-exceeded, parameter-problem } log group 2 accept
            ip6 nexthdr ipv6-icmp 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, ind-neighbor-solicit, ind-neighbor-advert } log group 2 accept
            ip6 nexthdr ipv6-icmp log group 2 accept
            counter packets 2686 bytes 421604 drop
    }

    chain IPSinput {
            type filter hook input priority filter + 10; policy drop;
            counter packets 88448 bytes 15799025 queue num 0-3 bypass,fanout
    }

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

    chain output {
            type filter hook output priority filter; policy accept;
    }

    chain IPSoutput {
            type filter hook output priority filter + 10; policy drop;
            counter packets 76196 bytes 201278628 queue num 0-3 bypass,fanout
    }
   }

nftables 防火墙工作正常。

但是,我的 nginx 服务器无法通过 IPv6 访问。我使用了不同的 IPv6 检查工具(例如https://ipv6-test.com/validate.php)并且Qualys ssltest无法通过 IPv6 访问服务器,但是 IPv4 工作正常。我在每个 nginx 服务器中都包含了listen [::]:80;(resp.指令。并给出了listen [::]:443;netstat -anlp |grep nginx

tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      48846/nginx: master
tcp        0      0 0.0.0.0:443             0.0.0.0:*               LISTEN      48846/nginx: master
tcp        0      0 192.168.42.98:443       93.104.163.178:39001    VERBUNDEN   48847/nginx: worker
tcp        0      0 192.168.42.98:443       93.104.163.178:39368    VERBUNDEN   48847/nginx: worker
tcp        0      0 192.168.42.98:443       93.104.163.178:43086    VERBUNDEN   48847/nginx: worker
tcp6       0      0 :::80                   :::*                    LISTEN      48846/nginx: master
tcp6       0      0 :::443                  :::*                    LISTEN      48846/nginx: master
unix  3      [ ]         STREAM     VERBUNDEN     160451   48846/nginx: master
unix  3      [ ]         STREAM     VERBUNDEN     160453   48846/nginx: master
unix  3      [ ]         STREAM     VERBUNDEN     160450   48846/nginx: master
unix  3      [ ]         STREAM     VERBUNDEN     160448   48846/nginx: master
unix  3      [ ]         STREAM     VERBUNDEN     160452   48846/nginx: master
unix  3      [ ]         STREAM     VERBUNDEN     160446   48846/nginx: master
unix  3      [ ]         STREAM     VERBUNDEN     160449   48846/nginx: master

在我的路由器上,我也激活了 IPv6。

有谁知道问题出在哪里?

nginx ipv6 nftables
  • 1 个回答
  • 288 Views
Martin Hope
Hooman Valibeigi
Asked: 2022-03-27 01:02:29 +0800 CST

如何在 nftables 中刷新设置元素超时?

  • 1

如何在集合元素过期之前用 nft 刷新它的超时/过期值?

将现有元素添加到集合中不会重置 timeout/expires 值:

nft add element ip mytable myset { 10.10.10.1 timeout 60s }
# wait 10s
nft add element ip mytable myset { 10.10.10.1 timeout 60s expires 60s }
nft list set ip mytable myset

使用 iptables/ipset 我可以通过添加现有元素来刷新超时:

ipset add myset 10.10.10.1 timeout 60
# wait 10s
ipset add myset 10.10.10.1 -exist timeout 60
ipset list myset
nftables linux-networking
  • 1 个回答
  • 264 Views
Martin Hope
Little Code
Asked: 2022-01-22 11:32:21 +0800 CST

nftables (nft) 链优先级问题

  • 1

nft让我头疼不已,无论我如何调整政策,我仍然无法让它发挥作用。

我想到的概念:

  • 一个存在通用规则的“基础”链(例如允许ssh等)
  • 一个或多个特定于守护程序特定规则所在的应用程序(例如 http 服务器链)

我尝试了许多不同的规则排列,但我永远无法同时获得“基础”+ 守护程序流量,我总是最终阻止其中一个!;-(

这是我当前的(简化的)配置(目前构成它允许ssh但不允许http)

/etc/nftables.conf:

#!/usr/sbin/nft -f                                                                                                                                                                                                                                              
flush ruleset                                                                                                                       
table inet filter {   
     counter input_ssh {}     
        set my_admin_ipv4 {                                                                                                        
                type ipv4_addr                                                                                                      
                flags interval                                                                                                      
                counter                                                                                                             
                elements = {                                                                                                        
                        10.0.0.0/8,                                                                                                 
                        172.16.0.0/12,                                                                                              
                        192.168.0.0/16                                                                                                                                                                                      
                }                                                                                                                   
        }         
       chain input {
                type filter hook input priority filter;
                iifname lo accept comment "Allow loopback traffic";
                ct state established,related accept comment "Allow established/related connections";
                ct state invalid drop comment "Deny invalid connections";

                # SSH
                tcp dport ssh ip saddr @my_admin_ipv4 counter name input_ssh accept comment "Allow IPv4 SSH from Admin";
    policy drop;
        }
        chain forward {
                type filter hook forward priority 0;
                policy drop;
        }
        chain output {
                type filter hook output priority 0;
        }
 include "/etc/nft/*.conf"
}

/etc/nft/http.conf:

counter input_http {} 
   chain http {
    type filter hook input priority filter - 1;
      # HTTP #
      tcp dport {80,443} counter name input_nginx accept comment "Allow HTTP";
    policy accept; 
    }
debian nftables
  • 1 个回答
  • 455 Views

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