Fix macOS DNS resolution for local domains when connected to a VPN.
macOS handles DNS differently than Linux. When you connect to a VPN, macOS often routes all DNS queries through the VPN's DNS server, breaking access to local network resources like:
- Local servers (
nas.home.local) - Self-hosted services (
git.example.lan) - Internal domains your home DNS resolves
Linux handles this gracefully with search domains and resolver ordering. macOS... doesn't.
macOS supports per-domain DNS resolvers via /etc/resolver/. This script manages those files so your local domains always resolve through your local DNS, regardless of VPN state.
curl -O https://raw.githubusercontent.com/kaibae19/mac-local-dns/main/mac-local-dns
chmod +x mac-local-dns
sudo mv mac-local-dns /usr/local/bin/Or clone the repo:
git clone https://github.com/kaibae19/mac-local-dns.git
cd mac-local-dns
chmod +x mac-local-dns
sudo cp mac-local-dns /usr/local/bin/Just run without arguments:
mac-local-dns╔═══════════════════════════════════════╗
║ macOS Local DNS Resolver Manager ║
╚═══════════════════════════════════════╝
=== Local DNS Resolvers ===
example.com → 192.168.1.1
home.local → 192.168.1.1
[A]dd [R]emove [Q]uit
>
# Add a domain with DNS server
mac-local-dns add home.local 192.168.1.1
# Remove a domain
mac-local-dns remove home.local
# List current resolvers
mac-local-dns listThe script creates files in /etc/resolver/ named after each domain:
/etc/resolver/home.local
/etc/resolver/mycompany.lan
Each file contains a nameserver directive pointing to your local DNS:
nameserver 192.168.1.1
macOS checks this directory and uses domain-specific resolvers before falling back to the system default (your VPN's DNS).
Home network with PiHole at 192.168.1.53 and local domain home.lan:
mac-local-dns add home.lan 192.168.1.53
mac-local-dns add nas.home.lan 192.168.1.53Now server.home.lan resolves via PiHole even when connected to work VPN.
Check macOS DNS configuration:
scutil --dnsVerify resolver files exist:
ls -la /etc/resolver/
cat /etc/resolver/your.domainTest resolution:
dscacheutil -q host -a name server.home.lanPolyForm Noncommercial 1.0.0 - Free for personal use. Commercial use requires a separate license.
Because this should just work like it does on Linux, but Apple decided DNS needed to be ✨special✨.