Live data from Hacker News

Using Dnsmasq for local development on OS X

passingcuriosity.com

11–20 of 39 posts

Re: Using Dnsmasq for local development on OS X

#11
post #10

Well, that’s one part of the equation. Are there any guides on what to do after; setting up virtual hosts?

I use nginx, which is a great alternative to Apache.

I've never tried it on OSX, but this guide seems to cover dnsmasq + nginx virtualhosts :-)

http://zaiste.net/2013/03/serving_apps_locally_with_nginx_an...

Re: Using Dnsmasq for local development on OS X

#12
post #3

For Ruby apps, there's also http://pow.cx/

Instead of symlinking ~/.pow/example to (say) ~/Sites/example, you can `echo 3000 > ~/.pow/example` and example.dev will now point to port 3000.

This lets you boot up your Rails app normally, or via Procfiles, instead of booting up through all the pow.cx magic that can be a real pain to debug.

Re: Using Dnsmasq for local development on OS X

#13
Another neat "trick" with dnsmasq is to redirect all the dns request for your domain to your dns provider when you're working with dns records (config needed: server=/example.com/176.124.112.100). Never wait for dns propagation anymore! Beat switching your system's dns to your provider because those could be slow for you, or could not answer domains that aren't in their database.

Re: Using Dnsmasq for local development on OS X

#14

What are the advantages of using an approach like this vs. editing /etc/hosts directly?

Two immediate I can think of:

1) You don't have to add new .dev hosts to /etc/hosts repeatedly. Once you're setup, all .dev is local

2) /etc/hosts doesn't support wildcards, so dnsmasq is great with apps that have many or randomized subdomains.

Re: Using Dnsmasq for local development on OS X

#16

Maybe I'm missing something, but… …how is this different from editing /etc/hosts?

/etc/hosts offers no wildcard support. You can teach dnsmasq to route everything under the .dev TLD to localhost, so you can effectively create hostnames (including subdomains) by just using them.

Re: Using Dnsmasq for local development on OS X

#17
post #5

Great article for highlighting the dnsmasq on OSX idea. I wasn't aware that you could run this there. On the goal of having unlimited easy to configure real domains that point to locahost, another service of interst is localtest.me [1]. This offers *.localtest.me -> 127.0.0.1 [1]: http://readme.localtest.me/

This is pretty useful! Maybe a noob question but how does this work offline / slow internet connections? I'm coding on the train pretty frequently and I hate waiting for urls to resolve... I'm guessing it's caching this DNS entry? (why would I otherwise have to run dscacheutil -flushcache...)

Doesn't work offline, sorry.

Re: Using Dnsmasq for local development on OS X

#18
post #2

Doesn't do the exact same (you'd have to add a new entry everytime, rather than point *.dev to localhost) but https://addons.mozilla.org/en-US/firefox/addon/hostadmin/ is easier to set up. It'll flush the dns cache everytime its changed.

No, you don't have to add a new entry every time, you just set it up and now absolutely.anything.dev points to localhost. When editing /etc/hosts you have to add a line for every hostname.

Re: Using Dnsmasq for local development on OS X

#19
I've been experimenting with this lately. I have been using dnsmasq to server up domains in my /etc/hosts file to local virtual machines for testing on different platforms without having to mess around with the hosts file in each virtual machine.

I am about to loop back around to a mobile project and I am hoping I can use it to tests my mobile app interactions with my local development box more easily than I have been able to in the past.

Re: Using Dnsmasq for local development on OS X

#20
post #10

Well, that’s one part of the equation. Are there any guides on what to do after; setting up virtual hosts?

I use something like this with apache's mod_vhost_alias feature:

http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html

I just create a new directory, and with the wildcard DNS, I have a new dev site.

Post reply on HN