Changing port forwarding after installing the OS

This is for discussing general topics about how to use VirtualBox.
Post Reply
nertskull
Posts: 2
Joined: 19. Aug 2010, 14:22
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Linux

Changing port forwarding after installing the OS

Post 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.
Sasquatch
Volunteer
Posts: 17798
Joined: 17. Mar 2008, 13:41
Primary OS: Debian other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows XP, Windows 7, Linux
Location: /dev/random

Re: Changing port forwarding after installing the OS

Post 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.
Read the Forum Posting Guide before opening a topic.
VirtualBox FAQ: Check this before asking questions.
Online User Manual: A must read if you want to know what we're talking about.
Howto: Install Linux Guest Additions
Howto: Use Shared Folders on Linux Guest
See the Tutorials and FAQ section at the top of the Forum for more guides.
Try searching the forums first with Google and add the site filter for this forum.
E.g. install guest additions site:forums.virtualbox.org

Retired from this Forum since OSSO introduction.
Post Reply