Create alias to local hostname

3

I have the following scenario: A host machine (OS X) and a guest machine (Ubuntu). The guest is running through Virtual Box, and the network configurations is set to "Bridged adapter". Both machines have a hostname, host.local for the host, and guest.local for the guest. They can communicate with each other using the hostnames, e.g. ping host.local.

I'd like to use the guest machine as a development server for websites. The sites will be located on the host, and are accessible to the guest using a shared folder. I've configured Apache to use a virtual document root, which will make the sites available on site.guest.local. However, this would require me to setup site.guest.local, site2.guest.local etc in my hosts file, pointing to the IP of the guest.

I don't want to depend on the IP address of the guest, since the computer might be connected to different networks, with a different IP address from time to time.

I've been fiddling around with a local DNS server, specifically DNSMasq, trying to create CNAME records etc, but I can't figure out the proper way to achieve this.

In short terms, I want to create a local alias that points to guest.local.

Olof Johansson

Posted 2013-01-03T10:18:34.913

Reputation: 131

I've managed to solve my problem with a workaround. I've setup my guest to use two network interfaces, one bridged, and one host only. The host only will have e static IP and will only be able to communicate with the host, and the bridged will have access to the outside world. Using the static IP, I'm able to use DNSMasq to create an address that points to the guest. – Olof Johansson – 2013-01-03T12:19:01.720

If you would like, you can answer your own question without any problem. Cheers! – Karolinger – 2013-01-08T01:41:42.887

Yeah I know, but I don't consider my solution as the answer to my original question, as it's a simple workaround :) – Olof Johansson – 2013-01-08T10:06:27.810

Answers

0

I use vagrant to manage VirtualBox VM's. They're all setup with host-only networking, a static IP, and an entry in /etc/hosts. Make sure VirtualBox's host-only network is set to NAT (VirtualBox / Preferences / Network).

The guest is be able to access the outside (assuming it's networking is configured correctly), and the virtual interface is translated by NAT so you can choose your own IP.

This may not help, but here's a line from one of my Vagrantfile's:

config.vm.network :hostonly, "10.11.12.13", :auto_config => true

If the IP of a guest ever collides with another device on the network, update the IP address of the host-only adapter (VirtualBox / Preferences / Network) and the static IP in the VM.

Johntron

Posted 2013-01-03T10:18:34.913

Reputation: 564