1. Home
  2. Mobile Devices
  3. How to Change DNS on a Mac Using Terminal

How to Change DNS on a Mac Using Terminal

Changing your DNS settings on a Mac can enhance your browsing experience and provide additional security. While you can change DNS settings through the system preferences, using the Terminal offers more control and the ability to lock settings to prevent changes. This guide will show you how to change your DNS settings on a Mac via the Terminal.

Why Use Terminal to Change DNS?

Changing DNS via Terminal is beneficial for advanced users, IT administrators, and organizations managing multiple devices. It allows you to enforce DNS changes more securely.

Macs come with the networksetup command line (CLI) utilities. This utility allows a user to configure the network on a MacOS. That’s all you will use to change your devices DNS nameservers and prevent users from making changes.

Steps to Change DNS on a Mac Using Terminal

Step 1 – Identify Your Interfaces

First, identify the network interfaces on your Mac. Open the Terminal application and run the following command:

$ sudo networksetup -listallnetworkservices

You will see a list of network services. An asterisk (*) indicates a disabled service. Typically, you’ll be using the “Wi-Fi” interface.

Example output:

An asterisk (*) denotes that a network service is disabled.
USB ACM
Thunderbolt Ethernet Slot 1
USB 10/100/1000 LAN
USB 10/100/1000 LAN 2
Wi-Fi
Bluetooth PAN
Thunderbolt Bridge

Step 2 – Update Interface with New DNS

o update the DNS settings, use the networksetup utility with the setdnsservers option. Replace (Network Service) with your interface (e.g., “Wi-Fi”) and (DNS IP) with your desired DNS server IPs.

For example, to set CleanBrowsing Family Filter DNS on the Wi-Fi interface:

sudo networksetup -setdnsservers Wi-Fi 185.228.168.168 185.228.169.168

This command sets both primary and secondary DNS servers.

If you have a paid account, you will replace the values above with the values provided in your account.

Step 3: Verify DNS Settings

To verify the DNS settings for the Wi-Fi interface, use the following command:

networksetup -getdnsservers Wi-Fi

Example output:

185.228.168.168
185.228.169.168

Additional Tips & Tricks for Networksetup

Option 1: Reset DNS to Default (DHCP)

To revert DNS settings back to DHCP, run: 

networksetup -setdnsservers Wi-Fi

Option 2: Verify Current DNS Settings

To check the current DNS settings for the Wi-Fi interface, use:

networksetup -getdnsservers Wi-Fi

Using Terminal to change DNS settings on a Mac provides a more secure and controlled way to manage your network configurations. This method is especially useful for IT professionals and organizations needing to enforce DNS policies across multiple devices.

Updated on August 7, 2024
Was this article helpful?

Related Articles

Need Support?
Can’t find the answer you’re looking for? Don’t worry we’re here to help!
Contact Support