MacOS problem with DNS server (dnsmasq, resolver)

Viewed 25

Like every standard developer, I was using /etc/hosts to add new domains related to localhost. But today (because of project requirements and needs of wildcard for local domain) I tried to install and use dnsmasq.

System info

Macos

macOs Monterey 12.5.1 (21G83)

dnsmasq (installed using brew)

╰─ sudo /usr/local/opt/dnsmasq/sbin/dnsmasq --version
Dnsmasq version 2.86  Copyright (c) 2000-2021 Simon Kelley
Compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack no-ipset auth no-cryptohash no-DNSSEC loop-detect no-inotify dumpfile

This software comes with ABSOLUTELY NO WARRANTY.
Dnsmasq is free software, and you are welcome to redistribute it
under the terms of the GNU General Public License, version 2 or 3.

Problem

When I tried to make dnsmasq work, I found a very strange thing. (Info below will be with disabled wifi. Wired internet connection direct to MacBook I do NOT have.)

dig example1 @127.0.0.1

; <<>> DiG 9.10.6 <<>> example1 @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27361
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example1.          IN  A

;; ANSWER SECTION:
example1.       3600    IN  A   198.18.2.86

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:12 EEST 2022
;; MSG SIZE  rcvd: 50

dig example1.local @127.0.0.1

; <<>> DiG 9.10.6 <<>> example1.local @127.0.0.1
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3372
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example1.local.            IN  A

;; ANSWER SECTION:
example1.local.     3600    IN  A   198.18.2.87

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:15 EEST 2022
;; MSG SIZE  rcvd: 62

dig example2.local @127.0.0.1

; <<>> DiG 9.10.6 <<>> example2.local @127.0.0.1
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31079
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example2.local.            IN  A

;; ANSWER SECTION:
example2.local.     3600    IN  A   198.18.2.1

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:20 EEST 2022
;; MSG SIZE  rcvd: 62

dig example3.local @127.0.0.1

; <<>> DiG 9.10.6 <<>> example3.local @127.0.0.1
;; global options: +cmd
;; Got answer:
;; WARNING: .local is reserved for Multicast DNS
;; You are currently testing what happens when an mDNS query is leaked to DNS
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22255
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example3.local.            IN  A

;; ANSWER SECTION:
example3.local.     3600    IN  A   198.18.2.3

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:33 EEST 2022
;; MSG SIZE  rcvd: 62

dig example3.dev @127.0.0.1

; <<>> DiG 9.10.6 <<>> example3.dev @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43093
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example3.dev.          IN  A

;; ANSWER SECTION:
example3.dev.       3600    IN  A   198.18.2.4

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:45 EEST 2022
;; MSG SIZE  rcvd: 58

dig example4.dev @127.0.0.1

; <<>> DiG 9.10.6 <<>> example4.dev @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22783
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example4.dev.          IN  A

;; ANSWER SECTION:
example4.dev.       3600    IN  A   198.18.2.88

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:48 EEST 2022
;; MSG SIZE  rcvd: 58

dig example2.dev @127.0.0.1

; <<>> DiG 9.10.6 <<>> example2.dev @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 49506
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example2.dev.          IN  A

;; ANSWER SECTION:
example2.dev.       3600    IN  A   198.18.2.89

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:52 EEST 2022
;; MSG SIZE  rcvd: 58

dig example2.localhost @127.0.0.1

; <<>> DiG 9.10.6 <<>> example2.localhost @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 23993
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example2.localhost.        IN  A

;; ANSWER SECTION:
example2.localhost. 3600    IN  A   198.18.2.90

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:03:58 EEST 2022
;; MSG SIZE  rcvd: 70

dig example3.localhost @127.0.0.1

; <<>> DiG 9.10.6 <<>> example3.localhost @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36206
;; flags: qr rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;example3.localhost.        IN  A

;; ANSWER SECTION:
example3.localhost. 3600    IN  A   198.18.2.91

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Sep 22 16:04:03 EEST 2022
;; MSG SIZE  rcvd: 70

Nmap when dnsmasq enabled:

nmap -p 53 127.0.0.1
Starting Nmap 7.93 ( https://nmap.org ) at 2022-09-22 16:07 EEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00017s latency).

PORT   STATE  SERVICE
53/tcp closed domain

Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

Nmap when dnsmasq disabled:

nmap -p 53 127.0.0.1
Starting Nmap 7.93 ( https://nmap.org ) at 2022-09-22 16:09 EEST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00016s latency).

PORT   STATE SERVICE
53/tcp open  domain

Nmap done: 1 IP address (1 host up) scanned in 0.03 seconds

Files in resolver folder /etc/resolver/ all with content nameserver 127.0.0.1:

.local
.localhost
dev
local
localhost
test
scutil --dns
DNS configuration

resolver #1
  flags    :
  reach    : 0x00000000 (Not Reachable)

resolver #2
  domain   : local
  options  : mdns
  timeout  : 5
  flags    :
  reach    : 0x00000000 (Not Reachable)
  order    : 300000

resolver #3
  domain   : 254.169.in-addr.arpa
  options  : mdns
  timeout  : 5
  flags    :
  reach    : 0x00000000 (Not Reachable)
  order    : 300200

resolver #4
  domain   : 8.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    :
  reach    : 0x00000000 (Not Reachable)
  order    : 300400

resolver #5
  domain   : 9.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    :
  reach    : 0x00000000 (Not Reachable)
  order    : 300600

resolver #6
  domain   : a.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    :
  reach    : 0x00000000 (Not Reachable)
  order    : 300800

resolver #7
  domain   : b.e.f.ip6.arpa
  options  : mdns
  timeout  : 5
  flags    :
  reach    : 0x00000000 (Not Reachable)
  order    : 301000

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)

resolver #9
  domain   : .local
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

resolver #10
  domain   : local
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

resolver #11
  domain   : .localhost
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

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

resolver #13
  domain   : localhost
  nameserver[0] : 127.0.0.1
  flags    : Request A records, Request AAAA records
  reach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

So, the question is: Where and how I get IP address 192.168.2.* instead of 127.0.0.1? And how to replace it with 127.0.0.1. I do not have anything starting with 192.168 in my network configs:

ifconfig | grep 192

0 Answers
Related