Change DNS servers from the command line in Mac OS X

Changing DNS servers isn’t something most people need to do frequently. When you do need to change them up, though, it takes too many clicks in System Preferences. Use networksetup at the command line instead. For example, to change your DNS server to the OpenDNS servers, issue the following (if you’re using Ethernet):

sudo networksetup -setdnsservers Ethernet

To get a list of all the network services you could be using, run

networksetup -listallnetworkservices

If you make a lot of changes to your network throughout the day, it’s worth getting to know what networksetup can do. And don’t forget that any command you can run in a shell can be incorporated into an AppleScript or Automator workflow with do shell script.

Comments are closed here.