Skip to content

Install and Configure Dnsmasq on Ubuntu

systemd-resolved uses port 53, so ...

Bash
sudo systemctl disable systemd-resolved
Bash
sudo systemctl stop systemd-resolved
Bash
sudo unlink /etc/resolv.conf
Bash
echo nameserver 1.1.1.1 | sudo tee /etc/resolv.conf
Bash
sudo apt update
sudo apt install dnsmasq
Bash
sudo nano /etc/dnsmasq.conf

add

Text Only
# Listen on this specific port instead of the standard DNS port
# (53). Setting this to zero completely disables DNS function,
# leaving only DHCP and/or TFTP.
port=53
# Never forward plain names (without a dot or domain part)
domain-needed
# Never forward addresses in the non-routed address spaces.
bogus-priv
# By  default,  dnsmasq  will  send queries to any of the upstream
# servers it knows about and tries to favour servers to are  known
# to  be  up.  Uncommenting this forces dnsmasq to try each query
# with  each  server  strictly  in  the  order  they   appear   in
# /etc/resolv.conf
strict-order
# Set this (and domain: see below) if you want to have a domain
# automatically added to simple names in a hosts-file.
expand-hosts
# Set the domain for dnsmasq. this is optional, but if it is set, it
# does the following things.
# 1) Allows DHCP hosts to have fully qualified domain names, as long
#     as the domain part matches this setting.
# 2) Sets the "domain" DHCP option thereby potentially setting the
#    domain of all systems configured by DHCP
# 3) Provides the domain part for "expand-hosts"
#domain=thekelleys.org.uk
domain=example.com

# Set Listen address
listen-address=127.0.0.1 # Set to Server IP for network responses

Optional

Bash
sudo dnssec

Restart dnsmasq

Bash
sudo systemctl restart dnsmasq
Bash
sudo nano /etc/hosts

add

Text Only
1x.x.x.x some.domain.com
10.1x.x.x api.domain.com 
192.168.11.21 lol.domain.com 
Back to top