VirtualBox の NAT の設定

VirtualBox のネットワークの設定は NAT がデフォルトである。NAT ということは Guest から外に出て行く分にはいいけど、外から Guest に ssh などで接続しようとしたときに Host OS の port と Guest OS の port を map する必要がある。

で、その方法をヘルプより抜粋。

You can set up a guest service which you wish to proxy using the command line tool VBoxManage. You will need to know which ports on the guest the service uses and to decide which ports to use on the host (often but not always you will want to use the same ports on the guest and on the host). You can use any ports on the host which are not already in use by a service. An example of how to set up incoming NAT connections to a ssh server on the guest requires the following three commands:

VBoxManage setextradata "Linux Guest"
  "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/Protocol" TCP
VBoxManage setextradata "Linux Guest"
  "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/GuestPort" 22
VBoxManage setextradata "Linux Guest"
  "VBoxInternal/Devices/pcnet/0/LUN#0/Config/guestssh/HostPort" 2222

※ Windows 版にもこのコマンドは存在する。

実はこの設定について GUI からは方法がないのは以前から知っていたんだけど、調べるのが面倒で Q.app と VirtualBox をいったりきたりしていた。でももうこれで Q.app をやめることができそうだ。

本当は extradata でこんな長い文字を打たせなくてもいいように network の設定をうまく抽象化してほしいなぁとは思うところだけど、それは今後に期待ということにしよう。

More