Skip to main content

Resolve all local domains to 127.0.0.1 with dnsmasq

You need DNS to resolve locally ?

  1. Option 1: edit your hosts file

    1. sudo vim /etc/hosts

    2. Add the following: 127.0.0.1 example.dev

  2. Option 2: Alternatively, I recommend running dnsmasq and configuring all .dev extensions to resolve to 127.0.0.1. Note that using the .local extension results in lots of problems and kills baby kittens, don’t use it.

    1. First, Ubuntu 12.04 has dnsmasq installed and enabled by default. Config file, y u no work? This needs to be disabled so we can install a version of dnsmasq that allows configuration.

      1. sudo vim /etc/NetworkManager/NetworkManager.conf

      2. Comment out dns=dnsmasq

      3. sudo restart network-manager

    2. Now, install dnsmasq

      1. sudo apt-get install dnsmasq

      2. sudo vim /etc/dnsmasq.conf

      3. Around line 60 ... set *.dev=127.0.0.1
        # 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
        # web-server.
        #address=/double-click.net/127.0.0.1
        address=/.dev/127.0.0.1

      4. Around line 90 put listen-address=127.0.0.1
        # Or which to listen on by address (remember to include 127.0.0.1 if
        # you use this.)
        #listen-address=
        listen-address=127.0.0.1

      5. sudo /etc/init.d/dnsmasq restart

    3. Test to make sure any subdomain of .dev resolves to local

      1. dig example.dev

      2. nslookup example.dev