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.
Locahl 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, Locahl 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._
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"Explained why *.test never worked in my hosts file and set me up with dnsmasq in minutes."
June 12, 2026
"The macOS resolver config was the missing piece for *.test subdomains. Works perfectly now."
June 10, 2026
"Great guide. A systemd-resolved section for Ubuntu would complete it."
June 8, 2026
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
Best Hosts File Editors for Windows (2026)
The best hosts file editors for Windows in 2026: Locahl, Notepad as admin, Hosts File Editor+, SwitchHosts and BlueLife Hosts Editor. Pros, cons and when to use each.
Locahl 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.
Locahl 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.
Locahl Team
Developer tools team
How to Edit the Hosts File on Windows 10 (2026)
Edit the Windows 10 hosts file step by step: Notepad as administrator, file location, UAC, save errors, DNS flush, and troubleshooting access denied.
Locahl Team
How to Edit the Hosts File on Windows 11 (2026)
Three methods to edit the Windows 11 hosts file: Notepad as admin, PowerShell, and VS Code. Includes UAC tips, DNS flush, and troubleshooting for 24H2.
Locahl Team