Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

This tutorial taught me how to create an Ubuntu Server (12.10, 64-bit) VM in VirtualBox on a Windows 7 host machine, install Apache and have it serve a site from a dummy domain accessible via the host machine's browser.

It took a day and many attempts (although it seemed I was following the instructions as they were laid out, I was always doing something wrong) and I'd finally done it.

I find Ubuntu as a much seamless development environment than Windows, and so I wanted to same thing on Ubuntu. So, this time, I created an Ubuntu Server VM in VirtualBox on Ubuntu host machine, installed Apache and configured it. But when I access the site via the dummy domain, I get the 'Server not found' error.

Yes, I did modify the /etc/hosts file just as mentioned in the tutorial (which is for Windows 7). But I couldn't get it to work. Don't know what's wrong. Anyone know what else I should be doing?

EDIT: If I am not clear enough, please ask. I am willing to clarify.

share|improve this question
    
Do you want to use the server from your computer (for example to develop) or from others in the network? –  Davisein Nov 28 '12 at 16:04
    
The server is installed in a virtual machine (using virtualbox), and I want to access the test website served by the server from a browser on the host machine. Hope that's clear. I've posted the answer by the way (but can only mark it as answered after 2 days). –  its_me Nov 28 '12 at 16:17
1  
Sure, I have already upvoted your answer which is very good (btw). I just wanted to recommend you to add both host-only and bridged (for internet access). And also the other answer is a requirement in a bridged envirnonment if you want to access to the VM from the outside. To make the question fully clear for others ;) –  Davisein Nov 28 '12 at 16:25
add comment

2 Answers

up vote 2 down vote accepted

If you need to allow other machines in your physical network reach your VM or if the VM needs Internet access, use bridged networking. Otherwise, stick to host-only networking.

  1. Stop your VM and open the settings for it in the VirtualBox (OSE) Manager

  2. Go to the Network tab

  3. Select the network mode at your choice (bridged networking or host-only)

    If you want to use bridged networking, you've to select the right network adapter at Name: ________. For wired connections, you'd select something named like eth0. Wireless connections are usually named wlan0 (the numbers may vary).

  4. Save the settings

  5. Start the Ubuntu VM

  6. When up, you can gather the IP address by running:

    sudo ifconfig
    

    The output should look similar to this:

    eth0      Link encap:Ethernet  HWaddr 08:00:27:f4:c3:7b  
              inet addr:192.168.1.4  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::a00:27ff:fef4:c37b/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:20 errors:0 dropped:0 overruns:0 frame:0
              TX packets:25 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000 
              RX bytes:3244 (3.2 KB)  TX bytes:2512 (2.5 KB)
    
    lo        Link encap:Local Loopback  
              inet addr:127.0.0.1  Mask:255.0.0.0
              inet6 addr: ::1/128 Scope:Host
              UP LOOPBACK RUNNING  MTU:16436  Metric:1
              RX packets:0 errors:0 dropped:0 overruns:0 frame:0
              TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0 
              RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)
    

    In the above output, 192.168.1.4 (on the second line) is the IP address that can be used in your Ubuntu host system to access your VM.

  7. Now open the hosts file in Ubuntu host machine:

    sudo gedit /etc/hosts
    

    (If you don't want to use gedit, replace the word with the name of your favorite editor. E.g. vim, nano.)

    Once the file is open, add this line, and save it:

    192.168.1.4   my-dummy-site.com
    
  8. Open any browser on your host machine and go to my-dummy-site.com to access your website, served right from VirtualBox.

( Special thanks to @iSeth for the help. Entirely based on this answer, bit is NOT the same. )

share|improve this answer
1  
This solution should work. I'm trying a development server with this config right now. Additionally both bridged and host-only can be used at the same time. Bridged do not allow the hosting machine to reach your own server (as far as I know). And the host-only does not allow access to internet (so no updates). I usually use both –  Davisein Nov 28 '12 at 16:04
1  
@Davisein Wrong. Bridged network mode allows your virtual machines to be accessed from the host machine, while also giving it (VM) access to the Internet connection used by the host. :) –  its_me Sep 9 '13 at 10:57
    
True. I don't delete my previous comment so that yours don't look weird but it's wrong. The system that does not allow the hosting and the guest machine to talk is NAT as said here virtualbox.org/manual/ch06.html. –  Davisein Sep 11 '13 at 9:37
add comment

Only root can open ports < 1024, so if a regular user is running VirtualBox it won't open port 80 on Host and forward it to the Guest.

You can allow programs to open privileged ports by running:

setcap 'cap_net_bind_service=+ep' /path/to/executable

I don't know the path to the VirtualBox executable, but you can easily figure it out searching for something similar to "VirtualBox" in the output of ps auxf.

share|improve this answer
    
I will try it out and let you know. Meanwhile, you said that "Only root can open ports < 1024", but I was still able to get it to work (please see my solution below). –  its_me Nov 28 '12 at 13:48
    
@its_me it's because your solution makes use of bridged networking. –  Eric Carvalho Dec 28 '12 at 2:19
    
Ah, okay. Thanks for the clarification Eric. :) –  its_me Dec 29 '12 at 16:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.