Skip to main content

How to Set Up DNS Routing by Domain on macOS

·493 words·3 mins

Introduction #

In today’s interconnected world, efficient network configuration is key. This guide focuses on a specific aspect of network configuration on macOS: setting up DNS routing for specific domains. Ideal for those who use VPNs and wish to maintain optimal network configuration, this guide will walk you through the process step-by-step.

Overview: Custom DNS Configuration for Specific Domains on macOS #

I have been looking into a solution for using specific DNS servers for certain internal sudomains. These DNS servers are only available via VPN.

I don’t want all my queries to go trough this internal DNS resolver, because the my usual resolver blocks ads and trackers.

The Effective Solution: to specify the resolver to use for a specific domain, create a file named after the domain in /etc/resolver/ and add the nameservers.

Step-by-Step Configuration Guide #

Step 1: Verify the Existence of /etc/resolver/ Directory #

It’s essential to first ensure that the required directory exists on your system. This directory will hold your custom DNS configurations. First make sure the /etc/resolver/ directory exists

macbook:~ user$ sudo mkdir /etc/resolver/

Step 2: Creating a Domain-Specific Configuration File #

Once you have confirmed the existence of the directory, the next step involves creating a file that is specific to the domain you want to configure. Create the domain file

macbook:~ user$ sudo vi /etc/resolver/

Step 3: Adding Nameservers to Your Domain File #

After creating the domain-specific file, the crucial part is to add the nameservers. This determines where your DNS queries for the domain are sent. Add the nameservers to the file you just created

macbook:~ user$ cat /etc/resolver/

Now, all queries for will be resolved by

The caveat with this technique is that tools like dig won’t actually resolve domains like apps and will bypass this.

Testing Your DNS Configuration #

After setting up your DNS configurations, it’s vital to test and ensure that they are working as expected.

Verifying Configuration with ‘scutil –dns’ #

A reliable way to test your configuration is by using the scutil --dns command.

Using ‘scutil –dns’ for Verification #

Use the scutil --dns Command to Verify Configuration:

macbook:~ user$ scutil --dns
resolver #8
  domain   :
  nameserver[0] :
  flags    : Request A records, Request AAAA records
  reach    : 0x00000002 (Reachable)

Frequently Asked Questions #

Q1: Why is custom DNS routing important on macOS?
A: Custom DNS routing allows for more control over network traffic, particularly useful in professional settings or when using VPNs.

Q2: Can this setup improve network security?
A: Yes, by directing DNS queries through specific servers, you can enhance security and privacy.

Q3: What if I encounter errors during configuration?
A: Ensure you have admin rights and that you’re entering commands correctly. For specific issues, consult online forums or Apple support.

Custom DNS routing on macOS can significantly improve your network performance, especially when dealing with internal domains over VPNs. This guide aims to simplify the process, making it accessible even to those with limited networking experience.