I often get errors like this when running Vagrant:
VBoxManage: error: A NAT rule of this name already exists
VBoxManage: error: Details: code NS_ERROR_INVALID_AR
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.
Network
from the list on the left and open the Port Forwarding
dialogueFrom 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"
You can delete a rule from the command line by issuing:
VBoxManage controlvm "boot2docker-vm" natpf1 delete "tcp-port80"
the last parameter in quotes is the rule name you wish to delete.
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); }'
Expanding on Andrew's answer, this lists the rules for all your VMs
for vm in `vboxmanage list vms | awk -F'"' '$0=$2'`
do
echo "Rules for VM $vm"
VBoxManage showvminfo $vm --machinereadable | awk -F '[",]' '/^Forwarding/ { printf ("Rule %s host port %-5d forwards to guest port %-5d\n", $2, $5, $7); }'
printf '\n'
done
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