Changing your DNS settings on a Mac can improve browsing speed, enhance security, and allow for better content filtering. While the System Preferences pane provides a graphical interface for these changes, using the Terminal gives you more control—especially useful for advanced users and IT administrators managing multiple machines.
This guide walks you through changing DNS settings on a Mac using the Terminal.
Why Use Terminal to Change DNS?
Using Terminal offers several benefits:
- Greater control and automation capabilities
- Ability to lock settings from user interference
- Efficient for deploying DNS changes across multiple devices
macOS includes a built-in utility called networksetup
, a command-line tool that lets you configure network services, including DNS settings.
Steps to Change DNS on a Mac Using Terminal
Note: This example uses CleanBrowsing’s Free Family Filter DNS servers. If you’re using a premium DNS provider, substitute the IP addresses with those from your dashboard.
Step 1 – Identify Your Interfaces
Open the Terminal app and enter:
$ sudo networksetup -listallnetworkservices
You’ll see a list of all network services. An asterisk (*
) indicates a disabled interface. Typically, your active connection will be under “Wi-Fi.”
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
Use the following command to assign DNS servers to a network service. Replace (Network Service)
with your actual service name (e.g., “Wi-Fi”) and (DNS IP)
with the DNS server IPs you want to use:
Set IPv4 DNS Servers
sudo networksetup -setdnsservers "Wi-Fi" 185.228.168.168 185.228.169.168
Set IPv6 DNS Servers
sudo networksetup -setv6dns "Wi-Fi" 2a0d:2a00:0001:: 2a0d:2a00:0002::
Replace “Wi-Fi” with the name of your network interface if different.
This sets both primary and secondary DNS servers. If you have a paid DNS plan, use the IPs provided in your account.
Step 3: Verify DNS Settings
To confirm that your DNS settings were updated correctly:
networksetup -getdnsservers Wi-Fi
Expected output:
185.228.168.168
185.228.169.168
2a0d:2a00:0001::
2a0d:2a00:0002::
Step 4: Handle Dynamic Public IP Addresses
If your ISP provides a dynamic IP address (which changes periodically), you’ll need to update your DNS provider regularly. CleanBrowsing, for example, uses a Dynamic Device feature for this purpose (found on Network Page).
Open the crontab editor:
$ crontab -e
Add the following line, replacing MYCODE
with the Dynamic Device code from your CleanBrowsing dashboard:
*/2 * * * * curl https://my.cleanbrowsing.org/dynip/MYCODE
This will update your IP every 2 minutes. For more information, see CleanBrowsing’s article: Update CleanBrowsing with Public IP’s that Change (w/MacOS)
Additional Tips & Tricks for Networksetup
Option 1: Reset DNS to Default (DHCP)
To revert back to the default settings (typically assigned via DHCP):
networksetup -setdnsservers Wi-Fi
Option 2: Verify Current DNS Settings
To view the current DNS configuration for your interface:
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.