禁用systemd-resolved
# sudo systemctl disable systemd-resolved
# sudo systemctl stop systemd-resolved
安装依赖
# apt -y install make gcc
下载dnsmasq
# wget https://thekelleys.org.uk/dnsmasq/dnsmasq-2.89.tar.gz
安装dnsmasq
创建dnsmasq用户
# groupadd -r dnsmasq && useradd -M -N -g dnsmasq -d /usr/local/dnsmasq -r -s /bin/false -c "DNSmasq Server" dnsmasq
解压dnsmasq
# tar xf dnsmasq-2.89.tar.gz
# cd dnsmasq-2.89
修改安装路径
# grep PREFIX Makefile
PREFIX = /usr/local/dnsmasq-2.89 # 按需修改
BINDIR = $(PREFIX)/sbin
MANDIR = $(PREFIX)/share/man
LOCALEDIR = $(PREFIX)/share/locale
安装dnsmasq
# make install
make[1]: Entering directory '/root/dnsmasq-2.89/src'
.....
cc -o dnsmasq cache.o rfc1035.o util.o option.o forward.o network.o dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o bpf.o helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o dhcp-common.o outpacket.o radv.o slaac.o auth.o ipset.o pattern.o domain.o dnssec.o blockdata.o tables.o loop.o inotify.o poll.o rrfilter.o edns0.o arp.o crypto.o dump.o ubus.o metrics.o hash-questions.o domain-match.o nftset.o
make[1]: Leaving directory '/root/dnsmasq-2.89/src'
install -d /usr/local/dnsmasq-2.89/sbin
install -d /usr/local/dnsmasq-2.89/share/man/man8
install -m 644 man/dnsmasq.8 /usr/local/dnsmasq-2.89/share/man/man8
install -m 755 src/dnsmasq /usr/local/dnsmasq-2.89/sbin
创建软连接
# ln -svf /usr/local/dnsmasq-2.89/ /usr/local/dnsmasq
'/usr/local/dnsmasq' -> '/usr/local/dnsmasq-2.89/'
复制配置文件
# cp dnsmasq-2.89/dnsmasq.conf.example /usr/local/dnsmasq/dnsmasq.conf
dnsmasq.service
[Unit]
Description=dnsmasq - A lightweight DHCP and caching DNS server
Requires=network.target
Wants=nss-lookup.target
Before=nss-lookup.target
After=network.target
[Service]
Type=forking
PIDFile=/var/run/dnsmasq.pid
ExecStart=/usr/local/dnsmasq/sbin/dnsmasq --conf-file=/usr/local/dnsmasq/dnsmasq.conf
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
dnsmasq.conf
# egrep -v "^$|^#" /usr/local/dnsmasq/dnsmasq.conf
bogus-priv
resolv-file=/usr/local/dnsmasq/resolv.conf
strict-order
user=dnsmasq
group=dnsmasq
addn-hosts=/usr/local/dnsmasq/hosts
准备文件
# cp /etc/resolv.conf /usr/local/dnsmasq/
# touch /usr/local/dnsmasq/hosts
# chown -R dnsmasq.dnsmasq /usr/local/dnsmasq
运行dnsmasq
# systemctl enable dnsmasq
# systemctl start dnsmasq
Apr 14 19:26:50 172-16-18-54 systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: started, version 2.89 cachesize 150
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: compile time options: IPv6 GNU-getopt no-DBus no-UBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ips>
Apr 14 19:26:50 172-16-18-54 systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: reading /usr/local/dnsmasq/resolv.conf
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: using nameserver 10.42.255.1#53
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: using nameserver 10.42.255.2#53
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: using nameserver 114.114.114.114#53
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: read /etc/hosts - 9 names
Apr 14 19:26:50 172-16-18-54 dnsmasq[46942]: read /usr/local/dnsmasq/hosts - 0 names
参考文档
https://thekelleys.org.uk/dnsmasq/doc.html
标签:14,部署,18,ubuntu22.04,2.89,dnsmasq,usr,local From: https://www.cnblogs.com/wangguishe/p/17317977.html