How can I access a server running in VirtualBox from the host?


Kirkland

I am running a web application on a VM.

I can view the application localhost:8888through the browser inside the VM .

I can't see the app from the host using the same URL. That's the goal.

I tried it and VBoxManage modifyvm "VM name" --natdnshostresolver1 onit didn't make a difference.

My configuration is:

  • Host: Windows 7
  • Guest: Ubuntu 16.04.1 LTS
  • VirtualBox: 5.1.4r110228

Guest configuration

(guest) ifconfigwhen on NAT

kirkland@GC:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:d0:fc:0e  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::4c67:70b5:c37b:8fa8/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:7431 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3587 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:7444830 (7.4 MB)  TX bytes:731870 (731.8 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:65536  Metric:1
          RX packets:1566 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1566 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:655936 (655.9 KB)  TX bytes:655936 (655.9 KB)

(guest) /etc/hosts

127.0.0.1   localhost
127.0.1.1   GC

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
Daniel Liston

The localhost:8888URL is just a valid URL in your VM. Outside of that VM you will have to use ip.ad.dr.ess:8888or hostname:8888. In the latter case, a dependency on hostname resolution on the network is ip.ad.dr.essintroduced .

By default, when creating a VM in VirtualBox, Network Adapter 1 is set to NAT. This will give the VM an IP address 10.0.2.15/24and default route 10.0.2.2(should be your host). Long story short, Windows won't route to the address that gives it NAT without jumping through more loops first.

Shutting down the VM, and changing the VM Network Adapter 1 setting to "Bridged", will allow your host (and any host on your local network) to communicate with that VM without adding any special routing or bypassing hoops.

Restart the virtual machine. Verify your connection to localhost:8888. Also verify your connection hostname:8888(assuming the hostname is notadded to the loopback/localhost address in the /etc/hosts file) and ip-address:8888. EDIT: According to the posted /etc/hosts details, you areare binding the VM to the webapp and therefore the webapp to the loopback network. This configuration simply cannot be used outside the VM.

If your web server and applications don't depend on the IP of the first configuration/installation IP, and you have a DHCP server on your LAN, the only other information you need to connect to the VM is the IP address. Assigned to it via DHCP.

Find the IP address of the VM: From the Ubuntu desktop (ctrl-alt-T) open a terminal/console window, we use the hostname, ifconfig and grep /etc/hostscommands to put the pieces together and find your address. In the terminal that opens, type hostnameand press Enter. It might be gc. In the same terminal, typing ifconfig eth0 | awk '/Bcast/{print $2}'will display the address. You should have a line in /etc/hosts with the address followed by the hostname. grep [hostname] /etc/hostsor grep [address] /etc/hostsshould find the line you need. If you provide a hostname in addition to the current address, you will need to modify the /etc/hosts file to add the correct information.

Hosts on the LAN should now be able to connect to the VM's IP on port 8888. For these hosts/clients, access to the web application hostname:8888will depend on the client hosts file, the local DNS or even the mDNS service that may be available on the DHCP server. .

Related


How can I access a server running in VirtualBox from the host?

Kirkland I am running a web application on a VM. I can view the application localhost:8888through the browser inside the VM . I can't see the app from the host using the same URL. That's the goal. I tried it and VBoxManage modifyvm "VM name" --natdnshostresolv

How to access apache server running in virtualbox from host?

techiek7 I want to access Apache web server running in centos virtualbox. After connecting the laptop to the office LAN, I can access this web server using bridged network mode. But what I want to do is to access when no network is connected. Is virtual interf

How to access apache server running in virtualbox from host?

techiek7 I want to access Apache web server running in centos virtualbox. After connecting the laptop to the office LAN, I can access this web server using bridged network mode. But what I want to do is to access when no network is connected. Is virtual interf

How to access Ubuntu server running in VirtualBox from outside

jaw I have installed Ubuntu Server 12.04 LTS on my laptop via VirtualBox. I have installed LAMP, OpenSSH, mail server. When logging in, I ran ifconfig. The inet address it gives me is 192.168.0.3. So, should this be the address where I should be able to access

How to access Ubuntu server running in VirtualBox from outside

jaw I have installed Ubuntu Server 12.04 LTS on my laptop via VirtualBox. I have installed LAMP, OpenSSH, mail server. When logging in, I ran ifconfig. The inet address it gives me is 192.168.0.3. So, should this be the address where I should be able to access

How to access Ubuntu server running in VirtualBox from outside

jaw I have installed Ubuntu Server 12.04 LTS on my laptop via VirtualBox. I have installed LAMP, OpenSSH, mail server. When logging in, I ran ifconfig. The inet address it gives me is 192.168.0.3. So, should this be the address where I should be able to access

How to access Virtualbox internal IP from host?

TimD1 I've been trying to learn more about security by following http://www.pentesterlab.com/bootcamp/week2/ , but I'm struggling to access the VM's internal IP localhost from the host . I can access the host's internal IP from the VM (using 10.0.2.2) and the

How to access Apache from host (on VirtualBox guest)?

urok93 I have Apache installed on an Ubuntu VM. When I go into the client machine and load Firefox, I can see that Apache is running fine when I browse to localhost. I want to access the same page through the host. I tried using the guest's IP address, but not

How to access Virtualbox internal IP from host?

TimD1 I've been trying to learn more about security by following http://www.pentesterlab.com/bootcamp/week2/ , but I'm struggling to access the VM's internal IP localhost from the host . I can access the host's internal IP from the VM (using 10.0.2.2) and the

How to access Apache from host (on VirtualBox guest)?

urok93 I have Apache installed on an Ubuntu VM. When I go into the client machine and load Firefox, I can see that Apache is running fine when I browse to localhost. I want to access the same page through the host. I tried using the guest's IP address, but not

Unable to access server running in container from host

Alexander Mills I have a simple Dockerfile FROM golang:latest RUN mkdir -p /app WORKDIR /app COPY . . ENV GOPATH /app RUN go install huru EXPOSE 3000 ENTRYPOINT /app/bin/huru I build like this: docker build -t huru . and run like this: docker run -it -p 3000

Access a server running on docker from the host

Dangira I have a rest api server running on a docker container. The server runs on port 8000 of the docker container, and port 8081 of the host is bound to port 8000 of the container. By connecting to the container and doing curl localhost:8000 I can see that

Unable to access server running in container from host

Alexander Mills I have a simple Dockerfile FROM golang:latest RUN mkdir -p /app WORKDIR /app COPY . . ENV GOPATH /app RUN go install huru EXPOSE 3000 ENTRYPOINT /app/bin/huru I build like this: docker build -t huru . and run like this: docker run -it -p 3000

How to access VirtualBox host-only network from outside the host?

Brian I'm using Vagrant to deploy a large virtual network environment to test some applications and network activity. I'm using host-only networking, so all IP addresses can be defined in the Vagrantfile, but one of the applications I need for testing is an ex

How to access VirtualBox host-only network from outside the host?

Brian I'm using Vagrant to deploy a large virtual network environment to test some applications and network activity. I'm using host-only networking, so all IP addresses can be defined in the Vagrantfile, but one of the applications I need for testing is an ex