brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: set DNS servers per network service with networksetup

Network and access
~/tips/tip-macos-networksetup-dns

networksetup -listallnetworkservices

Changes the DNS servers of a network connection from the terminal, and resets them.

Changing DNS in System Settings means a lot of clicking. networksetup does it in two commands.

First find the name of the network service. Then set its servers.

networksetup -listallnetworkservices
networksetup -getdnsservers Wi-Fi
sudo networksetup -setdnsservers Wi-Fi 9.9.9.9 149.112.112.112

The syntax is -setdnsservers networkservice dns1 [dns2] [...]. To go back to whatever the network hands out, put the word empty in place of the server addresses.

sudo networksetup -setdnsservers Wi-Fi empty

The man page says the command needs at least admin privileges to change network settings, so expect to use sudo.

The caveat is the service name. It has to match exactly, quotes included when it has spaces, and your Wi-Fi may not be called Wi-Fi. List the services first. Also remember a manual DNS setting stays when you switch to another network, which is exactly the thing people forget about a year later.

The reason to prefer the terminal here is repeatability. If you switch between a home and a work setup, a two line script beats remembering which pane in System Settings hides the DNS field. Keep the command in a note, with the reset line right below it.

Further reading: networksetup.8 man page, On this site: dig @server name tells you which DNS server is lying to you, On this site: tailscale dns status shows what MagicDNS is really doing

More Network and access tips scp -3 alice@server-a:/var/backups/db.sql.gz bob@server-b:/srv/restore/ tailscale exit-node suggest tailscale lock sign nodekey:1abddef1 tlpub:abcdef12 wg genpsk > peer1.psk Table = off All Network and access tips (163) All topics

Link