NAT port forwarding with static IP address

This is for discussing general topics about how to use VirtualBox.
Post Reply
vom
Posts: 3
Joined: 11. Aug 2011, 11:23
Primary OS: Linux other
VBox Version: OSE other
Guest OSses: Linux

NAT port forwarding with static IP address

Post by vom »

I am trying to set up a NAT interface with port forwarding where the IP address of the interface is static i.e. assigned by a script in the OS. (Don't ask me why I need this because it would take ages to explain. The short version of the explanation would be that I need it for the lab environment.)

I have tried this in several ways and haven't succeeded. I tried to find something about this issue on the Internet but it seems that no one has run into this problem before (or I am a lousy user of the search engine). I also tried with a simple one-Ubuntu-guest setup just to check if it is working with that setup, and it did not.

So the setup is following:
-One node on VirtualBox 3.2.8 (yes, I am using an old version for the moment)
-Guest OS is Ubuntu
-One NAT interface

In order to activate the port forwarding to a static IP address I do the following:
1) Shut down the node
2) Add the PF rule with:

Code: Select all

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,192.168.130.48,22"
3) Start the node
4) Since eth0 automatically gets assigned 10.0.2.15 i change it using

Code: Select all

ifconfig eth0 192.168.130.48 netmask 255.255.255.0
5) I try to reach the node with SSH with no luck

I have redone this several times trying to reach other ports on the guest (e.g. 3333) with e.g. netcat but the forwarding just doensn't seem to be working.

In the user guide (http://www.virtualbox.org/manual/ch06.html#natforward) it says:
If for some reason the guest uses a static assigned IP address not leased from the built-in DHCP server, it is required to specify the guest IP when registering the forwarding rule:

VBoxManage modifyvm "VM name" --natpf1 "guestssh,tcp,,2222,10.0.2.19,22"

This example is identical to the previous one, except that the NAT engine is being told that the guest can be found at the 10.0.2.19 address.
Am I doing something wrong here?

Thank you in advace.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: NAT port forwarding with static IP address

Post by Perryg »

vom
Posts: 3
Joined: 11. Aug 2011, 11:23
Primary OS: Linux other
VBox Version: OSE other
Guest OSses: Linux

Re: NAT port forwarding with static IP address

Post by vom »

Thank you for your reply but this doesn't solve my problem since I want (actually need) to avoid DHCP.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: NAT port forwarding with static IP address

Post by Perryg »

Not going to happen. You still need to be in that range. then set it static.
Martin
Volunteer
Posts: 2562
Joined: 30. May 2007, 18:05
Primary OS: Fedora other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: XP, Win7, Win10, Linux, OS/2

Re: NAT port forwarding with static IP address

Post by Martin »

The manual chapter from Perry's link doesn't talk about DHCP.
Did you configure the Vbox NAT engine to use your 192.168.x.y network using the --natnet1 parameter?
vom
Posts: 3
Joined: 11. Aug 2011, 11:23
Primary OS: Linux other
VBox Version: OSE other
Guest OSses: Linux

Re: NAT port forwarding with static IP address

Post by vom »

OK, I have missinterpreted the point of that chapter. I've made it work now with changing the IP range.

Just to conclude here if someone else runs into this problem. The IP address used in the --natpf command must be in the address range of the NAT interface (which defaults to 10.0.x.0/24, where x corresponds to the instance of the NAT interface +2). The address range can be modified using --natnet.

Thank you very much guys!
Post Reply