Skip to content
Search

Dnsmasq

lastmod 2024-06-05created 2021-01-2213 edits

dnsmasq is a simple DHCP/DNS server that can be used on local networks with fewer than 1000 clients. Its key features are easy configuration and a small footprint. It also supports IPv6.

Install

Ubuntu 20.04

sudo -s
systemctl disable systemd-resolved
systemctl stop systemd-resolved
systemctl daemon-reload

ls -lh /etc/resolv.conf  ## lrwxrwxrwx 1 root root 39 Oct 16  2023 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf
unlink /etc/resolv.conf

echo "nameserver 8.8.8.8" > /etc/resolv.conf
apt update
apt install dnsmasq

netstat -n -u -p -a

vi /etc/hosts
vi /etc/dnsmasq.conf
systemctl restart dnsmasq
systemctl status dnsmasq

For reference, the contents of the original /etc/resolv.conf, i.e. the /run/systemd/resolve/stub-resolv.conf file:

# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.

nameserver 127.0.0.53
options edns0 trust-ad
search vcn03281442.oraclevcn.com

Running a domain server with the /etc/hosts file

/etc/dnsmasq.conf file:

listen-address=192.168.100.1  # Bind Address
expand-hosts  # hosts 파일로 도메인 운영

DNS Server - Docker build

/etc/dnsmasq.conf file:

# dnsmasq configuration file
no-resolv
server=8.8.8.8  # Upstream DNS server
addn-hosts=/etc/hosts.dnsmasq

/etc/hosts.dnsmasq file:

192.168.1.10   myserver.local
192.168.1.11   printer.local

Dockerfile ilfe:

FROM alpine:latest

RUN apk --no-cache add dnsmasq

COPY dnsmasq.conf /etc/dnsmasq.conf
COPY hosts.dnsmasq /etc/hosts.dnsmasq

EXPOSE 53/tcp 53/udp

CMD ["dnsmasq", "--no-daemon"]

Build:

docker build -t custom-dnsmasq .

Run command:

docker run -d \
  --name dnsmasq \
  -p 53:53/tcp -p 53:53/udp \
  -v /path/to/dnsmasq.conf:/etc/dnsmasq.conf \
  -v /path/to/hosts.dnsmasq:/etc/hosts.dnsmasq \
  andyshinn/dnsmasq

Register the nameserver on the client:

echo "nameserver 192.168.1.5" | sudo tee /etc/resolv.conf

systemd-resolved vs dnsmasq

See Systemd-resolved#systemd-resolved vs dnsmasq.

Resolving conflicts with systemd-resolved

Apply the DNSStubListener=no setting in the [Resolve] section of the /etc/systemd/resolved.conf file.

As follows:

[Resolve]
DNSStubListener=no

See also

Favorits site

author Zer0 sitemap