Live data from Hacker News

Using Dnsmasq for local development on OS X

passingcuriosity.com

31–39 of 39 posts

Re: Using Dnsmasq for local development on OS X

#32
One problem I've been running into: I have a virtual machine (linux running in vmware fusion on osx). I have dev.site.com in /etc/hosts. The vm is set to use a private network on the vm (as I don't want the ip address to change when I switch networks). How can I setup my phone to load dev.site.com and have it work while keeping the private network setup?

Re: Using Dnsmasq for local development on OS X

#33

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

I think this is really useful when you combine it with vhosts on apache/nginx. On my linux machine I run something similar that allows me to serve static assets, run a local dev server (runserver/flask/unicorn, etc) and have a .dev domain to test with.

You can then combine this with xip.io and be able to share your dev site with others.

Re: Using Dnsmasq for local development on OS X

#34

One problem I've been running into: I have a virtual machine (linux running in vmware fusion on osx). I have dev.site.com in /etc/hosts. The vm is set to use a private network on the vm (as I don't want the ip address to change when I switch networks). How can I setup my phone to load dev.site.com and have it work while keeping the private network setup?

run an http proxy on your host os and have the phone configured to use that?

Re: Using Dnsmasq for local development on OS X

#35

One problem I've been running into: I have a virtual machine (linux running in vmware fusion on osx). I have dev.site.com in /etc/hosts. The vm is set to use a private network on the vm (as I don't want the ip address to change when I switch networks). How can I setup my phone to load dev.site.com and have it work while keeping the private network setup?

run an http proxy on your host os and have the phone configured to use that?

how does the iphone know to route requests for the private network to the host os?

Re: Using Dnsmasq for local development on OS X

#36
post #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.

yeah thats what i meant and said.

by using something to edit the hosts file you'd have to edit it every time (can't do wildcards on hosts file, so it needs editing every time)

Re: Using Dnsmasq for local development on OS X

#37

Earlier quoted context omitted.

run an http proxy on your host os and have the phone configured to use that?

how does the iphone know to route requests for the private network to the host os?

HTTP Proxy in iOS Settings offers three options:

Off: proxies no HTTP requests.

Manual: proxies all HTTP requests through a proxy server at the specified host and port.

Auto: uses JavaScript code hosted on a Web server at a specified (unproxied) URL to determine how HTTP requests get proxied. Assuming your proxy server is at host.example.com:8080, specifying a URL pointing to a file containing

    function FindProxyForURL(url, host) {
        if (shExpMatch(host, "*.vm.example.com")) {
            return "PROXY host.example.com:8080";
        } else {
            return "DIRECT";
        }
    }
should proxy only HTTP requests whose URLs point to hosts in the .vm.example.com subdomain through your proxy server.

Disclaimer: I haven't tested any of this, and everything I know about proxy auto-configuration comes from skimming the Wikipedia page[1] just now.

[1] http://en.wikipedia.org/wiki/Proxy_auto-config

Re: Using Dnsmasq for local development on OS X

#38
I do something similar with Ubuntu 12.04/14.04 which uses Dnsmasq via the NetworkManager service. These steps help make Dnsmasq a little more useful - reading /etc/hosts and allowing it to listen on your hosts IP address for use in guest VM's

https://gist.github.com/magnetikonline/6236150

Re: Using Dnsmasq for local development on OS X

#39
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...)

It has a 1 hour TTL, so assuming you start working before you go offline you might be ok. Fair point though. It could be worth upping that to a day?
Post reply on HN