Sleezr
Buy Sleezr
hosts filednsmasqwildcardsubdomainslocal development

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.

S

Sleezr Team

·2 min read
Wildcard Local Domains: hosts File Limits & dnsmasq

**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:

TEXT
127.0.0.1 myapp.test api.myapp.test admin.myapp.test

See 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)

BASH
brew install dnsmasq
echo 'address=/myapp.test/127.0.0.1' >> $(brew --prefix)/etc/dnsmasq.conf
sudo brew services start dnsmasq

Then tell macOS to send .test lookups to dnsmasq:

BASH
sudo mkdir -p /etc/resolver
echo 'nameserver 127.0.0.1' | sudo tee /etc/resolver/test

Now anything.myapp.test resolves to 127.0.0.1 without editing the hosts file.

Linux

BASH
sudo apt install dnsmasq
echo 'address=/myapp.test/127.0.0.1' | sudo tee /etc/dnsmasq.d/myapp.conf
sudo systemctl restart dnsmasq

On systemd-resolved setups, ensure dnsmasq is the resolver for .test or point /etc/resolv.conf accordingly, then flush DNS on Linux.

Verify it works

BASH
dig foo.myapp.test @127.0.0.1
ping bar.myapp.test

Both 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

Also readhosts file syntax and format guide
Also readWhich TLD to use for local development
Share this article

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

4 min read
localhostsubdomainslocal development

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.

S

Sleezr Team

Developer tools team

4 min read
hosts fileadmin rightspermissions

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).

S

Sleezr Team

Developer tools team

10 min read
hosts fileWindowseditors

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.

S

Sleezr Team

Developer tools team

3 min read
WordPresslocal developmenthosts file

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.

S

Sleezr Team

Developer tools team