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_ARG (0x80070057), component NATEngine, interface INATEngine, callee nsISupports
VBoxManage: error: Context: "AddRedirect(Bstr(strName).raw(), proto, Bstr(strHostIp).raw(), RTStrToUInt16(strHostPort), Bstr(strGuestIp).raw(), RTStrToUInt16(strGuestPort))" at line 1524 of file VBoxManageModifyVM.cpp
I'd like to remove all port forwarding rules before doing vagrant up
, but I have trouble LISTING natpf rules. Is there any way to do it using vboxmanage
or via some facilities in Vagrant?
Update: Vagrant version 1.3.4. I can replicate the problem as follows: start vm installation normal way (vagrant up
) and force power off the vm during installation (this simulates e.g. failed install). Then the natpf1 port forwarding rule is left in the system. The only way to clean it up is like vboxmanage modifyvm #{vmid} --natpf1 delete rule_name
, but you have to know the rule name beforehand... Furthermore, the rule stays there after vagrant destroy
and it seems that my Ruby natpf1 clearing function present in Vagrant.configure
is not ran, which means that the stale rule still clashes with "fresh" one that Vagrant attempts to create.
This got the job done for me:
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 thePort 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:
And guess that the name of the rule will be
5432
. The name of the rule for forwarding the ssh port 22, is calledssh
You can delete a rule from the command line by issuing:
the last parameter in quotes is the rule name you wish to delete.
You can list the nat rules by the following command:
You then get a lot of information about your VM including the forwarding rules, for example: