(PuTTYユーザマニュアルの日本語訳) 3.5 SSHでポート転送を使う - 3.5 Using port forwarding in SSH

http://the.earth.li/~sgtatham/putty/0.60/htmldoc/Chapter3.html#using-port-forwardingの日本語訳です。<< 3.4 SSHのX11転送を使う - 目次に戻る - 3.6 生のTCP接続を作る >>

訳文

SSHプロトコルには、暗号化されたSSH接続上で任意のネットワーク接続を転送することで、平文のままのネットワークトラフィックの送信を回避する機能があります。これを利用すると、例えば、自宅のコンピュータからリモートマシン上のPOP-3サーバへの接続時、POP-3パスワードがネットワークスニファから見えなくなります。

The SSH protocol has the ability to forward arbitrary network connections over your encrypted SSH connection, to avoid the network traffic being sent in clear. For example, you could use this to connect from your home computer to a POP-3 server on a remote machine without your POP-3 password being visible to network sniffers.

ローカルマシーンのポートからリモートマシンのポートへポート転送を行うには、以下が必要です。

In order to use port forwarding to connect from your local machine to a port on a remote server, you need to:

  • PuTTYが接続待ちするローカルマシンのポートを選択します。未使用のポート番号は3000番以上にたくさんあるでしょう。(ここでローカルループバックアドレスを使用することもできます。詳細は最後の方を参照ください。)
  • SSH接続をする前に、トンネルパネルを開きます(4.23節参照)。「ローカル」ラジオボタンを選択します。「源ポート」テキストボックスに選択したローカルポートを入力します。「送り先」テキストボックスに、コロン区切りで送り先ホスト名とポート番号を入力します(例えば、POP-3サーバへの接続する場合にはpopserver.example.com:110と入力します)。
  • 「追加」ボタンをクリックします。ポート転送の詳細がリストボックスに表示されます。
  • Choose a port number on your local machine where PuTTY should listen for incoming connections. There are likely to be plenty of unused port numbers above 3000. (You can also use a local loopback address here; see below for more details.)
  • Now, before you start your SSH connection, go to the Tunnels panel (see section 4.23). Make sure the ‘Local’ radio button is set. Enter the local port number into the ‘Source port’ box. Enter the destination host name and port number into the ‘Destination’ box, separated by a colon (for example, popserver.example.com:110 to connect to a POP-3 server).
  • Now click the ‘Add’ button. The details of your port forwarding should appear in the list box.

設定が済んだら、セッションを開始してログインします。(ポート転送はログインするまで有効になりません。というのも、ログインする前からポート転送が有効であるとすれば、全くの匿名によるネットワーク攻撃が容易に可能となり、誰でもVPNにアクセスできてしまうからです)。PuTTYがポート転送を正しく設定しているかは、PuTTYのイベントログで確認できます(3.1.3.1節参照)。イベントログには以下のように出力されます。

Now start your session and log in. (Port forwarding will not be enabled until after you have logged in; otherwise it would be easy to perform completely anonymous network attacks, and gain access to anyone's virtual private network.) To check that PuTTY has set up the port forwarding correctly, you can look at the PuTTY Event Log (see section 3.1.3.1). It should say something like this:

2001-12-05 17:22:10 Local port 3110 forwarding to
         popserver.example.com:110

ここで、ローカルPCの源ポートに接続すると、送り先マシンで実行中のサービスに接続した場合と同様の応答が得られます。この例では、popserver.example.com:110の代わりにlocalhost:3110をPOP-3サーバとして使用するようにemailクライアントに設定できます。(当然、PuTTYのセッションを終了すると、ポート転送は停止されます)。

Now if you connect to the source port number on your local PC, you should find that it answers you exactly as if it were the service running on the destination machine. So in this example, you could then configure an e-mail client to use localhost:3110 as a POP-3 server instead of popserver.example.com:110. (Of course, the forwarding will stop happening when your PuTTY session closes down.)

また、逆方向にポート転送を行うことも可能です。つまり、サーバマシン上の特定のポート番号をPCに転送することで、PC上のサービスに接続しているかのように見えます。これを使用するには、「ローカル」ラジオボタンの代わりに「リモート」ラジオボタンを選択します。「源ポート」テキストボックスにはサーバ上のポート番号を設定します(ほとんどのサーバは、ポート転送で1024番以下のポート番号の使用を許可していません)。

You can also forward ports in the other direction: arrange for a particular port number on the server machine to be forwarded back to your PC as a connection to a service on your PC or near it. To do this, just select the ‘Remote’ radio button instead of the ‘Local’ one. The ‘Source port’ box will now specify a port number on the server (note that most servers will not allow you to use port numbers under 1024 for this purpose).

ローカル接続をリモートホストに転送するための別の方法として、動的SOCKSプロキシがあります。これを使用するには、「ローカル」の代わりに「ダイナミック」ラジオボタンを選び、「送り先」テキストボックスを未入力にします(何か入力しても無視されます)。PuTTYは指定されたポートで待ち受け、このポートに接続するプログラムに対してSOCKSプロキシサービスを提供します。例えば、プロキシパネルを設定(詳しくは4.15節参照)すれば、別のPuTTY接続をSOCKSプロキシで転送できます。

An alternative way to forward local connections to remote hosts is to use dynamic SOCKS proxying. For this, you will need to select the ‘Dynamic’ radio button instead of ‘Local’, and then you should not enter anything into the ‘Destination’ box (it will be ignored). This will cause PuTTY to listen on the port you have specified, and provide a SOCKS proxy service to any programs which connect to that port. So, in particular, you can forward other PuTTY connections through it by setting up the Proxy control panel (see section 4.15 for details).

通常、転送された接続の源ポートは、(ローカル転送とリモート転送でそれぞれ)SSHクライアントマシンとSSHサーバマシン以外からの接続を受け付けません。この動作はトンネルパネルで変更できます。

The source port for a forwarded connection usually does not accept connections from any machine except the SSH client or server machine itself (for local and remote forwardings respectively). There are controls in the Tunnels panel to change this:

  • 「ローカルポートは他のホストからのみ接続を受け入れる」オプションをチェックすると、ローカルからリモートへのポート転送(ダイナミックポート転送も含む)で、クライアントPC以外のマシンが転送ポートへ接続できるようになります
  • 「リモートポートも同様」オプションをチェックすると、リモートからローカルへのポート転送で同様のことができます(つまり、SSHサーバマシン以外のマシンが転送ポートに接続できるようになります)。なお、この機能はSSH-2プロトコルでのみ有効で、SSH-2サーバがこの機能を許可しているとは限りません(例えば、OpenSSHでは、この機能はデフォルトで無効になっています)。
  • The ‘Local ports accept connections from other hosts’ option allows you to set up local-to-remote port forwardings (including dynamic port forwardings) in such a way that machines other than your client PC can connect to the forwarded port.
  • The ‘Remote ports do the same’ option does the same thing for remote-to-local port forwardings (so that machines other than the SSH server machine can connect to the forwarded port.) Note that this feature is only available in the SSH-2 protocol, and not all SSH-2 servers honour it (in OpenSSH, for example, it's usually disabled by default).

待ち受けるIPアドレスを指定することもできます。通常、Windowsマシンは127から始まるどのIPアドレスでも待ち受けることができます。なお、これらのアドレスはすべてローカルマシンへのループバックアドレスです。したがって、(たとえば)127.0.0.5:79をリモートマシンのfingerポートに転送すれば、finger fred@127.0.0.5のようなコマンドを実行できます。これは、接続先ポート番号を変更できないプログラムの接続を転送したい場合に有効です。この機能は、ローカルからリモートへのポート転送で利用できます。SSH-1はリモートからローカルへのポート転送でこの機能をサポートしていません。また、SSH-2は理論上、リモートからローカルへのポート転送でこの機能をサポートしますが、サーバーによるサポートは必須ではありません。

You can also specify an IP address to listen on. Typically a Windows machine can be asked to listen on any single IP address in the 127.*.*.* range, and all of these are loopback addresses available only to the local machine. So if you forward (for example) 127.0.0.5:79 to a remote machine's finger port, then you should be able to run commands such as finger fred@127.0.0.5. This can be useful if the program connecting to the forwarded port doesn't allow you to change the port number it uses. This feature is available for local-to-remote forwarded ports; SSH-1 is unable to support it for remote-to-local ports, while SSH-2 can support it in theory but servers will not necessarily cooperate.

(Windows XP サービスパック2を使っている場合、127.0.0.5のようなアドレスを使うにはMicrosoftの修正パッチを適用する必要があります。これについては、A.7.20の質問を参照してください。)

(Note that if you're using Windows XP Service Pack 2, you may need to obtain a fix from Microsoft in order to use addresses like 127.0.0.5 - see question A.7.20.)

<< 3.4 SSHのX11転送を使う - 目次に戻る - 3.6 生のTCP接続を作る >>