iptables転送の問題

iptables転送の問題

eth0とeth1という2つのインターフェースを持つLinuxがあります。 1つは「外部」、もう1つは「内部」です。ポートを外部インターフェイスから内部インターフェイスにリダイレクトしたいのですが、リターンにはいくつかの問題があります。パケットの質問です。しかし、外部から外部に渡すと問題はありません。外部で動作し、これを実行するiptablesコードは次のとおりです。

iptables -t nat -A PREROUTING -p tcp --dport (port number) -j DNAT --to-destination (ipdestiny internal):(port destiny who are listening in the host in this case is the same of dport)
iptables -t nat -A POSTROUTING -p tcp -d (ipdestiny internal) --dport (port number) -j SNAT --to-source (ip external)

"internal eth"でtcpdumpを実行すると:TCPdump:

09:53:55.099904 IP (tos 0x8, ttl 127, id 21212, offset 0, flags [DF], proto TCP (6), length 52)
    ipexternal.(61236 port origin) > ipinternal.(port destiny): Flags [S], cksum 0x1aba (correct), seq 3030159247, win 64240, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
        0x0000:  4508 0034 52dc 4000 7f06 832b 0ac8 2840  E..4R.@....+..(@
        0x0010:  c0a8 3204 ef34 0050 b49c 8f8f 0000 0000  ..2..4.P........
        0x0020:  8002 faf0 1aba 0000 0204 05b4 0103 0308  ................
        0x0030:  0101 0402

私が見ることができるように、内部的に転送されたトラフィックは機能しますが、内部から外部に「返される」ことはありません。 /etc/sysctl.conf 次の行を確認しました。

net.ipv4.ip_forward=1

そしてコメントはありません。

これが私がnatテーブルを見る方法です:

iptables -t nat -L -n

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:(port number listening on "external") to:(destiny ip "internal"):(port destiny in the "internal")

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination
SNAT       tcp  --  0.0.0.0/0            (ip destiny)       tcp dpt:(port number listening on "external") to:(ip "external")


Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

ベストアンサー1

クライアントはトラフィックを受信しますが、戻りトラフィックをどこに送信するかわからない場合があります。クライアントコンピュータで固定パスまたはデフォルトゲートウェイを定義します。

おすすめ記事