LIST natpf rules in Virtualbox/Vagrant

You can list the nat rules by the following command:

VBoxManage showvminfo #{vmid}

You then get a lot of information about your VM including the forwarding rules, for example:

NIC 1 Rule(1):   name = ssh, protocol = tcp, host ip = 127.0.0.1, host port = 2022, guest ip = , guest port = 22

This got the job done for me:

VBoxManage showvminfo $VM_NAME --machinereadable | awk -F '[",]' '/^Forwarding/ { printf ("Rule %s host port %d forwards to guest port %d\n", $2, $5, $7); }'

I came here with the same problem; with your hint about deleting the rule I found that you can use the VirtualBox GUI to find the rules and delete them.

Of course, this only works when you are working on a machine with a GUI desktop.

  • Open the VirtualBox manager
  • Open the settings for the box in question (rmb -> settings, or the gear icon)
  • Select Network from the list on the left and open the Port Forwarding dialogue

From here you'll be able to directly remove the rules.

http://i.stack.imgur.com/6fQQc.png


Looking at the rules, it seems they just get a name that is equal to the port being set. So you can also look at the Vagrantfile, and search for a line like this:

db.vm.network :forwarded_port, guest: 5432, host: 5432

And guess that the name of the rule will be 5432. The name of the rule for forwarding the ssh port 22, is called ssh

$ vboxmanage modifyvm "vbox-id" --natpf1 delete "5432"