web-dev-qa-db-ja.com

Linuxでのヘアピニング

Linuxシステムをインストールしたルーターがあります。

ルーターでNATヘアピニングをサポートしたい。

そのような機能はカーネルLinuxに存在しますか?はいの場合、それをアクティブにする方法は?ヘアピニングをサポートするためにカーネルに適用するパッチはありますか?

ウィキペディアからのヘアピニングの説明:

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.
6
Mohamed KALLEL

コメントで指摘されているように、これを行う方法は、次のように、両方の内部サービスに対して2つのNATルールを作成することです。

iptables -t nat -A PREROUTING -d public.ip -p tcp --dport 4444 -j DNAT --to inthost1:12345
iptables -t nat -A PREROUTING -d public.ip -p tcp --dport 5555 -j DNAT --to inthost2:12345
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d inthost1 -p tcp --dport 12345 -j MASQUERADE
iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -d inthost2 -p tcp --dport 12345 -j MASQUERADE

このように、一方の内部ホストが他方にパケットを送信すると、パケットは「ゲートウェイ」(NATボックス)から送信されたように見えるため、NAT =ボックスは応答を取得し、それを他の内部ボックスに転送できます。

1
András Korn