Change DNS Servers Terminal Mac: How-To
You can change your Mac’s DNS servers from the Terminal using the networksetup command, which lets you set specific DNS servers for a given network interface. This guide shows you the exact commands, how to verify the change, and what to do if something goes wrong.
Why Change DNS on a Mac?
DNS (Domain Name System) is the phonebook of the internet: it translates human-readable domain names like example.com into IP addresses. Your Mac normally uses the DNS servers provided by your router or ISP, but there are several reasons to switch:
- Speed: Some public DNS providers are faster than your ISP’s, especially if your ISP’s servers are overloaded.
- Reliability: Public DNS services often have better uptime and redundancy.
- Privacy: Many public DNS providers offer encrypted DNS (DoH/DoT) and claim not to sell your browsing data.
- Parental controls or filtering: Some DNS services block adult content or malware domains.
Changing DNS on a Mac is a system-wide setting that affects all network connections using that interface (Wi-Fi or Ethernet).
How to Find Your Network Interface Name
The networksetup command requires the exact name of your network interface. Common names are Wi-Fi and Ethernet, but they can vary (e.g., USB 10/100/1000 LAN). To list all interfaces, run:
networksetup -listallnetworkservices
This prints something like:
An asterisk (*) denotes that a network service is disabled.
Wi-Fi
Ethernet
USB 10/100/1000 LAN
Note the exact spelling, including spaces. If you have multiple interfaces, you’ll need to set DNS for each one you use.
Set DNS Servers via Terminal
The basic command to set DNS servers for a specific interface is:
networksetup -setdnsservers <interface> <dns1> <dns2> ...
For example, to set Wi-Fi to use Google’s public DNS (8.8.8.8 and 8.8.4.4):
networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4
You can specify up to three DNS servers. The order matters: your Mac tries the first one first, then the second, and so on. To set a single server, just list one.
If you want to use Cloudflare’s DNS (1.1.1.1 and 1.0.0.1), you’d run:
networksetup -setdnsservers Wi-Fi 1.1.1.1 1.0.0.1
Note: the command does not require sudo, but you may need to enter your admin password if your user account lacks permission to change network settings.
Verify the Change
After setting DNS, you can verify that the new servers are active with:
networksetup -getdnsservers Wi-Fi
This prints the current DNS servers for that interface. To test that DNS resolution actually works, you can use ping or nslookup:
nslookup example.com
Or check which DNS server is being used with scutil --dns (though it shows the full configuration, including any cached entries).
Revert to Automatic DNS (DHCP)
If you want to go back to using the DNS servers provided by your router or ISP (via DHCP), use the -setdnsservers command with the keyword empty:
networksetup -setdnsservers Wi-Fi empty
This clears all manual DNS entries and reverts to automatic. You can also do this from System Settings > Network > Wi-Fi > Details > DNS, but the terminal command is faster if you’re already in the shell.
Common Problems and Fixes
- Command not found: If
networksetupis missing, you’re likely not on macOS (it’s a Unix command). On Linux, you’d usenmcliorresolvectl. - Interface name wrong: If you get an error like “The parameters were not valid,â€� double-check the exact interface name with
networksetup -listallnetworkservices. Spaces matter. - Change doesn’t take effect: Sometimes the DNS cache needs to be flushed. Run
sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder(on macOS Monterey and earlier) orsudo killall -HUP mDNSResponder(on newer versions). - VPN or other network tools override DNS: If you’re using a VPN or a tool like Little Snitch, they may have their own DNS settings. Check those apps’ preferences.
Frequently Asked Questions
Does changing DNS via Terminal persist after reboot?
Yes, the setting is written to your network configuration and persists until you change it back or switch to DHCP. It’s the same as changing it in System Settings.
Can I set different DNS servers for Ethernet and Wi-Fi?
Absolutely. Each network interface has its own DNS settings. You can run the command separately for each interface, and your Mac will use the DNS for the interface that’s currently active.
What’s the best DNS server to use?
There’s no single “bestâ€� for everyone. Google (8.8.8.8), Cloudflare (1.1.1.1), and Quad9 (9.9.9.9) are popular. You can test latency with dig or nslookup, but performance varies by location and ISP. Many people choose based on privacy policies or features like malware blocking.
Will changing DNS speed up my internet?
It can reduce the time it takes to resolve domain names, which makes web browsing feel snappier, but it won’t increase your raw bandwidth. If your ISP’s DNS is slow, you might see a noticeable improvement.
Is it safe to change DNS servers?
Yes, as long as you use a reputable provider. Be cautious about entering random DNS servers from the internet, as they could be malicious. Stick to well-known public DNS providers.
How do I reset DNS to default on a Mac?
Use the command networksetup -setdnsservers Wi-Fi empty (replace Wi-Fi with your interface) to revert to DHCP-provided DNS. You can also go to System Settings > Network > your interface > Details > DNS and click the minus button to remove all entries.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.