*.localhost -> 127.0.0.1

Install with Homebrew

brew install dnsmasq

make launchd start dnsmasq at startup

sudo brew services start dnsmasq

Config

edit macOS homebrew dnsmasq configuration file /usr/local/etc/dnsmasq.conf

listen-address=127.0.0.1

# Never forward plain names (without a dot or domain part)
domain-needed

# Never forward addresses in the non-routed address spaces.
bogus-priv

address=/.localhost/127.0.0.1

restart dnsmasq

sudo brew services restart dnsmasq

set macOS DNS servers

networksetup -setdnsservers Wi-Fi \
    127.0.0.1 \
    1.1.1.1 \
    1.0.0.1 \
    2606:4700:4700::1111 \
    2606:4700:4700::1001 \
    8.8.8.8 \
    8.8.4.4 \
    2001:4860:4860::8888 \
    2001:4860:4860::8844

Test

dig s3.localhost
; <<>> DiG 9.10.6 <<>> s3.localhost
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 51833
;; flags: qr aa rd ra ad; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;s3.localhost.            IN    A

;; ANSWER SECTION:
s3.localhost.        0    IN    A    127.0.0.1

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Sat Mar 09 14:06:31 +07 2019
;; MSG SIZE  rcvd: 57