背景
我们需要x99服务器提供dns来解析公司的域名和部署在x99的微服务域名。
由于ubuntu的dns默认是 systemd-resolved 会占用53端口(虽然可以用其他端口部署dns但是客户端调用很麻烦(已踩雷)
禁用 systemd-resolved 服务自带的本地 DNS 存根(Stub)监听器。
修改配置文件改成 DNSStubListener=no
❯ 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=no
#DNSStubListenerExtra=
#ReadEtcHosts=yes
#ResolveUnicastSingleLabel=no
~ ❯
部署dnsmasq
以下的配置文件是直接读取的/etc/resolv.conf文件,并不是我主动改的。
❯ cat /etc/resolv.conf
# This is /run/systemd/resolve/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 directly to
# all known uplink DNS servers. This file lists all configured search domains.
#
# 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 114.114.114.114
nameserver 202.96.128.86
search .
~ ❯
验证
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