In my /etc/hosts/ file on Linux/OSX, how do I do a wildcard subdomain?

Solution 1:

Install dnsmasq (I do this on all my Linux desktops as a DNS cache anyways). In dnsmasq.conf add the line:

address=/localhost.com/127.0.0.1

Solution 2:

It is not possible to specify wildcards in the /etc/hosts file. Either specify the required hostnames explicitly or alternatively set up a local name server with the appropriate rules.


Solution 3:

I have written a dns proxy in Python. It will read wildcard entries in /etc/hosts. See here: https://github.com/hubdotcom/marlon-tools/blob/master/tools/dnsproxy/dnsproxy.py


Solution 4:

You need to set up a DNS server and have each client use it for resolution. The server itself can be something as "light" as dnsmasq or as heavy as BIND.


Solution 5:

Simple Workflow (no need to install anything)

I personally like to create a PAC file for that and make my browser just use it.

Step 1: create a file e.g.: *.proxy.pac* somewhere (I use my $home folder)

Step 2: paste this code (example is with port 8000):

function FindProxyForURL(url, host) {
  if (shExpMatch(host, "*localhost")) {
    return "PROXY localhost:8000";
  }
  return "DIRECT";
}

Step 3: Make your Browser use this PAC file.

Youtube Video for PAC & Firefox

Step 4: Now you can test your app by accessing: http://mysubdomain.localhost/

Step 5: Enjoy :)