首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nftables不允许ssh

nftables不允许ssh
EN

Stack Overflow用户
提问于 2021-08-02 13:25:17
回答 2查看 1.6K关注 0票数 0

我的服务器中有如下规则集:

代码语言:javascript
复制
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端口允许连接。

我做错什么了?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2021-10-21 22:15:27

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

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

票数 1
EN

Stack Overflow用户

发布于 2021-10-29 03:27:24

OUTBOUND链更改为:

代码语言:javascript
复制
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响应.

  • 总是在每个默认拒绝链的末尾记录丢弃的数据包。当某些东西不起作用时,通常是防火墙问题。
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68622404

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档