SSHトンネルを介してUDPを送信するためのiptablesルール

SSHトンネルを介してUDPを送信するためのiptablesルール

質問

2つのリモートコンピュータで実行され、特定のプロトコルを介して通信する2つのプログラムがあります。私が知っているのは、プロトコルがUDPを介してのみ通信し、ポート1101と1102を使用し、両方のコンピュータが同じローカルネットワーク上にある必要があることです。

VPN(p2p)を使ってこれを行いましたが、SSHトンネルを介してiptablesを使用できるかどうかを知りたいです(ここではSSHトンネリングが必須です)。

私は2つのLinux Debian wheezyサーバーを使用して、2つのプログラム間のインターネットを介してトンネルを開きます。 UDPトラフィックを片側から他方へ(すべてのポートに対して)リダイレクトするSSHトンネルを作成しましたが、機能しません。この目的のために、私はsocat(ここではポート1101)を使います。

transmission from computer1 --> port 1101/server1 --> socat to port 61101 --->
---> ssh tunnel ---> 
---> socat from port 61101--> port 1101/server2 --> reception on computer2

私の目標は、「computer2」の観点から、「server2」が「computer1」と同じように動作するようにすることです(またはその逆)。パケットを送信するときは、IPアドレスを正しく変換し、それに応じて送信されるデータも変更する必要があります。

SSH は、鍵ファイルを使用して自動的にログインするように構成されます。

マイトンネルの設定

これは、両方のポートを双方向にリダイレクトするようにトンネルを設定した方法です。

#From server1's shell 
$ ssh -f -N -T -R51101:localhost:51101 login@server2 # reverse tunnel for port 1101
$ ssh -f -N -T -R51102:localhost:51102 login@server2 # reverse tunnel for port 1102
$ ssh -f -N -T -L61101:localhost:61101 login@server2 # tunnel for port 1101
$ ssh -f -N -T -L61102:localhost:61102 login@server2 # tunnel for port 1102

#socat redirection on server1
$ socat TCP4-LISTEN:51101,fork UDP4:server1:1101 #redirects from the tunnel to the local 1101 port
$ socat TCP4-LISTEN:51102,fork UDP4:server1:1102 #redirects from the tunnel to the local 1102 port
$ sudo socat -d -d UDP4-LISTEN:1101,fork,bind=1101 TCP4:localhost:61101  #redirects to both tunnel and local UDP port 1101
$ sudo socat -d -d UDP4-LISTEN:1102,fork,bind=1102 TCP4:localhost:61102  #redirects to both tunnel and local UDP port 1102

#From server2's shell 
#socat redirection on server2
$ socat TCP4-LISTEN:61101,fork UDP4:server1:1101 #redirects from the tunnel to the local 1101 port
$ socat TCP4-LISTEN:61102,fork UDP4:server1:1102 #redirects from the tunnel to the local 1102 port
$ sudo socat -d -d UDP4-LISTEN:1101,fork,bind=1101 TCP4:localhost:51101  #redirects to both tunnel and local UDP port 1101
$ sudo socat -d -d UDP4-LISTEN:1102,fork,bind=1102 TCP4:localhost:51102  #redirects to both tunnel and local UDP port 1102

iptablesを使ってこれを行うことは可能だと思いますが、方法がわかりません。

誰にも解決策はありますか?それとも正しいアドレス変換のためにiptablesを使用する方法についてのヒントはありますか?

ベストアンサー1

おすすめ記事