Introduction
DNS (Domain Name System) converts user-friendly website names (like google.com) into IP addresses that computers understand. By default, macOS uses DNS servers provided by your internet service provider. However, these servers may be slow, insecure, or block access to certain websites.
By switching DNS to public servers from Google, Cloudflare, or other providers, you can:
- Speed up webpage loading through faster domain resolution.
- Bypass regional blocks and censorship.
- Improve security by using DNS with DNSSEC support and phishing filtering.
This guide will show you how to change DNS on a Mac in two ways: through the graphical interface and via the terminal.
Requirements
Before you begin, ensure that:
- You have a Mac with macOS 12 or newer (instructions apply to Monterey, Ventura, Sonoma).
- You are logged in with an administrator account (a password may be required to apply system settings).
- You have an active network connection (Wi-Fi or Ethernet).
- You know the DNS server addresses you want to use. Popular options:
- Google DNS:
8.8.8.8and8.8.4.4 - Cloudflare DNS:
1.1.1.1and1.0.0.1 - OpenDNS:
208.67.222.222and208.67.220.220
- Google DNS:
Method 1: Change DNS via System Settings
This method is suitable for most users and does not require command-line work.
Step 1: Open Network Settings
- Click the Apple menu (∧) in the top-left corner of the screen.
- Select "System Settings".
- In the sidebar, find and click "Network".
💡 Tip: In macOS Ventura and earlier versions, the section may be called "Network" in the "System Settings" window. The Sonoma interface is similar.
Step 2: Select Active Connection and Open DNS Settings
- From the list of network interfaces on the left, select your active connection:
- For a wired connection — Ethernet.
- For wireless — Wi-Fi (it should be highlighted in green).
- Click the "Advanced" button in the bottom-right corner of the window.
- A new window will open. Navigate to the "DNS" tab.
Step 3: Add DNS Servers
- Click the "+" (plus) button below the list of DNS servers.
- Enter the DNS server address (e.g.,
8.8.8.8). Press Enter. - Repeat for the second server (e.g.,
8.8.4.4). You can add more servers, but two are usually sufficient. - To remove an old DNS server, select it in the list and click "-" (minus).
⚠️ Important: Ensure the added DNS servers are first in the list. macOS uses them in priority order. Drag them up if needed.
Step 4: Save Changes
- Click "OK" in the bottom-right corner of the "Advanced" window.
- Back in the network window, click "Apply" to save the settings. Changes take effect immediately.
Method 2: Change DNS via Terminal
This method is useful for automation, remote management, or if the graphical interface is unavailable.
Step 1: Identify the Network Service Name
- Open Terminal from the "Utilities" folder or via Spotlight (Cmd+Space, type "Terminal").
- Enter the command to list network services:
networksetup -listallnetworkservices - Find the name of your active connection (e.g.,
Wi-FiorEthernet) in the output. Note that names may contain spaces or quotes.
Step 2: Set DNS Servers
Use the networksetup command, specifying the service and DNS addresses.
Example for Wi-Fi:
sudo networksetup -setdnsservers "Wi-Fi" 8.8.8.8 8.8.4.4
Example for Ethernet:
sudo networksetup -setdnsservers "Ethernet" 1.1.1.1 1.0.0.1
⚠️ Important:
- The command requires an administrator password (enter it when prompted; characters are not displayed).
- If the service name contains spaces, enclose it in quotes.
- To revert to automatic DNS (from your provider), run:
sudo networksetup -setdnsservers "Wi-Fi" Empty
Step 3: Verify Current DNS Settings (Optional)
Confirm that DNS has changed:
networksetup -getdnsservers "Wi-Fi"
The output should display the addresses you added.
Verify the Result
After changing DNS, ensure the settings work correctly:
- Restart your browser or network-using applications.
- Check domain resolution via
nslookupin Terminal:nslookup google.com
Look for the "Address" line in the output — it should correspond to the IP address forgoogle.com. If DNS is working, the command will return an address without errors. - For a more detailed check, use
dig(if installed via Homebrew):dig google.com
The IP address should appear in the "ANSWER SECTION". - Test speed: visit several websites, especially those that previously loaded slowly. If DNS was the bottleneck, loading should be faster.
Potential Issues
Issue 1: Changes Not Applied
- Cause: The "Apply" button in network settings wasn't clicked, or the
networksetupcommand was run withoutsudo. - Solution: In the graphical interface, always click "Apply". In the terminal, use
sudoand enter your password.
Issue 2: No Internet Access After DNS Change
- Cause: Incorrect DNS server addresses or a temporary outage with the DNS provider.
- Solution: Revert to your previous DNS servers (or select "Automatic"). Verify that the chosen DNS servers are reachable (e.g.,
8.8.8.8should respond to ping).
Issue 3: DNS Queries Still Going to Old Server
- Cause: DNS cache on your Mac or router.
- Solution: Clear the macOS DNS cache:
If you use a router, reboot it.sudo dscacheutil -flushcache sudo killall -HUP mDNSResponder
Issue 4: Conflict with VPN or Antivirus
- Cause: Some VPN clients or security programs override DNS settings.
- Solution: Configure DNS within the VPN application or disable it for testing. Check your antivirus settings.
Issue 5: Terminal Cannot Find Service
- Cause: Incorrect network service name (e.g., "Wi-Fi" vs. "Wi-Fi" with quotes).
- Solution: Check the exact name via
networksetup -listallnetworkservices. Ensure you use the precise name, including spaces and capitalization.