Set macOS DNS Server IP Using Terminal

DNS is the service that translates fully qualified hostnames into an IP address. We can change the DNS setting from the command line of macOS by using the networksetup command or the scutil command.

While networksetup and scutil have many advanced and complex uses, setting DNS with networksetup is actually quite easier and faster than doing it with scutil.

To set the DNS manually we can use the networksetup command, followed by the -setdnsservers flag, followed by the network service and finally the DNS-IP, like this:

networksetup -setdnsservers <Network Service> <DNS-IP>

List Interfaces

DNS setting is interface specific, each interface has it's own DNS servers set to it. To list the interfaces (network services) use:

networksetup -listallnetworkservices
  root [~] $ networksetup -listallnetworkservices
An asterisk (*) denotes that a network service is disabled.
iPhone USB

Set The DNS

networksetup -setdnsservers Ethernet

networksetup -setdnsservers Wi-Fi

You can also set fallback DNS servers, like this:

networksetup -setdnsservers Ethernet

Clear Custom DNS Servers

If you are using DHCP then your router can take care of DNS for you, and you can clear the settings by actually omitting the IP numbers while executing the same flag, like this:

networksetup -setdnsservers Ethernet

If you configured your IP manually then you need to have at least one DNS server configured. Without it, the interface won't be able to resolve domain names.

{{ message }}

{{ 'Comments are closed.' | trans }}