I often develop sites/web applications that provide some common or core functionality at a top level domain and use sub-domains for hosting portals, micro-sites or related apps. While developing these apps on my local machine I might have a dozen or so portals running under sub-domains of a top level local domain. It’s possible to add an entry to the hosts file, one for the top domain and one for each sub-domain, but the number of sub-domains may quickly grow big enough to render this method way too cumbersome.
To get around this hurdle, I run a lightweight DNS server locally, that has support for wildcard sub-domains. It’s called dnsmasq and is available as a standard package on most Linux systems. It installs as a system service, and is configured through the file /etc/dnsmasq.conf (on most rpm-based systems).
Below is a quick round-up of the bare minimum settings you need to enable and configure in order to get up and running:
# Never forward plain names (without a dot or domain part)
# Never forward addresses in the non-routed address spaces.
# This option only affects forwarding, SRV records originating for
# dnsmasq (via srv-host= lines) are not suppressed by it.
# Add domains which you want to force to an IP address here.
# The example below send any host in double-click.net to a local
# The IP address to listen on
Restart dnsmasq after these changes and run something like:
$ ping xyz.localhost
to ensure your settings are correct.