Wildcard Local Domains: hosts File Limits & dnsmasq
The hosts file does not support wildcards like *.myapp.test. Learn why, and how to set up wildcard local domains with dnsmasq on macOS and Linux.
Sleezr Team

Table of Contents
**The hosts file cannot do wildcards, a line like 127.0.0.1 *.myapp.test will not work. The hosts file matches exact** hostnames only, so every subdomain must be listed on its own line. When you need *.myapp.test (any subdomain) to resolve locally, use dnsmasq, a lightweight DNS resolver that supports wildcard rules.
Why the hosts file has no wildcards
The hosts file is a flat lookup table: one IP, one or more exact names per line. There is no pattern matching, so *, regexes, and ranges are ignored. For a few known subdomains, just list them:
127.0.0.1 myapp.test api.myapp.test admin.myapp.testSee the hosts file syntax guide for the exact format. This breaks down only when subdomains are dynamic or too many to maintain.
Wildcard local domains with dnsmasq
dnsmasq resolves a domain and all its subdomains with one rule.
macOS (Homebrew)
brew install dnsmasq
echo 'address=/myapp.test/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
sudo brew services start dnsmasqThen tell macOS to send .test lookups to dnsmasq:
sudo mkdir -p /etc/resolver
echo 'nameserver 127.0.0.1' | sudo tee /etc/resolver/testNow anything.myapp.test resolves to 127.0.0.1 without editing the hosts file.
Linux
sudo apt install dnsmasq
echo 'address=/myapp.test/127.0.0.1' | sudo tee /etc/dnsmasq.d/myapp.conf
sudo systemctl restart dnsmasqOn systemd-resolved setups, ensure dnsmasq is the resolver for .test or point /etc/resolv.conf accordingly, then flush DNS on Linux.
Verify it works
dig foo.myapp.test @127.0.0.1
ping bar.myapp.testBoth should resolve to 127.0.0.1. Pick a safe TLD first, see which TLD to use for local development.
hosts file vs dnsmasq: which to use
- A few fixed subdomains: the hosts file is simpler and needs no service.
- Dynamic or many subdomains: dnsmasq with a wildcard rule.
For everyday fixed mappings, Sleezr manages hosts entries with safe toggles and automatic DNS flushing, so you only reach for dnsmasq when you genuinely need wildcards.
_Last tested: June 2026 on macOS and Ubuntu 24.04._
Sources and further reading
Frequently Asked Questions
Does the hosts file support wildcards?
No. The hosts file matches exact hostnames only. A line like 127.0.0.1 *.myapp.test does not work, each subdomain must be listed explicitly.
How do I get wildcard local domains?
Use dnsmasq. A single rule like address=/myapp.test/127.0.0.1 resolves myapp.test and every subdomain to 127.0.0.1.
How do I point .test to dnsmasq on macOS?
Create /etc/resolver/test with "nameserver 127.0.0.1" so macOS sends all .test lookups to dnsmasq.
When should I just use the hosts file instead?
If you only have a handful of fixed subdomains, list them in the hosts file. Use dnsmasq when subdomains are dynamic or numerous.
Related Articles
How to Use Subdomains on localhost for Local Development
Use subdomains on localhost: the free *.localhost trick browsers resolve automatically, fixed subdomains via the hosts file, and wildcard subdomains with dnsmasq on Mac and Linux.
Sleezr Team
Developer tools team
Can You Edit the Hosts File Without Admin Rights?
Can you edit the hosts file without administrator rights? The honest answer plus real alternatives on Windows, Mac and Linux when you cannot elevate (proxy, Docker, local DNS, SSH).
Sleezr Team
Developer tools team
Best Hosts File Editors for Windows (2026 Comparison)
Compare the best Windows hosts file editors in 2026: Sleezr, PowerToys Hosts File Editor, HostsMan, SwitchHosts, and Notepad. Feature matrix, pros/cons, and who should switch.
Sleezr Team
Developer tools team
Which TLD to Use for Local Development (.test vs .localhost)
Which TLD to use for local development: prefer .test, avoid .dev and .local. Why .test is reserved, how to map it in the hosts file, and HTTPS tips.
Sleezr Team
Developer tools team
WordPress Local Development With a .test Domain (hosts file)
Set up a local WordPress site with a clean .test domain using the hosts file. Works with LocalWP, MAMP, XAMPP and Docker. Map the domain, flush DNS, configure WP.
Sleezr Team
Developer tools team