How to put wildcard entry into /etc/hosts?

aamir picture aamir · Dec 7, 2013 · Viewed 130.9k times · Source

I recently wanted to point all subdomains for a test domain, let's say example.com to the localhost. Is there a way to point all requests on *.example.com to resolve to 127.0.0.1

Answer

aamir picture aamir · Dec 7, 2013

It happens that /etc/hosts file doesn't support wild card entries.

You'll have to use other services like dnsmasq. To enable it in dnsmasq, just edit dnsmasq.conf and add the following line:

address=/example.com/127.0.0.1