Page 1 of 1

Noob: Virtualbox networking question

Posted: 16. Oct 2011, 13:05
by topcattony
Hi,

Sorry if this is one of those stupid noob questions but I am having trouble understanding how the networking is handled in Virtualbox.

The scenario: I'm runnning VB 4.1.4 on a windows 7 host with a CentOS 5.5 guest. I want to set up a dev. web server on the guest which I can access from the browser of the windows host where I have my development environment, however, the networking side of things is confusing me. My host is on a 10.0.0.x private network receiving it's IP from a dhcp server on the router (typical home network setup). I have "host only" selected in virtualbox for the virtual NIC. IPCONFIG on the host shows the virtual NC as having a 192.168.x.x private range IP. When I run IFCONFIG on the guest, the IP displayed is in the 10.0.2.x network. If I enter the 192.168.x.x IP of the virtual NIC in the host browser I receive the "It works!" html page - I have no idea where this comes from. But I cannot access any of the apache virtualhosts on the guest machine, even if I add the apache virtualhost domain name and the 192.168.x.x address to the windows hosts file.
Does VB run a kind of virtual router or something - I have no idea how the virtual networking aspect works in VB - where are the IP's coming from and how are packets getting from one network to another?
Any help with this specific problem or a link to a simple introduction to VB networking would be really appreciated.
Many thanks.
Tony

Re: Noob: Virtualbox networking question

Posted: 16. Oct 2011, 13:55
by Sasquatch
Check out the Tutorials and Rules/FAQ section for a guide on the networking options in VB. The IP the Guest has, 10.0.2.15, is what you get when it's set to NAT. This gives the Guest internet access, which is useful in case you need to install something from the repositories, like php5. But if all that is already in place and you just need to get the Apache webserver going, then using Host-Only is the way to go. They can go along side each other, so having two NICs is no problem. You just have to configure them accordingly.

Now, going further with Host-Only, it's best to give the Guest a static IP, unless it's the only VM you have (then it will get the same IP all the time). Set Apache to listen on all interfaces, or the 192.168.56.x address.
If there are multiple domain names, like domain.local and sub.domain.local, then you have to enter each of them in the hosts file on the Host side, like you did with one already. Then you can use the domain names and subsequent subdomains on the Host to test the website.

If you have no idea what I'm talking about, then I suggest you read up on some networking and the Apache documentation so you know how to set it all up. The page showing "It Works!" is the default site in Apache when no configuration is done, or if you try to open the default site, instead of a vhost.

Re: Noob: Virtualbox networking question

Posted: 16. Oct 2011, 15:04
by topcattony
Hey Sasquatch,
Thanks for the reply - I appreciate your time.
I'm still a little confused. You were right about the NAT - I had the NIC set to NAT and not host only which I have now changed.
I have vhosts corectly set which I can access through the browser on the guest. Apache is not set to listen on a specific IP, it is just listening on Port 80. So I don't think Apache is the problem.
The IP of the virtual NIC viewed from the host is 192.168.56.1 but IFCONFIG from the guest shows eth0 as being 192.168.56.101 - I don't really get why the ip address for the virtual NIC is different when looking at it from the host and the guest, my understanding of networking is that an interface has an IP address full stop. I can't even change the IP address statically from within the guest I just get an error msg.
I'm reading the VB networking link that you sent me but any insights are always useful.

Cheers,
Tony

Re: Noob: Virtualbox networking question

Posted: 16. Oct 2011, 19:50
by Sasquatch
Ok, let's compare networking with mobile phones shall we? Now, you have a mobile phone with a number that you have to dial to make it ring. A friend of yours also has a mobile phone. In order to call him, you don't use your own number, for which we use the simple number of 10. Your friend has phone number 12. So you dial 12 to call him.
This is the same in networking, each system has it's own unique address number. The Host has number 1, the Guest 101. To access the Guest, you 'dial' 101. To access the Host, you dial 1. Simple as that.

Re: Noob: Virtualbox networking question

Posted: 16. Oct 2011, 20:08
by topcattony
Hey, thanks for the reply. I actually sorted it out already. I just didn,t realise that when you use "host only" networking mode both the physical machine and virtual machine are placed in a completely virtual network and provided with virtual NIC's by VB. I was assuming the virtual NIC I was seeing on the host was the virtual NIC of the guest not the host's own virtual interface. Clearly the actual network is ridiculously simple I just had no idea what the approach was that VB was using.

Re: Noob: Virtualbox networking question

Posted: 16. Oct 2011, 22:13
by Sasquatch
The interface on the Host is the doorway to the network segment called Host-Only, where the VM that is configured to that interface name (you can have more than one Host-Only interface) can be reached. Networking can be very easy, if you see the logic behind it. Some never will, others need a few minutes to see it.