Skip to main content
Home
Dave Lane

Main navigation

  • Abilities
  • Blog
  • CV
  • About
    • About
    • This Site
    • Commercial Terms
  • Contact
User account menu
  • Log in

Breadcrumb

  1. Home

2 Step Howto to set up a local wildcard domain resolution on Ubuntu/Linux Mint

Profile picture for user dave
By dave , 5 November 2015

So today it occurred to me as I was doing web development on several different Vagrant instances simultaneously on my work laptop, that it'd be very convenient to have a single wildcard domain on my local machine that, for example, resolved all domains of the form "*.localhost" (note, the domain "*.local" is normally associated with "zeroconf" sites, and so it can lead to weird errors if you use it) to the localhost IP, 127.0.0.1. Normally, one would have to manually create a separate entry in /etc/hosts, like

127.0.0.1 somedevdomain.localhost someotherdomain.localhost

Having to do that is annoying. Although it'd be easy to type, something like

127.0.0.1 *.localhost

doesn't work. Thankfully, it turns out that it's quite easy to do something almost as easy on a modern Ubuntu-based Linux distro (I have Linux Mint 17.2, based on Ubuntu 14.04 - this might work on earlier distros and on Debian, but I haven't tested it - feel free to let me know)...

Modern Ubuntu-based Linux distros use the very convenient NetworkManager app to manage all network connectivity on desktop machines. I didn't realise this, but it integrates the very useful open source DNSMasq application (I use it on my DD-WRT equipped router to provide local DNS resolution on my home network, so that locally hosted services resolve to internal IPs on the local LAN when I'm home, but resolve to the external static IP when I'm outside the home network) which, it turns out, provides a trivial way to achieve wildcard local DNS resolution. Here it is in two steps (replace my domain with your own preferred domain name):

  1. Create the following file using your preferred editor (I used vim, some might use emacs, nano, or something else - the sudo will trigger you to enter you password so you can edit the file owned by the root user):
    sudo vim /etc/NetworkManager/dnsmasq.d/dnsmasq-localhost.conf

    with the following line:
    address=/localhost/.localhost/127.0.0.1
    

    save the file and exit.
  2. Then restart the NetworkManager:
    sudo service network-manager restart

At that point, your new configuration should be in place and active. You can test it by typing, at the commandline:

 

dig local

 

or you can try:

 

dig randomsubdomain.localhost

 

both should return this:

; <<>> DiG 9.9.5-3ubuntu0.5-Ubuntu <<>> local
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 41430
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;localhost.    IN A
;; ANSWER SECTION:
localhost.   0 IN A 127.0.0.1
;; Query time: 1 msec
;; SERVER: 127.0.1.1#53(127.0.1.1)
;; WHEN: Thu Nov 05 11:16:59 NZDT 2015
;; MSG SIZE  rcvd: 39

You might need to install dnsutils if your system complains you don't have dig installed:

sudo apt-get install dnsutils

The content of this field is kept private and will not be shown publicly.
About text formats

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
CAPTCHA
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Note to commenters: due to problems with spam comments, your comment will only appear on this site after it's been deemed (by me) to be legitimate.

Blog posts

Why is mainstream social media so damn 'user friendly'?
4 Aug 2025 - 11:54
Just a thought: Fediverse is different
4 Aug 2025 - 11:53
Windows broken by design
4 Aug 2025 - 11:53
Computer Operating System Analogy
1 Aug 2025 - 15:41
Online voting continues to be a very bad idea in 2025 and beyond
14 Jan 2025 - 17:14
Societal response to acute isolated harm vs. harm that's widespread but less intense
13 Dec 2024 - 14:27
Enough is enough!
13 Dec 2024 - 13:27

Pagination

  • 1
  • Next page
More posts...
RSS feed

Creative Commons License - CC By attribution, Share alike - International 4.0

Contact Dave!
Download Dave's CV
Eliminate DRM!

Contact Modes

Social Media

Software

Terms of Engagement
Terms of Reference
Powered by Drupal