54
53

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VirtualBoxでポートフォワーディングの設定をコマンドラインから追加、削除、表示

Last updated at Posted at 2014-03-05

ポートフォワーディングの追加

OSX上のdockerでCentOS 6.5にnginxを公式レポジトリからインストールするサンプル - Qiitaにも書きましたが、ポートフォワーディングの追加は以下のようにします。

VBoxManage controlvm "boot2docker-vm" natpf1 "nginx,tcp,127.0.0.1,8080,,80"

この例ではlocalhostの8080番ポートをboot2docker-vmの80番ポートにフォワーディングします。

ポートフォワーディングの削除

削除するには追加した時の名前を指定してdeleteします。
参考: VBoxManage controlvmのマニュアル

VBoxManage controlvm "boot2docker-vm" natpf1 delete nginx

ポートフォワーディングの変更

すでに登録済みの名前を再度追加しようとすると

VBoxManage: error: A NAT rule of this name already exists

というエラーが出ます。

ということで、変更するには一旦削除してから追加します。

ポートフォワーディングの確認

VBoxManage showvminfo boot2docker-vm | grep '^NIC'

以下の様な出力が出ます。

NIC 1:           MAC: 080027AB2BD4, Attachment: NAT, Cable connected: on, Trace: off (file: none), Type: virtio, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 1 Settings:  MTU: 0, Socket (send: 64, receive: 64), TCP Window (send:64, receive: 64)
NIC 1 Rule(0):   name = docker, protocol = tcp, host ip = 127.0.0.1, host port = 4243, guest ip = , guest port = 4243
NIC 1 Rule(1):   name = nginx, protocol = tcp, host ip = 127.0.0.1, host port = 8080, guest ip = , guest port = 80
NIC 1 Rule(2):   name = redis, protocol = tcp, host ip = 127.0.0.1, host port = 16379, guest ip = , guest port = 6379
NIC 1 Rule(3):   name = ssh, protocol = tcp, host ip = 127.0.0.1, host port = 2022, guest ip = , guest port = 22
NIC 2:           MAC: 0800270F0BE8, Attachment: Host-only Interface 'vboxnet0', Cable connected: on, Trace: off (file: none), Type: Am79C973, Reported speed: 0 Mbps, Boot priority: 0, Promisc Policy: deny, Bandwidth group: none
NIC 3:           disabled
NIC 4:           disabled
NIC 5:           disabled
NIC 6:           disabled
NIC 7:           disabled
NIC 8:           disabled
54
53
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
54
53

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?