Virtualbox Localhost Mac



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!

I'm always working on a Mac machine, but sometimes I need to debug an issue that only affects windows machines and more specifically IE. For that, I usually use VirtualBox with a free VM from Microsoft for debugging. I never remember what to do to access a server running on my Mac from my Windows VM. So I'm writing this, for me. And I guess for. Common Third-Party RDP Viewers. Since VRDP is backwards-compatible to RDP, you can use any.

Unfortunately, this makes VirtualBox pretty useless for me. Mac OS X absolutely NEEDS the adapter exposed to System Preferences in order to use the VM as a gateway. You can mess with the routing table all you want, but the system will erase your changes whenever another device becomes active. Setup a Local Only SMTP Email Server (Linux, Unix, Mac) 1 - Point localhost.com to your machine. Most of programs will not accept an email using just @localhost as domain. So, edit /etc/hosts file to make the domain localhost.com point to your machine, including this content to the file: 127.0.0.1 localhost.com. 2 - Install Postfix.

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.

Parallels access localhost on mac

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.

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.

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

Mac

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.

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.

Heads Up! This post is now very outdated. There’s a MUCH easier way to access localhost in VirtualBox.

Last week I explained how to convert the IE6 – IE8 VirtualPC disk images to VirtualBox on the Mac. This week I noticed something critically wrong, I can’t access localhost or any LAN IP address from inside VirtualBox. This is a huge problem if you want to do local testing in IE.

The problem is that Mac support is still rather early with VirtualBox and they only provide a NAT networking option. I wont explain what NAT is because I don’t completely understand it myself. If you’re on Linux or Windows you can simply use the bridged network and it’ll work fine.

As with any problem, there is a solution! You could go buy VMWare Fusion, which should support this out of the box, but what’s the fun and challenge in that? The fun and free solution is to use a service called DynDNS.

What is DynDNS

If you’re like most people your ISP gives you a dynamic IP, which means that your home network doesn’t always have the same IP address and every so often your ISP will assign you a different one. DynDNS will give you a free domain name that always points to your ever changing home network IP address.

This means that when you’re done you’ll load a URL like “http://<you>.dyndns.org/” instead of “localhost” inside VirtualBox. This also assumes that you have some sort of web server running on your computer to serve up the pages.

Localhost

Step 1 – Web Server

Setup a simple web server like Apache or the free version of LightSpeed (free version is at the bottom of the download page).

Make sure the server is installed and running properly before proceeding.

Step 2 – DynDNS Account

Go to DynDNS, register an account and create a new host. The site has good help sections to assist you through any issues or questions you run into. (see the DynDNS How-To section)

Mac software for cracking wifi. After creating the new host, download, install and run the DNS update program. This will update the service with your new IP address every time it changes.

Step 3 – Router

If your network uses a router, you might need to update it’s settings to let the requests through to your computer inside the network. At this point it is important to realize that your router has the “main” IP, which is provided by your ISP, and each computer inside your network will get their own “internal” IP address, provided by the router itself.

Reminders for mac. First test the new DynDNS URL you created. When you load the URL in your browser does it show pages from your local web server or does the browser sit there and mock you as it endlessly spins the “loading” animation?

If your web server didn’t load anything, you might need to alter your firewall settings and/or setup port forwarding in your router. Start by checking your router manual for information on how to login and change settings on it. On my SMC wireless router after logging in I found the settings I needed under Advanced Setup > NAT > Virtual Server. There I entered the last number from my “internal” IP address (IP on my computer) and the port that should direct to that computer. So if my internal IP is 192.160.2.53 and my web server is setup to respond to port 80, I enter “53” and “80” into the fields.

Step 4 – Static Internal IP

If you had to setup port forwarding in the last step, you should also create a static internal IP on your computer. Otherwise next time you restart your computer it’s IP might be different and your URL wont work.

This step is surprisingly simple:

  1. Open your network preferences
  2. Go to the network you use (in my case “Airport”)
  3. Click Advanced (or similar button — I’m using Mac Leopard)
  4. Go to the “TCP/IP” area.
  5. Change the dropdown menu from “Using DHCP” to “Using DHCP with manual address”
  6. Enter the internal IP address you added to the port forwarding setting in your router.
  7. Done

Troubleshooting

Virtualbox In Browser

If you have any problems with the setup, check out the troubleshooting page at DynDns.

Virtualbox Localhost Mac Free

Done

Virtualbox Localhost Host Machine

Now you should be able to access your local computer from inside VirtualBox with your new URL.