Automatic local domains: Setting up dnsmasq for macOS High Sierra to Big Sur using Homebrew

Photo by imgix on Unsplash

Have you ever wished you could add domains on your local machine ( on the fly and not have to modify your /etc/hosts file?

These are the steps will allow you to create foo.localhost, bar.localhost, myproject.localhost …. just anything.localhost

Why .localhost? Back in 1999 localhost top level domain (tld) was reserved by the Internet Engineering Task Force (IETF), see RFC 2606. They also reserved test tld (.test) if you are interested in separating test from development.

How do we accomplish this?

Step 1

Install Homebrew

$ /usr/bin/ruby -e “$(curl -fsSL"

Step 2

Install dnsmasq

brew install dnsmasq

Step 3

Create config folder if it doesn’t already exist

mkdir -pv $(brew —- prefix)/etc/

Step 4

Configure dnsmasq for *.localhost

echo ‘address=/.localhost/’ >> $(brew — prefix)/etc/dnsmasq.conf

Step 5

Configure the port for macOS High Sierra

echo ‘port=53’ >> $(brew —- prefix)/etc/dnsmasq.conf

Step 6

Start dnsmasq as a service so it automatically starts at login

sudo brew services start dnsmasq

Step 7

Create a dns resolver

sudo mkdir -v /etc/resolversudo bash -c ‘echo “nameserver” > /etc/resolver/localhost’

Step 8

Verify that all .localhost requests are using

scutil --dns

You should see something like this

resolver #8domain   : localhostnameserver[0] :    : Request A records, Request AAAA recordsreach    : 0x00030002 (Reachable,Local Address,Directly Reachable Address)

You can also test by using ping

ping foo.localhost
ping anything.localhost


Now you can reference *.localhost and it will point to your local development machine. Now Profit!

Medium formatting is off, please see my blog to easily copy and paste.

Don’t forget to clap and share so others can find it.




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium Biweekly Lists KAVA、CART、FLOW and Starts Deposits and Trading Activity

Git and GitHub

Git and GitHub

Why Use C++ for Developing Business Applications?

The Best Programming Languages to Learn in 2021

ffmpeg convert on Mac

CS373 Spring 2022: Joriann Bassi

Destructive Migrations don’t have to destroy your Rails App

The Sidecar Pattern

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Khary Sharpe

Khary Sharpe

More from Medium

Scan your Terraform Code with Terrascan in Azure DevOps

What does the Computer Misuse Act mean? — Privacy Ninja

Scriptease: How to install the most popular services in several minutes

How to: Launching a web server on an ECS instance (2/2)