Nat router (network) in VirtualBox 4.3

This is for discussing general topics about how to use VirtualBox.
Post Reply
unbalanced
Posts: 6
Joined: 11. May 2012, 08:29

Nat router (network) in VirtualBox 4.3

Post by unbalanced »

Hey guys.

I'm using Ubuntu 13.04 as the guest (on win7 host). This Virtualbox is used as a web server for development.
Until now i had 2 network adapters - Host Only + Nat.

1. Using VB 4.3, i switched the 2 adapters with the new "Nat Network" adapter. is this OK? does it suppose to save the hassle and complex of having 2 adapters?

2. How can i configure the /etc/network/interfaces file on ubuntu so that the dev server will have a static ip (10.0.2.4)
- i want to use port forwarding from host specifically to that guest and i don't want to get different internal ip each time i boot it.

3. Using the "Nat Network" port forwarding, can i forward port 80 from 127.0.0.1 to port 80 on the ubuntu server (10.0.2.4 virtualbox) in order to allow other computers on my office wifi see the website on my development server?

Really appreciating the help here :)
Thanks!
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: Nat router (network) in VirtualBox 4.3

Post by BillG »

Is there a reason why you don't use bridged mode so that the other machines on the LAN could see the server directly? That seems the obvious way to me.
Bill
unbalanced
Posts: 6
Joined: 11. May 2012, 08:29

Re: Nat router (network) in VirtualBox 4.3

Post by unbalanced »

It has to do with the hosts file settings on other machines on the net. though your approach will work (tried it in the past)
i'd still love to know if anyone knows the answers for the above!

Thanks BillG :)
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: Nat router (network) in VirtualBox 4.3

Post by BillG »

Yes, it should work but it requires a fair bit of work. I haven't tested it fully yet, but I hope to in the near future.
Bill
unbalanced
Posts: 6
Joined: 11. May 2012, 08:29

Re: Nat router (network) in VirtualBox 4.3

Post by unbalanced »

Can anyone tell me how to setup a static ip to each virtual machine under the nat network adapter, Thanks!
noteirak
Site Moderator
Posts: 5231
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Nat router (network) in VirtualBox 4.3

Post by noteirak »

Have you tried setting up the IP in the VM itself, like you would do it on physical machine? does it work?
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: Nat router (network) in VirtualBox 4.3

Post by BillG »

Why would it be any different just because you are using a NAT network?

Or was your question really "how do I manually configure the network settings for a machine using NAT network"?

The answer to that question is - look at the config you get from DHCP and make sure that everything is exactly the same, apart from the actual IP address.
Bill
unbalanced
Posts: 6
Joined: 11. May 2012, 08:29

Re: Nat router (network) in VirtualBox 4.3

Post by unbalanced »

i tried using the following settings on etc/network/interfaces

Code: Select all

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
address 10.0.2.4
netmask 255.255.255.0
network 10.0.2.0
broadcast 10.0.2.255
gateway 10.0.2.2
my nat network is configured: 10.0.2.0/24 and the "support dhcp" is checked.

Couldn't get the connection to work.
Guys I'm really appreciating your responses, thanks!
BillG
Volunteer
Posts: 5106
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: Nat router (network) in VirtualBox 4.3

Post by BillG »

Well that should work if you are in a 10.0.2.0/24 network (ie a network with addresses beginning 10.0.2 and a subnet mask of 255.255.255.0) and a gateway of 10.0.2.2 . Does it work if you get the config from DHCP? What does the config look like then?

I have had a good look at it now and NAT networking works just as advertised for me (even with static IPs). I have set up a Windows domain with static IP on the DC and DHCP for the clients without problems (apart from the standard DNS oddities with NAT and AD).

Here is a check list I would use.
1. Carefully read the manual section on NAT networking.
2. Configure your internal network using a addressing scheme you will remember and enable DHCP. If in doubt use the example from the manual.
3. Set the NIC in the vm to the NAT networking option. Boot the vm.
4. Check that the vm gets an IP from DHCP and that you can access LAN machines from the vm. If you want to make it static, use exactly the same settings as it got from DHCP. Everything should be the same except the last octet of the IP address (ie the machine identifier in the subnet) which you can change.
5. Configure port forwarding in NAT to forward http from the host to the LAN IP of the guest. If you do it properly, an http request from a LAN machine to the host (by name or IP) will get a reply from the webserver in the vm.
Bill
Post Reply