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
ltc target local.lattice.cf becomes
ltc target dev.lattice.
- Use Homebrew to install
# Update your homebrew installation $ brew up # Install dnsmasq $ brew install dnsmasq
- Use the commands provided by
brew info dnsmasqto configure and start the service.
As of dnsmasq v2.72,
brew info dnsmasqreturned:
$ 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
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
$ sudo mkdir /etc/resolver
- Create a file that defines the resolver for
$ sudo tee /etc/resolver/dev.lattice >/dev/null <<EOF nameserver 127.0.0.1 EOF
Starting Lattice cluster with alternate name
LATTICE_DOMAINenvironment variable during
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 220.127.116.11