内网组网-2. 私有DNS

1 阅读1分钟

背景

我们需要x99服务器提供dns来解析公司的域名和部署在x99的微服务域名。

禁用 systemd-resolved 服务自带的本地 DNS 存根(Stub)监听器

部署dnsmasq

sudo apt update
sudo apt install -y dnsmasq

修改配置文件 /etc/systemd/resolved.conf

❯ sudo cat /etc/systemd/resolved.conf

❯ sudo cat /etc/systemd/resolved.conf

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it under the
#  terms of the GNU Lesser General Public License as published by the Free
#  Software Foundation; either version 2.1 of the License, or (at your option)
#  any later version.
#
# Entries in this file show the compile time defaults. Local configuration
# should be created by either modifying this file, or by creating "drop-ins" in
# the resolved.conf.d/ subdirectory. The latter is generally recommended.
# Defaults can be restored by simply deleting this file and all drop-ins.
#
# Use 'systemd-analyze cat-config systemd/resolved.conf' to display the full config.
#
# See resolved.conf(5) for details.

[Resolve]
# Some examples of DNS servers which may be used for DNS= and FallbackDNS=:
# Cloudflare: 1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
# Google:     8.8.8.8#dns.google 8.8.4.4#dns.google 2001:4860:4860::8888#dns.google 2001:4860:4860::8844#dns.google
# Quad9:      9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
#DNS=
#FallbackDNS=
#Domains=
#DNSSEC=no
#DNSOverTLS=no
#MulticastDNS=no
#LLMNR=no
#Cache=no-negative
#CacheFromLocalhost=no
#DNSStubListener=yes
#DNSStubListenerExtra=
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no

DNS= 127.0.0.1
FallbackDNS= 114.114.114.114 223.5.5.5
Cache=yes
Domains=cyan.com
DNSStubListener=yes

  ~ ❯  
重启dnsmasq
sudo systemctl restart systemd-resolved
sudo systemctl restart dnsmasq
X99服务器:

 nslookup jenkins-dev.dachensky.com
Server:         114.114.114.114
Address:        114.114.114.114#53

Non-authoritative answer:
Name:   jenkins-dev.dachensky.com
Address: 192.168.4.32

  ~   



个人PC:

> nslookup jenkins-dev.dachensky.com
Server:         10.0.0.2
Address:        10.0.0.2#53

Non-authoritative answer:
Name:   jenkins-dev.dachensky.com
Address: 192.168.4.32


看dns解析地址,如果是你的服务器解析的地址就对了。这里记得在wireguard配置dns

如果10.0.0.2的dns没有注册到system-resolved里

resolvectl dns wg0 10.0.0.2
resolvectl domain wg0 ~.

#查看
resolvectl status