How can I access Apache (on VirtualBox guest) from host?
I installed Apache on an Ubuntu VM. When I go into the guest and load up Firefox I can see that Apache is working fine when I browse to localhost.
I would like to access this same page through the host. I've tried using the IP address of the guest but nothing comes up.
Ideally I would love to set up my Windows 7 (host) to request
http://guestserver.comof the Apache server on the guest. How can I do this?
I found site which helped me solve it. Below answers are correct but not showing anything about creating virtual adapter in VM. Site I referred is: https://christophermaier.name/2010/09/01/host-only-networking-with-virtualbox/
If you need other machines in your physical network to be able to reach your VM (or if the VM needs Internet access), use bridged networking. Otherwise, stick to host-only networking.
- Stop your VM and open its settings in the VirtualBox (OSE) Manager
- Go to the Network tab
Select the network mode at your choice (bridged networking or host-only) (in the below example, I'm using 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)
- Save the settings
- Start the Ubuntu VM
When up, you can gather the IP address by running:
ifconfig | grep addr
In the below output,
192.168.56.101is the IP address that can be used in your Win7 host system to access your VM:
eth0 Link encap:Ethernet HWaddr 08:00:27:70:27:fe inet addr:192.168.56.101 Bcast:192.168.56.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe7b:25fe/64 Scope:Link inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host
In your windows host system, edit
C:\Windows\System32\drivers\etc\hostsas administrator and add a line:
If you've a Ubuntu host system, edit
sudo nano /etc/hosts
This worked perfectly for host-only networking and I can now access the guest from the host's browser. However with a bridged connection, which I would like, I don't have access to the internet from the guest.
If anyone can help me out with the bridged connection that would be great, I don't know if I'm doing anything wrong, I just selected bridged and started up the guest, but didn't have any connection to the internet, neither from the host.
That's weird, perhaps you need to reboot your physical machine? Please note that this Q&A site is for Ubuntu. If you've windows-related questions, visit http://superuser.com/
Ok thanks, I switched to wireless connection and it works now, I'll restart later and if it doesn't work I'll ask on superuser.com, thanks for your help.
If you really mean ipconfig, then 'config' is not a command on Windows. Where do you run the command in step 6?
@Max That was a typo, it should be `grep`. An alternative command is just `ip addr`, but definitely not `config`.
@Lekensteyn Are the steps you mentioned above valid for the bridged mode also or some change must be done somewhere ?
@begueradj Those steps above apply to bridged networking but some networks do not allow/give you multiple addresses. On my uni, I could not use bridged networking because of that, in those situations I would use NAT with port forwarding instead.
Enabling two network adapters, one NAT and bridged, allowed me to see and bee seen.
In my case, I have a router assigning a static IP to my Host PC.
Set the network adapter as Bridge:
Settings > Network > Adapter 1 (Enable Network Adapter) > Attached to: (Bridge Adapter) > OK
Start the Virtual Machine > log in
Change the VirtualMachine's IP from dynamic to static
sudo nano /etc/network/interfaces
Under The primary network interface change the word dhcp to static and enter your new static IP or comment the line and add a new one
#iface eth0 inet dhcp iface eth0 inet static address 192.168.10.110 netmask 255.255.255.0 gateway 192.168.10.1 network 192.168.10.0 broadcast 192.168.10.255
Notice my router is working at xxx.xxx.10.x and yours could be at xxx.xxx.0.x or xxx.xxx.1.x or some else.
After you do that, you can have internet conection in both host and guest machine, and type that static IP in your web browser to check you apache server.
Instead of trying to set the adapters to Bridged or Host Only Network Adapter, you can try Port forwarding under Firewall/ Other ports, with your port no set to tcp and udp connections.
This is by far the easiest option for just a web server. Leave your guest networking as NAT, and forward any ports you need onto your host. Simple. The bonus is you still have access to all your networks from the guest. When you bridge you only have access to the bridged network.
The accepted answer did not work for me (I installed virutalbox inside ubuntu 12.04 LTSand inside virtualbox I installed ubuntu 14.04 LTS Server). I just swapped the network settings for Adapter1 and Adapter2 i.e. setting up Adapter1 for "bridged networing" and Adapter2 for "NAT" and it started working.
This was useful, but switch the adapter order so the guest uses NAT by default and be able to connect to the internet.
This actually worked for me. I'm trying to access a Windows VM from within a Mac Host.
If you only need a specific port (Say if you are running a web application like Jetty or Tomcat) just do:
Settings -> Network -> Set one of the adapters as NAT -> Press 'Port forwarding' -> Set the relevant host and guest port.
Once you save, You could just go from your local machine to localhost:hostport and it'll be redirect to the virtual box relevant port and you are done.
If you cant connect over ip you're not likely to have any success with dns names on a default apache install.
check the network settings of the virtual host, I always putt it to bridged to it can be accessed throughout the entire network.
do you get an IP in the quest OS? I usually set up multiple NIC's to match all my physical NIC's. Can you perhaps dump your ifconfig from the quest and host
When I'm working with wireless it works but with cable no, here are some screenshots showing my config: http://imageshack.us/photo/my-images/832/guestr.png/ http://imageshack.us/photo/my-images/846/virtualbox.png/ http://imageshack.us/photo/my-images/9/hostwin7.png/
it looks like your computer is directly connected to the internet and that may be the reason why your client isn't getting a IP (v4)
my computer connects to the router and then to the internet. Is there anything I can do to make the guest user be able to connect?
so it is impossible to connect my virtualbox guest to the internet when my host is directly connected to the modem?
Lekensteyn's answer is right. But if you are in a corporate environment, you might have to disable the proxy server for your guest's IP address. For example, if you are using Mozilla Firefox on your Host machine and you are trying to access 192.168.56.101/ on the guest, you need to go to Firefox's Tools->Options->Advanced->Network->Settings and use "No Proxy" or "No Proxy For -> 192.168.56.101".
If you need to access a guest which gets different IP due to use of DHCP, I suggest accessing via it's hostname. However accessing via hostname when the host is Windows might require an extra tool.
The following text was copied from my own answer at superuser.com.:
I suggest you use Multicast DNS to fix this.
Ubuntu is using this by default via Avahi.
The Windows host needs an Avahi-client for it to discover other Avahi-services. If your host already uses some Apple software this is probably already there via a service called Bonjour. However, if this is not already installed then a small version of Bonjour is available for download here: Bonjour Print Services. After installation you should be able to access your guest via .local.
Note: The mDNS system seem to use the .local postfix by default. So, if your hostname is "dev.myapp.com", then the actual hostname will be "dev.myapp.com.local".
i solved the same problem after search a lot and read a lot of message in the next form:
1) Mount a Virtual Machine in Virtual Box 6.1 with an empty versión of Ubuntu Server 16.04, 2GB RAM and one CPU. The host Machine is Windows 7 conected to a router. I've a public IP, and configured mi Router vía IP Forwarding and open port 80 for the local IP of my host machine: 192.168.xx.xx.
2) Then in Virtual Box, go to Tools->Preferences -> Network ->Add New NAT Network. Then Edit this new NAT Netw. -> Name = "NatNetwork". Then Click in Forward Ports -> IPv 4 -> Rule 1; TCP; Host IP 192.168.xx.x (the local IP of the Host computer); Host Port = 80; Guest IP = 10.0.2.xx (it's the IP of my guest ubuntu server, what i'm seeing vía $ifconfig from console); Guest Port = 80. Then click in ACEPT.
3) In Virtual Machine (Ubuntu in my case) go to Configuration -> LAN Configuration: Conected to: RedNat; Name = "NatNetwork" (select the Nat Netw. what created in 2).
4) Next i RUN my guest machine (Ubuntu Server 16).
5) In the console i installed Apache2 follow the steps in https://www.digitalocean.com/community/tutorials/como-instalar-linux-apache-mysql-php-lamp-en-ubuntu-16-04-es
6) When apache2 is installed i can view my Apache Server via $ curl 10.0.2.xx (local ip of my guest machine) and the same Apache Server via Chrome in my Host Machine in the local IP 192.168.xx.xx and the same Apache Server in my public IP (because i've already configured my router for IP Forwarding).
In the next page you can view a graphic proccess: https://estudioecabrera.com.ar/apache-ubuntu/