How would I prepend 127.0.0.1 as a nameserver all the time I do web development and I would like to have dnsmasq running and handing my local dns requests. However I work in a lot of different networking scenarios and I need to DHCP updating my networking information multiple times a day.

I already have dnsmasq running and I can have my laptop always use it by setting the DNS name server.

It's not too bad, this way, I can use the location management (in the network preference pane) and just switch location between 'Automatic' and 'Automatic (dnsmasq)' when I need to, however what I really want it something linux has.

In linux I can configure my dhcp client to prepend a name server to whatever I get from dhcp. On ubuntu I do this by editing /etc/dhcp3/dhclient.conf and setting.

prepend domain-name-servers 127.0.0.1;


Is there an equivalent in OS X (10.8 Mountian Lion). Thanks
As you already know, OS X will overwrite any changes you make to /etc/resolv.conf so you can't really specify your own nameserver in there. Luckily, there is a way to add your own resolver entries in a way that will persist whatever network connection you use whilst still using DHCP assigned name servers for most normal lookups.

Create the directory /etc/resolver and create a text file within it that simply has a standard name server directive like nameserver 127.0.0.1. Make sure this text file is named the same as the domain or TLD you wish to use dnsmasq for. In my case, all my development sites end with the .dev TLD so my config file is named /etc/resolver/dev.

And that's it! From now on, when ever you connect to a network using DHCP, your name servers will be automatically assigned and used as normal but any requests for your specified TLD (*.dev in my example) will be routed to dnsmasq.