Page 1 of 1

Changing port forwarding after installing the OS

Posted: 19. Aug 2010, 14:34
by nertskull
I've been looking around for a few hours and I'm not fully understanding.

If I set up port forwarding on a machine, install the OS on the virtual machine. Can I change those forwarded ports later?

My situation --> I set up a linux webserver virtual machine (ubuntu-server) running on my host machine (also ubuntu-desktop). I initially set it up to forward port 2222 to ssh 22 on the virtual machine. It worked, and all was well. But then I wanted to change it to forward another port. So something like forward 7683 (just an example) to port 22 on the virtual machine.

I used the VBoxManage setextradata command to add these forwards and then remove them, and then add the new forwarded ports. But now I can not get anything to connect on the new port.

I read something on a webpage somewhere during my search saying I would need to re-install the virtual machine. That once the ports are set you can't change them. Is that true?

I also tried removing all the forwarded ports, and then tried adding them using this command

Code: Select all

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,,22" 
and variants of it, but I can't get anything to connect now.

Any suggestions would be greatly appreciated.

Re: Changing port forwarding after installing the OS

Posted: 22. Aug 2010, 15:39
by Sasquatch
When adding or removing port forward configuration, you have to make sure that VB isn't running (the VM especially). Then you first remove the existing rules, before you add new ones. You can check the VM config file between removing and adding the rule to make sure that there is nothing left of it. Once that's done, you start the VM and check with the netstat -ta command to see if there is anything listening on the port you just forwarded. If it is, then it should be working. If it's not listening, something went wrong and you have to retry. If you do see the listen port, but the forwarding doesn't work, you have to check the configuration inside the Guest OS. With NAT, you have to set it to DHCP, else it won't work.