Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (45 sloc) 1.92 KB

Set up a local test domain with dnsmasq

Use the .test TLD

RFC-2606 reserves 4 different TLDs for testing and documentation examples:

  • .test
  • .example
  • .invalid
  • .localhost

It also reserves these second-level addresses:

  • example.com
  • example.net
  • example.org

Set up dnsmasq and resolvers

  1. Install Homebrew and Homebrew Services if you haven't already.

  2. brew install dnsmasq, edit its config (/usr/local/etc/dnsmasq.conf, assuming your brew --prefix is /usr/local) and enable only these options:

    no-resolv
    address=/.localdomain/127.0.0.1
    address=/.test/127.0.0.1
    
  3. Create /etc/resolver directory, and add 127.0.0.1 (dnsmasq) as nameserver for our TLDs:

    % sudo mkdir -pv /etc/resolver
    % sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/localdomain'
    % sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/test'
    
  4. System Preferences > Network > Wi-Fi > Advanced… > Search Domains > add localdomain to the list.

  5. Start / restart dnsmasq and check that it is listening. Ping to test.

    % sudo brew services restart dnsmasq
    % lsof -Pn -i | grep LISTEN
    % ping foo
    PING foo.localdomain (127.0.0.1): 56 data bytes
    64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.033 ms
    ^C
    % ping foo.test
    PING foo.test (127.0.0.1): 56 data bytes
    64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.044 ms
    ^C
    % dig @127.0.0.1 foo.test
    

References

You can’t perform that action at this time.