Skip to content

Set custom DNS servers from Terminal — via SS64

Commandlow riskNeeds adminmacOS 14 Sonoma and later

You can point your Mac at a different DNS provider (for example your router, Pi-hole, or a public resolver) in System Settings, or with one networksetup command that's easy to script and to undo.

Takes effect right away

The easy way

  1. The easy way: System Settings > Network, click your connection, click Details, then DNS, and add servers with +.
  2. In Terminal, run networksetup -listallnetworkservices to get the exact service name (such as Wi-Fi or Ethernet), then run the command with your chosen servers.
  3. Check with networksetup -getdnsservers Wi-Fi. The undo (empty) goes back to the DNS servers your router hands out.

Command

Run in Terminal (Applications › Utilities). It uses sudo, so macOS asks for your password.

sudo networksetup -setdnsservers Wi-Fi 1.1.1.1 1.0.0.1

Undo

sudo networksetup -setdnsservers Wi-Fi empty
The example uses Cloudflare's public resolvers; swap in any servers you prefer.

Sources

Source reviewed
2026-11-02
Link checked
2026-11-02
Tested hands-on
Not by Oddbyte.Me

Oddbyte.Me hasn't tried this on every macOS version, so keep the undo handy.

dnsnetworksetuppi-holecloudflarecustom dnsterminal

More in Networking

Flush the DNS cache — via Marc Abramowitz

Commandlow riskAdmin

If a website moved to a new server, or you changed DNS settings and some sites still won't load, your Mac may be holding on to old address lookups. Flushing the DNS cache makes it look them up fresh. It's a troubleshooting step, not a speed boost.

Run Apple's built-in internet speed test — via SS64

Commandlow risk

macOS has its own speed test in Terminal. Besides download and upload speed, it measures 'responsiveness' (round trips per minute while the line is busy), which explains why video calls stutter on a connection that looks fast.