How to Set DNS Servers from the Command Line of OS X with networksetup
The networksetup command is available in all vaguely modern versions of Mac system software. You’ll use the -setdnsservers flag, point it at the network service, and then include the DNS IP, this may look like the following:
networksetup -setdnsservers (Network Service) (DNS IP)
For example, to set a Mac with wi-fi to Google DNS of 8.8.8.8 the syntax would be:
networksetup -setdnsservers Wi-Fi 8.8.8.8
You can set multiple DNS servers if desired, which will enable fallback in the event the first or second server is unreachable. For example, this would set OpenDNS for the first two DNS servers, and Google DNS as the third fallback:
networksetup -setdnsservers Wi-Fi 208.67.222.222 208.67.220.220 8.8.8.8
...[► Source]
Post a Comment