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: a file in /etc/resolver sends one domain to its own DNS server on a Mac

Network and access
~/tips/tip-dns-etc-resolver-mac

sudo mkdir -p /etc/resolver

Resolve a home or lab domain with a specific server while everything else stays unchanged.

On a Mac you may want names under your home domain to go to the router, while everything else keeps using the DNS from the network you happen to be on. macOS has a simple, old mechanism for that.

Create a file named after the domain:

sudo mkdir -p /etc/resolver
echo "nameserver 192.0.2.1" | sudo tee /etc/resolver/home.example

From now on, lookups for home.example and its subdomains go to 192.0.2.1. The man page for resolver(5) says the file name is used as the domain name, so you do not need a domain line inside. You can add up to three nameserver lines, and a port line if your server listens somewhere else than 53.

Check that macOS picked it up:

scutil --dns | grep -A3 home.example

Here comes the part I find confusing. nslookup and dig do not use this system; they read /etc/resolv.conf and ask that server directly. So they will tell you it does not work while Safari and ssh resolve the name fine. Test with dscacheutil -q host -a name nas.home.example or just ping.

To undo it, delete the file. It needs no restart either way.

Further reading: resolver(5) man page

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