Web server inside a VM.

This is for discussing general topics about how to use VirtualBox.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Web server inside a VM.

Post by mpack »

I've been impressed by "Trac", the bugtracking software Sun uses for this site, so I thought I'd try creating a Trac installation myself inside an XP VM.

I clone an existing XP Pro VM, selecting host interface networking, the guest has no problem accessing the internet.

I installed Python, Trac and the other packages Trac requires, created a test project, run the web server (Genshi) and using IE inside the guest I can connect to the Trac project using the URL "http://localhost:8000" (as described in the Trac docs).

I now want to browse into it from the host. "http://localhost:8000/ doesn't work. The Trac web server claims (I think) to be using IP address 127.0.0.1, so from the host I also tried "http://127.0.0.1:8000/ - but that also didn't work.

I don't know if my problem is with Trac or Vbox, and I have no experience setting up anything similar (nothing with a web server interface).

Does anyone know what I need to do to get this to work?
vbox4me2
Volunteer
Posts: 5218
Joined: 21. Nov 2008, 20:27
Location: Rotterdam
Contact:

Re: Web server inside a VM.

Post by vbox4me2 »

Use your brain, when using Bridge the Guest has its own IP and you are trying to access it via the Host local IP...
piedoggie
Posts: 19
Joined: 13. Sep 2007, 20:35

Re: Web server inside a VM.

Post by piedoggie »

Don't worry mpack. It's kind of confusing when you first set up virtual machines and get the network going. Simplest solution is to run a web browser on the same machine as your trac implementation. That way you use your local hosts URL and everything should work. Somewhat more difficult is to set up a host to host network between your host machine and guest machine. Then you can use a browser on your host machine but the IP address in the URL should point to the guest machine. Only slightly more complicated is using a bridge external address. Again, point your browser at the IP address of the bridge interface on your network to access trac. In each case, it's not terribly difficult, you just need to know what IP address you're talking to and, if your host and guest are connected to the same network.
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Re: Web server inside a VM.

Post by TerryE »

piedoggie wrote:Simplest solution is to run a web browser on the same machine as your trac implementation...
mpack, I differ in my recommendation. The simplest way is to use Host IF. Also Track is a classic LAMP application, so using XP as a WAMP server seems an odd way to go about things. So not get to grips with a LAMP optimised Linux build such as Ubuntu JeOS? This will happily support Trac in a 256Mb VM.

PS. given that mpack has over 300 posts to his tally, and many very helpful to the OPs, he does have some depth of knowledge in VBox.
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Web server inside a VM.

Post by mpack »

TerryE wrote: mpack, I differ in my recommendation. The simplest way is to use Host IF.
Thanks, that's what I thought.
TerryE wrote: Also Trac is a classic LAMP application, so using XP as a WAMP server seems an odd way to go about things. So not get to grips with a LAMP optimised Linux build such as Ubuntu JeOS? This will happily support Trac in a 256Mb VM.
I have no experience of Linux, and I'm trying to keep my learning curve on this little project within manageable limits. XP I know, VBox I know, Trac and Python I don't know. TCP/IP networking - I know the theory but have little experience.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Web server inside a VM.

Post by mpack »

piedoggie wrote: It's kind of confusing when you first set up virtual machines and get the network going.
Thanks for the response. Actually I'm familiar with how to set up VMs (I've been using VBox for about a year now, and I'm a professional programmer, so I'm not frightened by technical stuff). It's simply that I'm pretty hazy about the nuts and bolts of networking, all I have is a basic understanding of the theory.
piedoggie wrote: Simplest solution is to run a web browser on the same machine as your trac implementation. That way you use your local hosts URL and everything should work.
Yes, I already got that working as mentioned in my message. However I then wanted to test connecting to the the network "from the outside world", as if the web server were on a physical PC and I was connecting to it remotely. That's the bit I don't know anything about. Presumably the guest IP address has to be made visible to the outside network somehow... port forwarding? Ideally I want to connect using a nice readable URL - some kind of DNS config somewhere? I'm floundering, which is why I asked for help.
piedoggie wrote: Then you can use a browser on your host machine but the IP address in the URL should point to the guest machine. Only slightly more complicated is using a bridge external address. Again, point your browser at the IP address of the bridge interface on your network to access trac.
I would like to avoid using bridged networking if at all possible. It hated it when that was all VBox supported (for anything except simple browser networking).
piedoggie wrote: In each case, it's not terribly difficult, you just need to know what IP address you're talking to and, if your host and guest are connected to the same network.
That was my question: which IP address to use (using host interface networking), or how to go about finding out which IP address to use.
vbox4me2
Volunteer
Posts: 5218
Joined: 21. Nov 2008, 20:27
Location: Rotterdam
Contact:

Re: Web server inside a VM.

Post by vbox4me2 »

mpack wrote:That was my question: which IP address to use (using host interface networking), or how to go about finding out which IP address to use.
Let me spell it out again...
Use your brain, when using Bridge the Guest has its own IP and you are trying to access it via the Host local IP...
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Web server inside a VM.

Post by mpack »

vbox4me2 wrote:
mpack wrote:That was my question: which IP address to use (using host interface networking), or how to go about finding out which IP address to use.
Let me spell it out again...
Well, I ignored your previous content-free outburst, but you seem insistant, so let me spell it out for you: I'm well aware of that 127.0.0.1 is incorrect. My question was, what is the correct IP address or alternatively how do I find out? Or implicitly how do I make the guest web server visible to the host?

You seem quick to state the obvious as if it were some kind of revelation, but do you also have anything positive to offer?

Since you already missed two opportunities to say anything useful, I suspect the answer is no.
vbox4me2
Volunteer
Posts: 5218
Joined: 21. Nov 2008, 20:27
Location: Rotterdam
Contact:

Re: Web server inside a VM.

Post by vbox4me2 »

If you are aware that localhost does not connect to the Guest, then why are you trying it anyway and also why are you so confused it doesn't work??? you are contradicting yourself here, first you say you are aware localhost is incorrect, you try it anyway to connect to a Guest webservice, I tell you localhost belongs to whatever machine you are using it from, I tell you to use the Guest IP address and not localhost (in Bridge mode, in NAT you need to portforward) and you still manage to miss the point...

In windows ipconfig, in linux ifconfig will tell you what IP address the machine is using/given, if that matches your LAN configuration (like 192.168.1.11) then that is the address you must use to reach any service to which this address belongs to.
Localhost can only be used on the machine your using, a virtual machine also has its OWN localhost, weither this be via NAT or via a Bridge makes no difference, unless you are tunneling a localhost port to a remote address.

This has nothing to do with an outburst, but everything with the difference between NAT and Bridge (Host interface networking), to which I had assumed you know very well.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Web server inside a VM.

Post by mpack »

So, returning to the practical discussion...

I've read the VBox manual (networking section) again. I can't find anything in there on how to access the guest from the host when using host interface networking. I thought that host interface networking worked by installing a device driver that filtered all network traffic on the host, redirecting guest traffic to the guests. In that case I would have thought that the guest has a visible IP - but I don't know how to find out what it is. The manual describes how IP addresses are assigned in NAT mode, but not host interface mode. I would suspect what I want isn't possible, except I've seen messages on this site claiming that it does work, if you use the guests IP address.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Web server inside a VM.

Post by mpack »

vbox4me2 wrote:If you are aware that localhost does not connect to the Guest, then why are you trying it anyway and also why are you so confused it doesn't work?
I mentioned that "localhost" worked within the guest, by way of proving that the server was up an running - excluding one potential cause of failure.

I also mentioned trying "localhost" on the host, since after all the software is running on the same physical hardware and there was no harm in trying. The fact that it didn't work did not surprise or confuse me, but for completeness I nonetheless described what I'd already tried - in order that people would not suggest things I'd already tried.

Thank you for telling me about "ipconfig" - I've tried that and it worked. If you had said that at the beginning then it would have saved a great deal of wasted bandwidth.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Web server inside a VM.

Post by mpack »

And so to recap the outcome of this discussion:

Using host interface networking, a web server running in a guest is easily made visible to the host. First you use "ipconfig" to find out which IP address the guest is using (ignore whatever IP address Trac tells you it is using). Trac listens on port 8000, so if ipconfig says that the guest IP address is 192.168.1.2 then you can browse into the guest (from the host) using "http://192.168.1.2:8000/".
TerryE
Volunteer
Posts: 3572
Joined: 28. May 2008, 08:40
Primary OS: Ubuntu other
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Ubuntu 10.04 & 11.10, both Svr&Wstn, Debian, CentOS
Contact:

Re: Web server inside a VM.

Post by TerryE »

mpack, it might be worth having a scan of the wiki article Internet Protocol Suite. This describes the four layer IPS model which is somewhat different from the 7 layer OSI one (not that you hear much of that these days since IP has won).

What you need to remember is that the NIC in your PC operates at layer 1. It has a hard-wired (actually PROMmed) default MAC address, but there is nothing to stop a NIC being programmed to respond other MAC addresses and in effect act as multiple devices. The VBox Host IF device driver does precisely that. For each active VM NIC it effectively programmes the host NIC to respond to these MAC addresses; it then incepts these packet and passes them onto the VM and its network drivers. So as far as the layer two IP is concerned, the VM is a separate device on the network. It must either fix its own IP address or negotiate it through DHCP.

Again this process relies on a host which is providing a DHCP service being attached the same Ethernet segment or same Wifi SSID. This has a pool of addresses that it uses to allocate to MAC devices that ask for one. Most home ADSL router default to a Class C private address space such as 192.168.0.* or 192.168.1.* and I note that all your IP addresses are in this last subdomain. Most ADSL routers provide this DHCP service by default. Once this negotiation is done the other devices in the same subnet will talk to the VM using ARP and RARP to map this IP address to the MAC address. Devices in other subnets rely on a router which is on the VMs subnet to route IP to it, though there is a wrinkle with Internet addresses since these use public rather than private IP addresses and therefore the router has to support Network Address Translation, but read the reference if you want to understand more.

Happy hunting with Trac. :)
Read the Forum Posting Guide
Google your Q site:VirtualBox.org or search for the answer before posting.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: Web server inside a VM.

Post by mpack »

TerryE wrote:mpack, it might be worth having a scan of the wiki article Internet Protocol Suite. This describes the four layer IPS model which is somewhat different from the 7 layer OSI one (not that you hear much of that these days since IP has won).
Thanks Terry. In fact, as I've probably mentioned before, I'm reasonably familiar with the theory of TCP/IP networks, having once made a stab at writing my own TCP/IP stack for an embedded system. However that was in the early 90s when RFCs were being created and modified at a frenetic pace, so it soon became clear that it was a never ending task.

What I'm really lacking is platform specific knowledge and experience, eg. the existance of the "ipconfig" tool in Windows... and all the other handy tools you might find on Windows or Linux.
TerryE wrote:What you need to remember is that the NIC in your PC operates at layer 1. It has a hard-wired (actually PROMmed) default MAC address, but there is nothing to stop a NIC being programmed to respond other MAC addresses and in effect act as multiple devices. ...
Thanks very much for that insight. I hadn't realised that the indirection worked at such a low level, but now that I do know it is given me different expectations of what should work.

So... I took my Trac VM into work today and installed it on my laptop which has a wireless connection to a router in the company server room. Run the VM, run Trac and presto! Every PC in the building suddenly has access to the Trac pages on my laptop VM. Magic! :-) Now if I can only work out how to give it a friendly URL instead of that "http://192.168.x.y:8000/" gibberish!

The background to all this was: I had told my boss about how much I liked Trac. My boss inquired with our IT contractor, who moaned about how difficult it would be to set up (talking about whole new server PC, lots of work), so the boss got cold feet. My purpose here to was to demonstrate that even a network novice like me could set it up in a couple of hours. And VBox was ideal for this: I could install software that I didn't intend to keep around without fear of disturbing my normal home PC setup, and then I could easily move it all onto a different PC in order to demonstate it. I'm very pleased! :-)
vbox4me2
Volunteer
Posts: 5218
Joined: 21. Nov 2008, 20:27
Location: Rotterdam
Contact:

Re: Web server inside a VM.

Post by vbox4me2 »

mpack wrote:Now if I can only work out how to give it a friendly URL instead of that "http://192.168.x.y:8000/" gibberish!
Talk to who manages the internal DNS/Routers, its quite easy to reserve an IP address linked to the MAC address from your VM and then link that to your companies internal DNS. Sometimes this will go automatically via the machine(VM) name which gets added to the internal DNS once it has gotten an IP, see also ipconfig/all and entries such as: Host Name and Primary Dns Suffix.
Locked