Skip to content

Dnsmasq

dnsmasq는 1000 클라이언트 이하의 로컬 네트워크에서 활용하 수 있는 간단한 DHCP/DNS 서버입니다. 핵심 특징으로는 쉬운 설정과 소규모 시스템을 꼽을 수 있습니다. 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

참고로 기존 /etc/resolv.conf, 즉 /run/systemd/resolve/stub-resolv.conf 파일의 내용은:

# 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

/etc/hosts 파일로 도메인 서버 운영

/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

클라이언트에 네임서버 등록:

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

systemd-resolved vs dnsmasq

Systemd-resolved#systemd-resolved vs dnsmasq 항목 참조.

systemd-resolved 와의 충돌 해결 방법

/etc/systemd/resolved.conf파일의 [Resolve] 섹션에 DNSStubListener=no 설정을 적용하면 된다.

아래와 같다:

[Resolve]
DNSStubListener=no

See also

Favorits site