Sunday, June 7, 2015

Update DNS Command Line Mac OS X With Networksetup

From this post you can learn how to use update DNS command line Mac OS X. Read all the information below.

There is very useful info for advanced Mac users that they can set DNS servers in OS X from the command line, and you don't have to use the System Preferences Network control panel. The command line method has many advantages for many use cases, especially for making temporary DNS changes, troubleshooting , and remote management with ssh.

To update DNS settings from the command line of OS X, you’ll be using the ‘networksetup’ command. The networksetup command has multiple complex and advanced uses, setting DNS is really easy process to do.

How to Update DNS Servers from the Command Line of OS X using networksetup

All Mac system software modern versions have this networksetup command. You’ll use the -setdnsservers flag, point it at the network service, and then include the DNS IP, it will look like as the following:

  • networksetup -setdnsservers (Network Service) (DNS IP)

Let's look at example. To set a Mac with WiFi to Google DNS of the syntax would look like as you can see below:

  • networksetup -setdnsservers Wi-Fi

If you want you can set multiple DNS servers, which will enable fallback in the event the first or second server is unreachable. For instance, this would set OpenDNS for the first two DNS servers, and Google DNS as the third fallback:

  • networksetup -setdnsservers Wi-Fi

If you want to change yours DNS servers to find the fastest DNS server you can do it with apps like NameBench. This app does benchmark testing with the aim to define which DNS will be fastest for your particular location.

Checking DNS Settings with networksetup

By using the -getdnsservers flag with networksetup, you can also check existing DNS settings. It will report back whatever the current DNS settings are, if any:

  • networksetup -getdnsservers Wi-Fi

How to Clear All DNS Servers with networksetup

This step will simply erase any existing custom DNS server settings. It can be useful if you’re wanting to fall back to DHCP provided DNS from a router, modem, or similar situation:

  • networksetup -setdnsservers Wi-Fi

As with setting DNS, removing DNS may require you to flush DNS caches after making adjustments. It depends on what you’re trying to do.

To update DNS command line on Mac OS X is really useful option. DNS changing and customization can be used for wide variety of purposes. For example, perform detailed lookups during propagation, speeding up lookups, finding more reliable servers or changing to alternate providers.


Post a Comment