Virtualbox Localhost Mac



Setup the virtualbox to use 2 adapters: The first adapter is set to NAT (that will give you the internet connection). The second adapter is set to host only. Start the virtual machine and assign a static IP for the second adapter in Ubuntu (for instance 192.168.56.56). On Mac OS (host): Shutdown your VM and do: VirtualBox Settings Network Add (you will get vboxnet0) On a terminal ifconfig will show you new interface vboxnet0. VM's Settings System check 'Enable I/O APIC.' VM's Settings Network Adapter 2 host-only vboxnet0. On Ubuntu (guest): Install OpenSSH Server.

So you’ve set up your virtual machine, but you would like to communicate withit over the network as if it were another machine, with its own IP address. Youcan do so by setting up a host-only network!

You may want to do so for a number of reasons:

  • You prefer to SSH into your machine as if it were another machine on thenetwork

  • You would like stress test a web server running on one virtual machine fromanother

  • You would like your host machine to be visible from your guest machine,for using sftp or scp

  • You’re trying to import Jae’s reference VM, which depends on there being ahost-only network

Creating a Host-Only Network

If this is your first time setting up a host-only network, you’ll need tocomplete this step. Afterwards, you can just add more VMs to the same virtualnetwork without needing to redo this.

First, open up your VirtualBox Manager GUI. Click the “Tools” button, then from thedropdown menu select “Network”.

In the Host Network Manager menu, you should see that a virtual, host-onlynetwork has been created for you, named “vboxnet0”. If not, click the “Create”button on the top left corner.

Make sure the “DHCP Server” box has been checked as “Enabled”.

Select “Properties” to check your Adapter and DHCP settings. By default, youradapter settings should have “Configure Adapter Manually” enabled, the IPv4 Address field should be 192.168.56.1, and the IPv4 Network Mask should be 255.255.255.0.(If you have a different IP address it is likely because the 192.168.56.1/24 rangeis already taken by another network interface on your host machine, this is okay).

Note the IPv4 address on the Adapter menu. This is the IP of your hostmachine on your virtual network. In particular, note the first 3 fields ofthe IP address: this is the subnet mask, and will help you determine yourVM’s IP address later on.

Adding Your VM to the Host-Only Network

If you’re not using the reference VM, you’ll need to configure it to be placedon our host-only network. You’ll need to do this for every new VM you wantadded to your host-only network.

Open up your VirtualBox Manager again. Make sure yourVM is off. Select your VM, go to “Settings”, and go to the “Network” tab.

We’re going to create a new network adapter. Go to the next available adapter(if you haven’t set up any other adapters, this should be “Adapter 2”), andselect “Enable Network Adapter”. In the “Attached To:” dropdown menu, select“Host-only Adapter”, and make sure that “vboxnet0” is selected.

Hit “OK” to save your settings. If your VM is currently running, you should rebootit to get a new host-only IP from the DHCP server.

Finding Your VM’s IP Address

Now that your VM is on the virtual network, we need to find out its IP address.This may vary, depending on how many VMs you have on your network, and yourDHCP settings.

Virtualbox

On your VM, run the following command:

That will list a series of IP addresses, one of which should start with the same3 digits as your host-only network’s IP range, by default 192.

This is your VMs IP address. For example:

This indicates that the VM has an IP address of 192.168.56.3. The last value,in this example enp0s8 is the network interface for this IP address.

Now you’ll be able to use that IP address from your host machine, or any otherVM on the same virtual network, for things like SSH access and serverload-testing.

Virtualbox Localhost Mac Free

Troubleshooting Common Issues

My VM does not have an IP address for the host-only network interface

Depending on the operating system of the VM, the new network interface may not be automatically enabled. To fix this, we should first find the name of the host-only network interface in your VM using

This lists all the interfaces and corresponding IP addresses. Find the interfacethat does not have an IP address and note its name (by default this should be enp0s8).

Now edit the network configuration file /etc/network/interfaces and add the host-only interface to enable it. Open the file as sudo, and append the following lines to the end (change enp0s8 if your interface name is different):

Reboot your VM and try finding your IP address again.

My VM has an IP address for the host-only network, but I cannot connect to it

If your IP address starts with 169, this indicates your VM was unable to get an IP from the DHCP server and is trying to assign one to itself. This can usuallybe resolved by rebooting your VM, and if that fails try also rebooting your host machine.

SSHing into your VM via the Host-Only Network

If you have sshd setup on your VM, you should be able to SSH into your VM atthat IP address. For example, with the above IP address, if your username isdebbie, you would SSH into my VM with the following command:

If you’ve followed the SSH guide, you’ll notice that we no longerneed to pass a -p flag; this is because instead of forwarding the port atthe localhost loopback interface (with IP 127.0.0.1), we’re just treatingthe machine like it’s any other machine on a network, and using the defaultport 22 to SSH in.

Virtualbox Localhost Host Machine

The corresponding ~/.ssh/config file for this would be:

Of course, replace your Hostname with your VM’s IP and User with yourusername. For more details about this setup procedure, including SSH keygeneration and management, see the VirtualBox SSH guide.