Set custom DNS servers from Terminal — via SS64
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
- The easy way: System Settings > Network, click your connection, click Details, then DNS, and add servers with +.
- In Terminal, run
networksetup -listallnetworkservicesto get the exact service name (such asWi-FiorEthernet), then run the command with your chosen servers. - 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.1Undo
sudo networksetup -setdnsservers Wi-Fi emptyThe example uses Cloudflare's public resolvers; swap in any servers you prefer.
Sources
- networksetup — by SS64
- 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.