On my Mac, I am trying to set my DNS servers so that they are and at my house, while at school they are the router default (they block google's public DNS)

How can I set up my DNS servers to be configured differently for each wireless network?

note: router configuration at my home is not an option.

I am running:
macOS 10.12.3 16D32 Sierra
MacBook Pro 13" w/ 4 Thunderbolt 3

  • This is not directly an answer to your question, but since you mention specifically that you want this because it's blocking Google's, I imagine it might be useful to mention some alternatives. Cloudflare runs a super-fast DNS service at and and OpenDNS offers theirs at and Further reading: and opendns.com
    – Nate
    Jun 7, 2019 at 16:38

3 Answers 3


How can I set up my DNS servers to be configured differently for each wireless network?

Set and Change in Network Preferences

You can set your own custom DNS settings on a location basis by defining a "Location" in Network Preferences

enter image description here

You would then enter your preferred DNS settings (click "Advanced") under the DNS tab:

enter image description here

After you create set the configuration to your liking, you can call it up by returning to this preferences page and just selecting the location of your choice.


You can switch from the directly from Apple Menu (). Just choose "Location" and select the location you want

enter image description here

Switch using command Line

For a quicker way, you can switch using the command networksetup. So, to switch to a profile you have already created called "School" your command would be:

networksetup -switchlocation School

Bonus footage...

You could create small bash scripts with the command pre populated and placed (or linked) on your desktop.

#Script to set the location to School

networksetup -switchlocation School

Name it something meaningful like school.sh or school.command (or even just school). Make it executable by issuing the command chmod +x /path/to/school.command (or whatever you called it). Make another for Home, Work, In-Laws, or wherever. When you double click on it, it will change the network location and your preset settings.


If your organization (like your school) blocks outside DNS servers and traffic limiting it to the DNS servers they specify, you won't be able to override them.

  • Great, thanks! I actually was using this because I discovered Google DNS is blocked by the school, and I need to use Google DNS at home without router config. Works like a charm! Mar 22, 2017 at 23:20
  • On MacOS mojave, the sub command should be -switchtolocation; $ networksetup | grep switch Usage: networksetup -switchtolocation <location name>
    – Tai Le
    Dec 27, 2018 at 4:11
  • Perfect answer. Thank you. Jul 16, 2023 at 6:36

I have posted on my Github a script as a solution to this problem. If you are interested you can use it. https://github.com/andreabac3/CDDN-Change-DNS-Dynamically-with-your-Network

  • 2
    Instead of posting a link to a script therefore sending people offsite and without an explanation how the script solves the problem please add the essential parts of the script directly into your answer and explain how it works. You can still leave the link in for people looking for the full solution.
    – nohillside
    Jun 2, 2019 at 11:19
  • @nohillside Sorry, you have right, I made an assumption the explanation of how it works is in the README attached with the script. I will modify my answer. Thank you for suggestions.
    – Andrea B
    Jun 10, 2019 at 8:28

You can also install dnscrypt so that the curious people that run the school don't know to which sites you are navigating.....

  • 1
    This isn't really an answer, it's more of a comment.
    – fsb
    Feb 23, 2019 at 15:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .