Community-driven coverage of elementary OS — news, guides & forums
Dark abstract low-poly geometric landscape with layered triangular facets in deep navy, charcoal, and muted teal, illuminated by a soft electric-blue glow near the horizon

News roundups, tutorials, application guides, and forums — built by users, for users of the elegant Linux distribution.

elementary weekly
#20
Latest roundup · 18 Apr 2015
Freya Release
Final
Covered in weekly #19 & #20
Forum Topics
Active
Installation, customization & more

How to set up a local DNS cache with Dnsmasq on elementary OS

Dnsmasq can turn an elementary OS computer into a compact caching resolver for the network you use every day. It answers repeated DNS lookups from its own cache, forwards uncached queries to an upstream resolver, and can return common local hostnames from /etc/hosts. The result is usually quicker application startup and less repeated traffic to an internet DNS service. It does not cache web pages, and it does not encrypt DNS traffic on its own. Learn more about Androidgyani.com.

Modern elementary OS releases generally use NetworkManager for connections and systemd-resolved to provide the local stub resolver at 127.0.0.53. Dnsmasq can sit behind resolved, serve resolved, or handle DNS directly; each arrangement has different failure points. This walkthrough keeps resolved as a compatibility layer while making Dnsmasq the caching forwarder. That approach suits Australian NBN connections from providers such as Telstra, Optus, Aussie Broadband and iiNet, whose supplied routers vary in caching controls and transparency.

Before changing anything, record the active interface, current nameservers and whether you are connected remotely. A local cache is useful for repeat lookups, including .com.au and .au sites that may resolve to different delivery endpoints depending on the resolver. It is not a substitute for an ISP filter, parental control or VPN, and public Wi-Fi in places such as Brisbane CBD or Melbourne Airport can still require a captive portal. The aim is therefore a small, testable DNS improvement rather than a wholesale network redesign.

How the local resolver works

A resolver translates a name such as www.example.com into an IP address. With the arrangement in this guide, an application asks systemd-resolved, resolved asks the Dnsmasq instance on 127.0.0.1, and Dnsmasq checks its cache. A miss travels to the configured upstream resolver; the returned record and its time-to-live are then stored locally until that TTL expires. A second request can be answered without another upstream lookup.

Negative answers can be cached too, which stops repeated requests for a misspelled domain from consuming unnecessary traffic. TTLs still matter: a short TTL follows changing records more closely, while a long TTL reduces lookups but can preserve an outdated address after a service moves. Dnsmasq can impose sensible minimum and maximum TTL values without pretending that every site behaves the same.

Keep the first rollout on the elementary OS machine itself. A resolver does not automatically improve phones, printers or other clients, and enabling DHCP in Dnsmasq could conflict with the NBN router’s own DHCP service. This guide deliberately covers DNS only. It also avoids replacing /etc/resolv.conf, a change that can leave a remotely administered system unreachable if it is done incorrectly.

Check the existing DNS path

Run resolvectl status to see the active interfaces, DNS servers and current stub configuration. Then use resolvectl dns, nmcli -f GENERAL.DEVICE,IP4.DNS,IP6.DNS device show and cat /etc/resolv.conf to compare what NetworkManager, resolved and the shell are using. systemctl is-active systemd-resolved confirms whether the stub resolver is running.

Write down the upstream addresses already supplied by your ISP. They may provide Australian CDN routing that is more appropriate for local services than a distant public resolver. If Android phones share the connection, Android device advice can help with the separate Private DNS settings; Android may bypass the Linux resolver, so not every device lookup is guaranteed to pass through Dnsmasq.

Check for listeners before binding port 53 with sudo ss -lntup 'sport = :53'. A working desktop commonly shows resolved listening on 127.0.0.53. If you are using SSH, keep that session open, make a small change and verify it before reconnecting. A quick sanity check before reconnecting avoids losing access to the machine.

Install Dnsmasq and define forwarding

Install the binary with sudo apt update && sudo apt install dnsmasq-base. The base package is a deliberate choice here: it provides Dnsmasq without letting a distribution service silently take over resolver configuration. We will validate a local configuration and run it under a clearly named systemd unit.

Choose upstream servers before editing the file. Addresses reported by resolvectl dns are a practical starting point for an Australian NBN service and may offer locally useful CDN answers. Public resolvers such as 1.1.1.1 or 9.9.9.9 can be fallbacks, but understand that your upstream still receives uncached domain names and sees your IP address. A local cache improves speed and repeat-request handling; it does not make the whole journey private.

Create /etc/dnsmasq.conf as root and use explicit public or ISP addresses in place of the examples. The configuration below stays on the loopback interface and does not start DHCP.

port=53
listen-address=127.0.0.1
bind-interfaces
no-resolv
server=1.1.1.1
server=9.9.9.9
cache-size=1000
min-cache-ttl=60
max-cache-ttl=3600
local-ttl=300
expand-hosts
domain-needed
bogus-priv
user=nobody
group=nogroup
strict-order
log-facility=-

Replace both example server lines with the chosen resolvers, or add a provider resolver ahead of a fallback. expand-hosts lets names in /etc/hosts resolve locally, while domain-needed and bogus-priv suppress unnecessary forwarding of local or private addresses. Check the file with sudo dnsmasq --test --conf-file=/etc/dnsmasq.conf before starting anything.

Connect the service to elementary OS

Create a dedicated service at /etc/systemd/system/dnsmasq-local.service so the setup is obvious in logs and easy to reverse. A minimal unit can run the foreground process, while systemd handles startup and restarts after a failure.

[Unit]
Description=Local DNS cache with Dnsmasq
After=network-online.target
Wants=network-online.target

[Service]
Type=simple
ExecStart=/usr/sbin/dnsmasq --no-daemon --conf-file=/etc/dnsmasq.conf
Restart=on-failure
RestartSec=2

[Install]
WantedBy=multi-user.target

After checking the configuration, run sudo systemctl daemon-reload and sudo systemctl enable --now dnsmasq-local. Keep systemd-resolved as the client-facing stub, but disable its own cache so repeat lookups reach Dnsmasq. Create /etc/systemd/resolved.conf.d/10-dnsmasq.conf with the following contents, then restart resolved.

[Resolve]
DNS=127.0.0.1
FallbackDNS=
Cache=no

There are three sensible integration paths, and the first is the least disruptive for a normal desktop.

Approach Query path Practical result
Keep resolved in front Application → resolved → Dnsmasq → upstream Preserves desktop integration and is the recommended path
Point applications directly at Dnsmasq Application → Dnsmasq → upstream Avoids resolved caching but needs per-application changes
Replace resolved Application → Dnsmasq → upstream Fewer layers, but resolver and remote-access management become riskier

The selected path preserves /etc/resolv.conf pointing to 127.0.0.53 while ensuring resolved forwards to Dnsmasq on 127.0.0.1. If the active connection is named “Wired connection 1”, apply sudo nmcli connection modify "Wired connection 1" ipv4.dns "127.0.0.1" ipv4.ignore-auto-dns yes ipv6.dns "127.0.0.1" ipv6.ignore-auto-dns yes. Reconnect the link, then confirm with resolvectl status that its DNS server is 127.0.0.1.

Verify that caching is working

Install the small DNS query utility if needed with sudo apt install dnsutils. Start by querying Dnsmasq directly: dig @127.0.0.1 wikipedia.org. Repeat the command within the TTL window. The answer should be identical, while the remaining TTL should fall; that is a practical sign that the second lookup came from the local cache. dig +short @127.0.0.1 wikipedia.org is useful when you only need the address.

Now test the normal system path with resolvectl query wikipedia.org and then repeat it. Because resolved caching is disabled, the request should be forwarded to Dnsmasq. sudo resolvectl statistics shows whether resolved is handling the query, while sudo journalctl -u dnsmasq-local -b --no-pager exposes startup problems without turning on verbose query logging.

Use sudo ss -lntup 'sport = :53' to confirm that resolved owns 127.0.0.53 and Dnsmasq owns 127.0.0.1. Then browse normally and watch for delays in application startup. A cold lookup can still cross the internet, so an occasional slow result is normal; repeated local answers are the expected improvement.

Confirm normal browsing with curl -I https://elementarynow.com and compare it with dig @127.0.0.1 elementarynow.com. If HTTPS fails while the address resolves, investigate proxy settings, certificate time or the upstream path rather than changing cache size blindly.

Troubleshoot and maintain the setup

If port 53 is already occupied, inspect sudo ss -lntup 'sport = :53'. Resolved binding 127.0.0.53 does not clash with Dnsmasq on 127.0.0.1, but a second resolver bound to every interface will. Do not kill an unknown listener; identify the package that owns it and adjust the bind address deliberately.

If names resolve through dig @127.0.0.1 but applications still use an ISP resolver, check resolvectl status for a per-link route, then inspect the NetworkManager connection’s ipv4.ignore-auto-dns and ipv6.ignore-auto-dns values. If the internet works but local hostnames fail, review /etc/hosts, expand-hosts and any domain directives. If nothing resolves, test each upstream directly with dig @1.1.1.1 example.com and then validate the Dnsmasq file again.

Use sudo systemctl restart dnsmasq-local after configuration changes, followed by sudo dnsmasq --test --conf-file=/etc/dnsmasq.conf; restarting before testing can hide a typo until the next boot. Keep query logging off unless it answers a specific diagnostic need, because domain histories can be revealing. If you want to reopen Terminal quickly during maintenance, the site's keyboard shortcut guide shows how to bind a shortcut for launching applications.

Roll out the change carefully

Start on a wired or otherwise stable connection and keep the original resolver details. This matters in Australia because an NBN line may sit behind provider-supplied equipment, while fixed-wireless and mobile hotspots can use different DNS paths. A test on one workstation avoids turning a family or small-office outage into an afternoon of troubleshooting.

Watch memory use as the cache warms. The shown 1,000-entry cache is modest and suits a typical laptop; a shared office resolver may justify more entries, but extra capacity rarely helps a single user. Measure repeat lookup latency, application startup and failed resolutions before changing TTLs. A cache that works well for Melbourne should behave similarly in Perth or Brisbane; DNS geography affects the address returned, not the local mechanism.

Treat the upstream choice as part of the design. For a home user, the ISP resolver may offer familiar Australian content routing and support arrangements. For a business, document which resolver receives queries and how long records are retained, because the Australian Privacy Principles can apply to personal information held in logs even though DNS caches normally contain names and addresses rather than page contents.

Finish the rollout by running sudo systemctl enable --now dnsmasq-local, then issue dig @127.0.0.1 wikipedia.org twice and confirm that the second response has a lower TTL.

Browse the News Archive
Latest Updates

From the elementary weekly series

Low-poly faceted abstract render in dark charcoal and electric blue tones, suggesting a news bulletin or announcement
elementary news

elementary weekly #20

The first week with the final Freya release — community reactions, tips, and early impressions gathered in one roundup.

Abstract low-poly geometric scene in midnight blue and soft cyan, conveying a live broadcast or event atmosphere
elementary news

elementary SPECIAL

A live Hangouts event with the elementary OS founders, held on 11 April 2015, discussing the Freya final release.

Low-poly faceted render in deep navy and muted teal with subtle amber highlights, suggesting a tutorial or guide
Tips and Tricks

Timeshift Guide

How to use Timeshift — the intuitive system restore utility for elementary OS — to recover from configuration mishaps.

Explore

Topics & Resources

Dive into guides, application recommendations, and community discussions covering every aspect of elementary OS.