When you type a website address like “google.com” into your browser, your Mac relies on a Domain Name System (DNS) server to translate that human-readable name into a machine-readable IP address. By default, your Mac uses the DNS servers provided by your Internet Service Provider (ISP), which are often slow, unreliable, or subject to logging and censorship.
Switching to a faster, more secure public DNS—such as Cloudflare (1.1.1.1) or Google Public DNS (8.8.8.8)—is one of the easiest ways to speed up your web browsing. While you can change these settings via the graphical System Settings menu, doing so across multiple network interfaces (Wi-Fi, Ethernet, Thunderbolt) is tedious.
In this guide, you will learn how to use the macOS Terminal and the powerful networksetup command to instantly change your DNS servers.
Step 1: Open the Terminal
Because you are modifying core networking parameters, you must use the command line and execute the commands with administrative privileges.
- Press Command + Space to open Spotlight Search.
- Type Terminal and press Return.
Step 2: Identify Your Network Interface
Before you can assign a new DNS server, you must tell macOS exactly which network adapter you are trying to modify. Is it your Wi-Fi card or a wired Ethernet dongle?
To list all available network services, type the following command and press Return:
networksetup -listallnetworkservices
The terminal will output a list of names, such as Wi-Fi, Thunderbolt Ethernet, or Bluetooth PAN. Identify the exact name of your active connection. In most cases, it will simply be Wi-Fi.
Step 3: Set the New DNS Servers
Now that you know the interface name, you can assign the new DNS addresses.
The syntax for the command is: sudo networksetup -setdnsservers [Interface Name] [DNS1] [DNS2].
For this example, we will configure the primary Wi-Fi interface to use Cloudflare’s blazing-fast, privacy-focused DNS servers (1.1.1.1 and 1.0.0.1).
- Type the following command into the Terminal:
sudo networksetup -setdnsservers Wi-Fi 1.1.1.1 1.0.0.1 - Press Return.
- The terminal will prompt you for a password. Type your Mac administrator password (the cursor will not move while typing) and press Return again.
The change is instantaneous. There is no confirmation message; the terminal will simply drop down to a new, blank command prompt. If your interface name has a space in it (like “Thunderbolt Ethernet”), you must wrap the name in quotation marks (e.g., "Thunderbolt Ethernet").
Step 4: Verify the Changes
To ensure the new DNS servers were properly applied, you can read the configuration back from the system using the -getdnsservers flag.
networksetup -getdnsservers Wi-Fi
The terminal should output the two IP addresses you just entered (1.1.1.1 and 1.0.0.1). Your Mac is now routing all web traffic through the new, optimized servers.
How to Revert to Default (ISP) DNS
If you ever travel to a hotel or cafe with a captive portal that requires the local ISP’s DNS to function properly, you can easily wipe your custom settings and revert to automatic DHCP routing.
Run the exact same command as Step 3, but replace the IP addresses with the word Empty:
sudo networksetup -setdnsservers Wi-Fi Empty
By mastering the networksetup command, system administrators and power users can script rapid network changes without ever touching the graphical interface.