Skip to content

Instantly share code, notes, and snippets.

@jakemalley
Created May 17, 2020 22:27
Show Gist options
  • Save jakemalley/763b98d6d39dcc193a09705b51146423 to your computer and use it in GitHub Desktop.
Save jakemalley/763b98d6d39dcc193a09705b51146423 to your computer and use it in GitHub Desktop.
Configure a local DNS server for local development work on Linux with NetworkManager and dnsmasq.

Local DNS Server Instuctions

Configure a local DNS server for local development work on Linux with NetworkManager and dnsmasq.

  1. Check if the systemd-resolved stub listener is running:

    If the output of:

    netstat -tulpn | grep "LISTEN"
    

    shows systemd-resolved listening on 127.0.0.53:53, then edit /etc/systemd/resolved.conf and set the following option:

    DNSStubListener=no
    

    Restart systemd-resolved with:

    systemctl restart systemd-resolved.service
    
  2. On Ubuntu / Fedora dnsmasq is pre-installed with NetworkManager, we just need to enable it by creating a file /etc/NetworkManager/conf.d/10-dnsmasq.conf with the contents:

    [main]
    dns=dnsmasq
    
  3. Configure dnsmasq to listen on the correct address by adding /etc/NetworkManager/dnsmasq.d/10-dnsmasq.conf with the contents:

    listen-address=127.0.0.53
    
  4. Add domains to dnsmasq by creating files in /etc/NetworkManager/dnsmasq.d/, for example:

    Create the a file /etc/NetworkManager/dnsmasq.d/20-lh.conf with the following:

    address=/lh/127.0.0.1
    
  5. Restart NetworkManager and verify:

    systemctl restart NetworkManager
    
    # Should show dnsmasq listening on 127.0.0.53:53
    netstat -tulpn | grep "LISTEN" 
    
    # Should show a dnsmasq process
    ps aux | grep dns
    

    You should be able to resolve *.lh e.g.:

    dig +short test.lh
    127.0.0.1
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment