Please note, these instructions are for OS X Lion.
First, you need to get the IP address of your machine on your local network. In OS X, the easiest place to find this is in System Preferences > Network
. If you’re using DHCP on your local network, you will want to make sure your computer requests the same IP address when it renews it’s IP address lease. I recommend configuring the DCHP Reservation settings on your router to accomplish this. Otherwise, you can specify a manual address in your network settings:
- Go to System Preferences > Network
- Click Advanced…
- Click the TCP/IP tab
- Change the Configure IPv4 dropdown to Using DHCP with manual address
- Enter your current IP address in the textbox that appears
- Click Ok then Apply
For the purpose of these instructions, let’s assume your local network IP address is 192.168.x.x.
Install dnsmasq
- Go to Downloads for Apple Developers and download the most recent release of Command Line Tools for Xcode and install it.
- Go to the MacPorts install page, then download and install the Mac OS X Package (.pkg) Installer for Lion.
- In Terminal, run
sudo port -v selfupdate
- Install dnsmasq
sudo port install dnsmasq
Configure dnsmasq
- Add the following line to /opt/local/etc/dnsmasq.conf. (Don’t forget to replace the IP address.)
address=/.dev/192.168.x.x
This will point all hostnames ending with .dev at 192.168.x.x. If you’d prefer a hostname extension other than .dev, you can always edit this later and add additional lines. sudo cp /etc/resolv.conf /opt/local/etc/
Start dnsmasq automatically on boot
sudo mkdir -p /System/Library/StartupItems/DNSMASQ
- Create
/System/Library/StartupItems/DNSMASQ/DNSMASQ
and fill it with the following:
1 |
|
- Create
/System/Library/StartupItems/DNSMASQ/Startup\ Parameters.plist
and fill it with the following:
1 | { |
- Add the following line to /etc/hostconfig
DNSMASQ=-YES-
- Make it executable
sudo chmod +x /System/Library/StartupItems/DNSMASQ/DNSMASQ
Start dnsmasq for the first time
- Open a separate Terminal window and run
tail -f /var/log/system.log
sudo /System/Library/StartupItems/DNSMASQ/DNSMASQ
You should see dnsmasq starting up in the system.log. Make sure there are no errors.
Add your IP to your DNS settings
- Go to System Preferences > Network
- Click Advanced…
- Click the DNS tab
- Add 192.168.x.x (your IP address) to the list and drag it to the top of the list if you can
- Click Ok then Apply
** MOST MOST MOST IMPORTANT **
You will need to do this on any device you would like to access your .dev hostnames, including VMWare instances and iOS devices.
Test
Clear Cache:
dscacheutil -flushcache
Dig a domain:
dig google.com
You should see something like this near the bottom:;; SERVER: 192.168.x.x#53(192.168.x.x)
ping somewhere.dev
You should see something like this:
1 | PING somewhere.dev (192.168.x.x): 56 data bytes |