Ubuntu: i want to use VM like a Localhost Serve



Question:

I'm writing now from Ubuntu Desktop 17.10 and I installed VirtualBox 5.1 from Ubuntu repository, then created new VM with Ubuntu Server 16.4 to use it as web server.. so I have Ubuntu Server 16.4 with ssh and Apache2 IN VM.

From "VirtualBox - Preferences => Network" I added new Host-Only Networks, it's named "vboxnet0"

Screen shot

and from "VM Settings => Network" I Chose:

  • "Nat" as "Adapter 1" and checked to Cable Connected,

  • "Host-Only Adapter" as "Adapter 2" and selected "vboxnet0" with "Promiscuous Mode: Allow All".

modified etc/network/interfaces like this:

like that (screenshot)

ifconfig -a shows:

Screenshot

and I disabled firewall.

but when i try to connect from desktop to vm using SSH this message shows:

ssh: connect to host 192.168.56.101 port 22: No route to host  

and i can't access to web server from desktop "http://192.168.56.101/" gives me:

This site can’t be reached  

I want to use VM like a Localhost Server, what's my mistake or what am I missing ?


Solution:1

When you use the Host-Only network on VirtualBox (or VMware), you're basically isolating your virtual machines into a same network that is inaccessible from other networks (because a Host-Only network doesn't have a gateway). So, to be able to do a routing between networks, you'll need to use the NAT network. This type of network is separated from your real network but it can still be routed because it's on the routing table of your computer. Think of a NAT network as a Host-Only that can be routed from your own computer.

As you can see, the Host-Only network can't be reached directly from your host, but the NAT network VMs can be routed to your host. As you can see, the Host-Only network can't be reached directly from your host, but the NAT network VMs can be routed to your host.

Once you've put your VM on NAT, make sure you've put a gateway in /etc/network/interfaces. For example:

 auto enp0s8      iface enp0s8 inet static          address 192.168.56.101          netmask 255.255.255.0          gateway 192.168.56.1  

(Image source: https://www.eandbsoftware.org/networking-between-host-and-guest-vms-host-only-networking-with-virtualbox/)


Solution:2

im founded what i missing,

just i miss to check to [Cable Connected] for "Adapter 2".

now i can access to VM server.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »