Resolve any `*.test` domain to `localhost`

A senior PHP + JavaScript + MySql developer of large-scale websites & backends and entrepreneur living in Vilnius, Lithuania with my wife Monika and my parrot Johnny.
Very good at project management and communication, too.
I’m here to create stuff that is useful to other people. Let's keep in touch!
Linux
This setup uses dnsmasq to handle *.test domain resolution, with systemd-resolved forwarding those queries to dnsmasq.
# Install dnsmasq
sudo apt update
sudo apt install dnsmasq
# Configure dnsmasq to listen on 127.0.0.2 and resolve *.test to 127.0.0.1
echo -e "port=53\nbind-interfaces\nlisten-address=127.0.0.2\naddress=/test/127.0.0.1" | sudo tee /etc/dnsmasq.d/test-tld.conf
# Create configuration directory
sudo mkdir -p /etc/systemd/resolved.conf.d
# Configure systemd-resolved to forward .test domains to dnsmasq at 127.0.0.2
echo -e '[Resolve]\nDNS=127.0.0.2\nDomains=~test' | sudo tee /etc/systemd/resolved.conf.d/test-tld.conf
# Restart services
sudo systemctl restart dnsmasq
sudo systemctl restart systemd-resolved
# Auto-start it after reboot
sudo systemctl enable --now dnsmasq
# Test it works
resolvectl status
resolvectl query foo.test
ping -c 1 foo.test
nslookup foo.test
Note: nslookup may show "REFUSED" error even when resolution works correctly. Use resolvectl query for clearer output.
How it works:
dnsmasq listens on
127.0.0.2:53and resolves*.testto127.0.0.1systemd-resolved forwards all
*.testqueries to dnsmasq at127.0.0.2NetworkManager is NOT configured to use dnsmasq (no changes needed)
Mac
macOS actually has a simpler approach using the /etc/resolver/ directory:
# Create resolver configuration for .test TLD
sudo mkdir -p /etc/resolver
echo "nameserver 127.0.0.1" | sudo tee /etc/resolver/test
# Install and configure dnsmasq
brew install dnsmasq
echo "address=/test/127.0.0.1" >> /usr/local/etc/dnsmasq.conf
sudo brew services start dnsmasq
# Test
ping foo.test
Windows
Install Laravel Herd for Windows, and it will automatically configure *.test domains to be served from 127.0.0.1.



