How can I access Apache (on VirtualBox guest) from host?
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 namedwlan0
(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.101
is 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\hosts
as administrator and add a line:192.168.56.101 guestserver.com
If you've a Ubuntu host system, edit
/etc/hosts
usingsudo nano /etc/hosts
- Profit!
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.