How can I quickly change DNS server

To get the settings:

networksetup -getdnsservers Airport

To change them:

networksetup -setdnsservers Airport xx.xx.xx.xx

These settings are non-persistent, so you could clear your manual settings, let the public wi-fi DNS do its thing, then use the -setdnsservers to set it to what you want until next time.


Once you have setup different Network Loacations as per Adam Rice's solution, you can quickly switch between the locations using top menubar option "Apple > Location".

enter image description here


You can have multiple network configurations and switch between them on your Mac. Open the Network prefpane, and you'll see that there's a popup menu at the top (probably says "default" or something). Let's say you get this set up the way you like it for home use. Pull down that menu to Edit Location…, double-click on the name, and give it an obvious name like "Home."

Then create another location in that window (hit the + button) and name it Coffee Shop. Finish up in that window and select Coffee Shop from the menu to make it your current menu. Change the settings to be whatever you want.

To change the DNS settings you use in each of these cases, you'll need to click on the Advanced button at the bottom, then the DNS tab.

Once you've got these two locations set up, you can switch between them in the Network prefpane in the future; I think there are independent applications that make it easier to switch between them (or even do it automatically based on what networks they detect) but I've never played around with them.


Launchbar will allow you to select from your pre-defined locations - I have two that only differ by setting DNS.

enter image description here

So I have Control-Space as my hotkey so this sequence of keys to toggle OpenDNS instead of the DHCP supplied DNS:

^+Space, L, O, C, Return, , Return

enter image description here

The down arrow key will cycle between all your locations if you have more than two. As I put in my comments above - FastScripts lets you assign one shortcut key sequence to whatever script you like from the other answers - it runs in the context of the running app and is free if you need less than 10 shortcut keys defined in the app.