Ubuntu 18.04服务器 - 如何检查正在使用的DNS IP服务器设置

Nat*_*ith 22 ubuntu-server

使用Ubuntu 18.04服务器LTS.我试图找到一种方法来检查通过DHCP设置时实际使用的DNS IP.resolv.conf现在只指向127.0.0.53./ etc/systemd/network文件夹为空.NSLOOKUP输出也始终引用内部127.0.0.53 IP.似乎所有旧技巧都不起作用.

Ubuntu文档尚未更新,因为它仍然看起来像16.04引用eth0的帮助,ifup和ifdown在18上全部弃用:https: //help.ubuntu.com/lts/serverguide/network-configuration.html

我尝试通过自定义.yaml设置Netplan的静态适配器设置.设置工作正常,但我似乎无法找到我在任何地方设置的DNS IP.我希望它在DHCP和静态设置之间保持一致,但我不知道现在在哪里看.

此时我会选择C库调用或bash CLI方法.有没有人有办法在18.04服务器上检查这个?

Nat*_*ith 32

我发现以下显示我的DNS服务器通过适配器到输出的末尾:

systemd-resolve --status
Run Code Online (Sandbox Code Playgroud)

它包含由Link组织的"DNS服务器"下的列表.我认为这与以前的Ubuntu版本有所不同.它需要一些文本解析工作,但这给了我我想要的东西.

  • 这不能回答你的问题。您的问题不是 dhcp 提供的 dns 服务器 ip 在哪里。您的问题是如何检查正在使用的 DNS 服务器 IP。 (2认同)

wis*_*cky 13

另一种方式是:

cat /run/systemd/resolve/resolv.conf
Run Code Online (Sandbox Code Playgroud)

该文件由systemd-resolved动态生成,但包含实际的DNS服务器而不是127.0.0.53.

实际上,如果你想将make /etc/resolv.conf设为默认值,你只需为它创建符号链接.(/etc/resolv.conf/run/systemd/resolve/stub-resolv.conf默认指向的符号链接):

sudo mv /etc/resolv.conf /etc/resolv.conf.orig
sudo ln -s /run/systemd/resolve/resolv.conf /etc/resolv.conf
Run Code Online (Sandbox Code Playgroud)

样品/run/systemd/resolve/resolv.conf:

# This file is managed by man:systemd-resolved(8). Do not edit.
#
# 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 must 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 10.1.2.3
search host.domain.com
Run Code Online (Sandbox Code Playgroud)

欲了解更多信息:

http://manpages.ubuntu.com/manpages/bionic/man8/systemd-resolved.service.8.html


SeP*_*PeF 6

您还可以使用:

nmcli dev show eth0
Run Code Online (Sandbox Code Playgroud)

用您的网络接口替换 eth0 以查看它是如何配置的。如果您通过 DHCP 获得了 DNS 地址,您应该在这里看到它。