Skip to content

Instantly share code, notes, and snippets.

@brightzheng100
Last active July 21, 2020 08:21
Show Gist options
  • Save brightzheng100/e88cf334432758f0d702165fabdb510d to your computer and use it in GitHub Desktop.
Save brightzheng100/e88cf334432758f0d702165fabdb510d to your computer and use it in GitHub Desktop.
Mac Book Pro

Install Local DNS by dnsmasq in Mac

Install dnsmasq

brew update
brew install dnsmasq

Configure dnsmasq

cat >> /usr/local/etc/dnsmasq.conf <<EOF
conf-dir=/usr/local/etc/dnsmasq.d,*.conf
EOF

mkdir -p /usr/local/etc/dnsmasq.d

# config test domain
touch /usr/local/etc/dnsmasq.d/test.conf

cat > /usr/local/etc/dnsmasq.d/test.conf <<EOF
address=/concourse.test/10.244.0.101
address=/minio.test/10.244.0.102
address=/git.test/10.244.0.103
address=/ldap.test/128.0.0.1
address=/.test/127.0.0.1
EOF

# Restart
sudo brew services restart dnsmasq

# Clear cache
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder

Further configuration: Only send .test domain queries to dnsmasq

sudo mkdir /etc/resolver
sudo touch /etc/resolver/test
cat <<EOF | sudo tee /etc/resolver/test
nameserver 127.0.0.1
search_order 1
EOF

Verify

$ scutil --dns

resolver #8
  domain   : test
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)
  order    : 1

$ dig concourse.test
...
;; ANSWER SECTION:
concourse.test.         0       IN      A       10.244.0.101

$ dig google.com
...
;; ANSWER SECTION:
google.com.             70      IN      A       172.217.194.101
google.com.             70      IN      A       172.217.194.138
google.com.             70      IN      A       172.217.194.113
google.com.             70      IN      A       172.217.194.139
google.com.             70      IN      A       172.217.194.100
google.com.             70      IN      A       172.217.194.102

Ref:

  1. https://www.stevenrombauts.be/2018/01/use-dnsmasq-instead-of-etc-hosts/
  2. https://www.stevenrombauts.be/2019/06/restart-dnsmasq-without-sudo/
  3. https://medium.com/@zhimin.wen/setup-local-dns-server-on-macbook-82ad22e76f2a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment