Linux의 헤어핀

Linux의 헤어핀

Linux가 설치된 라우터가 있습니다.

내 라우터가 NAT 헤어핀을 지원하길 원합니다

Linux 커널에 이러한 기능이 있습니까? 그렇다면 어떻게 활성화하나요? 헤어핀을 지원하기 위해 커널에 적용할 수 있는 패치가 있습니까?

Wikipedia의 머리핀 설명:

Let us consider a private network with the following:

    Gateway address: 192.168.0.1
    Host 1: 192.168.0.5
    Host 2: 192.168.0.7

    The gateway has an external IP : 192.0.2.1
    Host 1 runs a P2P application P1 on its port 12345 which is externally mapped to 4444.
    Host 2 runs a P2P application P2 on its port 12345 which is externally mapped to 5555.

If the NAT device supports hairpinning, then P1 application can connect to the P2 application using the external endpoint 192.0.2.1:5555.
If not, the communication will not work.

답변1

다음은 iptables"최근" 커널에서 잘 작동하는 것입니다(이후2.4, 10년 이상).

비결은 "역방향 NAT"를 수행하는 것입니다. 즉, 두 개의 NAT 서버에 액세스하는 로컬 네트워크의 모든 호스트의 IP 주소를 게이트웨이의 공용 IP에 매핑하는 것입니다.

다음과 같은 것(예:오직NAT팅 규칙, 방화벽 없음):

iptables -t nat -A PREROUTING -p tcp -m tcp  -s 192.168.0.0/24   -d 192.168.0.5  --dport 4444 -j DNAT --to-destination :12345
iptables -t nat -A POSTROUTING -o eth1  -p tcp -m tcp  -s 192.168.0.0/24   --dport 12345 -j SNAT --to-source 192.10.2.1
iptables -t nat -A PREROUTING -p tcp -m tcp  -s 192.168.0.0/24   -d 192.168.0.7  --dport 5555 -j DNAT --to-destination :12345
iptables -t nat -A POSTROUTING -o eth1  -p tcp -m tcp  -s 192.168.0.0/24   --dport 12345 -j SNAT --to-source 192.10.2.1
iptables -t nat -A PREROUTING -p tcp -m tcp   -d 192.168.0.1  --dport 4444 -j DNAT --to-destination 192.168.0.5:12345
iptables -t nat -A PREROUTING -p tcp -m tcp   -d 192.168.0.1  --dport 5555 -j DNAT --to-destination 192.168.0.7:12345
iptables -t nat -A POSTROUTING -o eth0   -j SNAT --to-source 192.168.0.1

방화벽 규칙을 작성하는 난해한 기술이 처음이라면 다음과 같은 GUI 프런트엔드를 사용하는 것이 좋습니다.펌웨어 빌더.

관련 정보