Setup Automatic Local Domains with Dnsmasq on MacOS Ventura
We will set up Dnsmasq as a local DNS server to resolve all development urls. For development purposes we will use the
.test since both
.dev domains are now publicly available domains. When the setup is completed all subdomains on the
.test domain will resolve to localhost (
This setup will work with any development environment either local web server or docker since all subdomains resolve to the localhost. Edit of
/etc/hosts file for each project will no long be required.
- Setup command line tools (Xcode) on macOS
gyp: No Xcode or CLT version detected macOS Big Sur |Anansewaa.com
How to solve gyp: No Xcode or CLT version detected on macOS Big Sur
- You should have brew setup and working
- Optional development environment; docker or full local server environment.
How to Set Up NGINX on Mac for Testing
Do you need to test the website you're developing but only have your Mac to work with? You don't need to build a…
macOS 12.0 Monterey Apache Setup: Multiple PHP Versions
Part 1: macOS 11.0 Big Sur Web Development Environment Developing web applications on macOS is a real joy. There are…
Step 1: Install and configure Dnsmasq
Use brew to install dnsmasq by opening your preferred terminal application and run the following command.
brew install dnsmasq
Create a config directory for dnsmasq
mkdir -pv $(brew --prefix)/etc/
Setup domain configurations for our
*.test domain. If you prefer a different domain than the suggested one, replace
.test in the command below with your preferred domain.
echo 'address=/.test/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
The configuration is complete, now use the service management option of brew to manage the dnsmasq service. This will autostart the service even after reboot.
sudo brew services start dnsmasq
To test if the configuration is successful, perform a dig to query your local dnsmasq instance.
dig arctic-jill.test @127.0.0.1
Step 2: Create a dns resolver and test setup
Next create a dns resolver for the selected domain, which is
.test in the example given. Create a resolver directory if it doesn’t already exist.
sudo mkdir -v /etc/resolver
Add dnsmasq namserver to resolvers
sudo bash -c 'echo "nameserver 127.0.0.1" > /etc/resolver/test'
Concluding test if external links resolve successfully using the ping command below.
ping -c 1 apple.com
It still works if a reply comes from the apple.com server.
Now check if dnsmasq handles all request on the
ping -c 1 another-sub-domain.test
This should return a reply from
That is a wrap, but this setup can be extended with a virtual host set for local server development environments (apache or nginx webserver). The following guides can help.
macOS 12.0 Monterey Apache Setup: MySQL, Xdebug & More...
Part 2: macOS 12.0 Monterey Web Development Environment In Part 1 of this 3-part series, we covered configuring Apache…