nftables 1:1 NAT(IP 주소 대 IP 주소)

nftables 1:1 NAT(IP 주소 대 IP 주소)

전혀 익숙하지 않은 nftables를 사용하는 Fedora 32로 업그레이드했으며 찾을 수 있는 모든 문서를 숙독한 후에도 nftables를 사용하여 1:1 NAT를 복제하는 방법을 알 수 없습니다. 이는 현재 메일 서버에 연결할 수 없음을 의미합니다.

저는 Firewalld/iptables에서 이러한 규칙을 사용하고 있었습니다.

  <passthrough ipv="ipv4">-t nat -A PREROUTING -i eno1 -d public.ip -j DNAT --to-destination 10.99.99.21</passthrough>
  <passthrough ipv="ipv4">-t nat -A POSTROUTING -s 10.99.99.21 -o eno1 -j SNAT --to public.ip</passthrough>
  <passthrough ipv="ipv6">-t nat -A PREROUTING -i eno1 -d public.ipv6 -j DNAT --to-destination fdb9:b611:5d5d:ffff::21</passthrough>
  <passthrough ipv="ipv6">-t nat -A POSTROUTING -s fdb9:b611:5d5d:ffff::21 -o eno1 -j SNAT --to-source public.ipv6</passthrough>

나는 이것을 시도했지만 작동하지 않는 것 같습니다.

nft list table nat
table ip nat {
        chain postrouting {
                type nat hook postrouting priority srcnat; policy accept;
                ip saddr 10.99.99.21 oif "eno1" snat to public.ip
        }

        chain prerouting {
                type nat hook prerouting priority dstnat; policy accept;
                iif "eno1" ip daddr public.ip dnat to 10.99.99.21
        }
}

추가 정보: 이를 추가로 추적한 결과 어떤 이유로든 일치하지 않는 것은 SNAT 규칙입니다.

답변1

나는 github에서 방화벽 개발자 중 한 명과 이야기를 나눈 후 알아낸 대로 내 자신의 질문에 답할 것입니다.

분명히 문제는 nftables와 iptables가 동시에 사용된다는 것입니다.

인용:

This makes sense. It's due to the fact that iptables and nftables rules are executed independently inside the kernel/netfilter. So your scenarios are:

    iptables backend
        your direct rules accept the packets in the FORWARD chain
        further iptables rules in the FORWARD chain are not evaluated (due to accept)
        firewalld rules are part of iptables, so they're not considered (due to accept)
    nftables backend
        your direct rules accept the packets in the FORWARD chain
        further iptables rules in the FORWARD chain are not evaluated (due to accept)
        packet is now subject to firewalld's nftables ruleset, this happens even if the packet is accepted it iptables.
        zone is using "default" target, so packet is dropped in the FORWARD chain
        due to drop POSTROUTING (SNAT) is never reached

There is no fix possible as it's a result of how the kernel works. You can read more about this in the CAVEATS section of man page firewalld.direct.

원천:https://github.com/firewalld/firewalld/issues/708

따라서 iptables-nft 대안을 통해 생성된 위의 nftables 규칙은 여전히 ​​iptables 커널 코드를 사용하기 때문에 작동하지 않습니다. nft에만 나오네요.

nftables 및 iptables 상호 작용에 대한 자세한 설명은 다음과 같습니다. https://developers.redhat.com/blog/2020/08/18/iptables-the-two-variants-and-their-relationship-with-nftables/

관련 정보