DNSMasq Configuration on OSX

Many Lattice services run over HTTP. Via the Gorouter, they share the same IP address. They are distinguished based on which hostname they’ve been accessed by. That’s why many Lattice examples require the use of local.lattice.cf instead of the raw IP address. That way, the client correctly communicates the domain name to the service regardless of how many services share that IP address.

As an alternative, you can use dnsmasq. Dnsmasq is a useful tool to provide a private, local DNS server that can be configured to return the IP address of your Lattice installment. In this document, the examples use the dnsmasq package for OSX. If you are not on OSX, you can use the source distribution.

After following these instructions, wherever you see servicename.local.lattice.cf you can simply use servicename.dev.lattice. So, ltc target local.lattice.cf becomes ltc target dev.lattice.

Installation

  • Use Homebrew to install dnsmasq:
# Update your homebrew installation
$ brew up
# Install dnsmasq
$ brew install dnsmasq
  • Use the commands provided by brew info dnsmasq to configure and start the service.
    As of dnsmasq v2.72, brew info dnsmasq returned:
$ brew info dnsmasq
dnsmasq: stable 2.72 (bottled)
http://www.thekelleys.org.uk/dnsmasq/doc.html
/usr/local/Cellar/dnsmasq/2.72 (7 files, 496K) *
  Built from source
From: https://github.com/Homebrew/homebrew/blob/master/Library/Formula/dnsmasq.rb
...
==> Caveats
To configure dnsmasq, copy the example configuration to /usr/local/etc/dnsmasq.conf
and edit to taste.

  cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf

To have launchd start dnsmasq at startup:
    sudo cp -fv /usr/local/opt/dnsmasq/*.plist /Library/LaunchDaemons
    sudo chown root /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
Then to load dnsmasq now:
    sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist

More info: http://blog.philippklaus.de/2012/02/install-dnsmasq-locally-on-mac-os-x-via-homebrew/

Configuration

Set up dnsmasq to resolve dev.lattice

  • Using your favorite text editor, append the following line to /usr/local/etc/dnsmasq.conf. Make sure to replace <LATTICE_IP> with your Lattice target IP address.
address=/dev.lattice/<LATTICE_IP> # i.e., 192.168.11.11
  • Restart the dnsmasq service
$ sudo launchctl stop homebrew.mxcl.dnsmasq
$ sudo launchctl start homebrew.mxcl.dnsmasq

Configure your workstation to use the dnsmasq resolver for dev.lattice

  • Create /etc/resolver folder
$ sudo mkdir /etc/resolver
  • Create a file that defines the resolver for dev.lattice
$ sudo tee /etc/resolver/dev.lattice >/dev/null <<EOF
nameserver 127.0.0.1
EOF

Starting Lattice cluster with alternate name

  • Set LATTICE_DOMAIN environment variable during vagrant up:
LATTICE_DOMAIN=dev.lattice vagrant up --provider=<PROVIDER>

Validating your dnsmasq setup

Here’s how you can prove that you’re set up to redirect requests for the dev.lattice domain, as well as make sure that regular DNS resolution has not been affected.

$ host www.dev.lattice 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases: 

www.dev.lattice has address 192.168.11.11
$ host www.cloudfoundry.org 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases: 

www.cloudfoundry.org has address 140.211.169.8

Modular. Flexible. Powerful

Application Instances