nftables 环回连接在 CentOS 7 中不起作用

nftables 环回连接在 CentOS 7 中不起作用

我已在 CentOS 7 (内核) 中删除firewalld并安装。我的规则集如下:nftables3.10.0-1160.42.2.el7.x86_64

# nft list ruleset

table ip my_table {
        set ssh_evils {
                type ipv4_addr
        }

        set sip_evils {
                type ipv4_addr
        }

        set dialers {
                type ipv4_addr
        }

        set sip_origins {
                type ipv4_addr
                elements = { 27.a.b.c, 51.p.q.r,
                             139.x.y.z }
        }

        set port_fw {
                type ipv4_addr
                elements = { 27.a.b.c }
        }

        set iax_ports {
                type inet_service
                elements = { 4501 }
        }

        chain input {
                type filter hook input priority 0; policy drop;
                iif "lo" accept
                tcp dport ssh ip saddr @ssh_evils counter packets 0 bytes 0 drop
                udp dport sip ip saddr @sip_evils counter packets 0 bytes 0 drop
                ct state vmap { invalid : drop, established : accept, related : accept, new : accept }
                udp dport { 1100-1199, 10000-20000 } accept
                udp dport @iax_ports accept
                udp dport { sip } ip saddr @sip_origins accept
                udp dport { sip } ip saddr @dialers accept
                tcp dport { ssh, http, https } accept
                icmp type echo-request limit rate 500/second accept
        }

        chain dummy1 {
                type filter hook prerouting priority -100; policy accept;
        }

        chain dummy2 {
                type filter hook forward priority 0; policy accept;
        }

        chain dummy3 {
                type filter hook postrouting priority 100; policy accept;
        }

        chain port_forward {
                type nat hook prerouting priority -10; policy accept;
                tcp dport 40004 ip saddr @port_fw dnat to 192.168.101.4:http
                tcp dport 40005 ip saddr @port_fw dnat to 192.168.101.5:http
                tcp dport 40009 ip saddr @port_fw dnat to 192.168.101.9:http
                tcp dport 50001 ip saddr @port_fw dnat to 10.1.1.2:http
        }

        chain sip_forward {
                type nat hook prerouting priority -10; policy accept;
                udp dport { 6060-6080 } redirect to :sip
        }

        chain tmp_forward {
                type nat hook prerouting priority -10; policy accept;
        }

        chain masq {
                type nat hook postrouting priority 10; policy accept;
                masquerade
        }
}

我已经firewalld彻底卸载并且没有任何iptables规则。

但这种nftable配置不允许loopback连接,甚至ping 127.0.0.1会超时。

其他功能(例如http端口ssh转发等)运行良好。

我找不到任何解决方案。nft monitor没有打印任何内容。

答案1

我找到答案了!问题出在无条件masquerading规则上。

我更换了

chain masq {
        type nat hook postrouting priority 10; policy accept;
        masquerade
}

chain masq {
        type nat hook postrouting priority 10; policy accept;
        oif != "lo" masquerade
}

问题解决了!

相关内容