【问题标题】:nftables don´t allow sshnftables 不允许 ssh
【发布时间】:2021-10-07 20:31:08
【问题描述】:

我的服务器中有一个规则集,如下所示:

table inet firewall {
    chain INBOUND {
        type filter hook input priority filter; policy drop;
        ct state established,related accept
        ct state invalid drop
        iif "lo" counter packets 0 bytes 0 accept
        ip protocol icmp limit rate 4/second accept
        ip6 nexthdr ipv6-icmp limit rate 4/second accept
        ip protocol igmp limit rate 4/second accept
        tcp dport 22 accept
        log
    }

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

    chain OUTBOUND {
        type filter hook output priority filter; policy drop;
        oif "lo" counter packets 35 bytes 1946 accept
        tcp dport 22 accept
    }
}

即使端口 22 应该打开,我也无法从 ssh 连接。如果我输入:

$ nft flush ruleset,那么,22端口允许连接。

我做错了什么?

【问题讨论】:

    标签: server connection port nftables


    【解决方案1】:

    在我看来,“OUTBOUND”链中的规则是问题所在。

    您有 tcp dport 22 accept,但我认为应该是 tcp sport 22 accept,因为当 SSH 数据包从您的服务器出站时,它们的源端口是 22,而不是目标端口 22。

    【讨论】:

      【解决方案2】:

      将您的 OUTBOUND 链更改为:

      chain OUTBOUND {
          type filter hook output priority filter; policy drop;
      
          # Allow traffic from established and related packets, drop invalid
          ct state vmap { established : accept, related : accept, invalid : drop }
          
          # Allow loopback
          oif "lo" accept
      
          # Accepted ports out (DNS / DHCP / TIME / WEB for package updates / SMTP)
          ct state new udp dport { 53, 67, 123, 547 } accept
          ct state new tcp dport { 53, 80, 443, 587 } accept 
      
          log prefix "DROP_output: " limit rate 3/second     
      }
      
      • 不接受 related 出站连接已停止 sshd 响应。

      • 始终在每个默认拒绝链的末尾记录丢弃的数据包。通常,当某些东西无法正常工作时,就是防火墙问题。

      【讨论】:

        猜你喜欢
        • 2017-02-05
        • 1970-01-01
        • 2016-05-03
        • 1970-01-01
        • 2017-06-01
        • 1970-01-01
        • 2018-01-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多