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」を行うことです。つまり、2 つの 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フロントエンドを使用することをお勧めします。ファームウェアビルダー

おすすめ記事