是否有一个命令可以列出我的系统所使用的dns服务器?
我试过
$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 127.0.0.1
$ cat /etc/network/interfaces
# interfaces(5) file used by ifup(8) and ifdown(8)
auto lo
iface lo inet loopback
但它没有列出任何服务器,如果我进入"网络管理器GUI工具",在无线部分,它列出了"DNS 192.168.1.1 8.8.8 8.8.4.4"。
我可以从命令行获得同样的信息吗?
我使用的是Ubuntu 12.04 LTS
resolv.conf已经不怎么用了,除非你自己实现它。 现在由网络管理员来做。 我创建了一个别名来列出我系统中的DNS服务器,因为我有时会从OpenDNS切换到谷歌的开放DNS。
Ubuntu >=15
nmcli device show <interfacename> | grep IP4.DNS
Ubuntu <=14
nmcli dev list iface <interfacename> | grep IP4
在我的例子中,<interfacename>
是eth0
,这很常见,但并不总是如此。
看看这是否是你想要的。
编辑。
我认为 resolv.conf 实际上是间接使用的,因为网络管理员创建了监听 127.0.0.1 的服务器,但有人告诉我这是一个实施细节,不应该被指望。 我认为,如果你在这个条目之前输入DNS地址,它们可能会被使用,但我不确定这到底是如何运作的。 我认为在大多数情况下,如果可能的话,最好使用网络管理器。
这对Ubuntu 13.10和更早的版本有效。对于Ubuntu 14.04及以上版本,请参阅Koala Yeung'的回答。如何知道我在14.04以上的Ubuntu中使用的是什么DNS 。
使用
nm-tool
你会得到一个类似于以下的输出
NetworkManager Tool
State: connected (global)
- Device: eth0 [Wired connection 1] -------------------------------------------
Type: Wired
Driver: e1000e
State: connected
Default: yes
HW Address: 00:11:22:33:44:55
Capabilities:
Carrier Detect: yes
Speed: 1000 Mb/s
Wired Properties
Carrier: on
IPv4 Settings:
Address: 10.21.6.13
Prefix: 24 (255.255.255.0)
Gateway: 10.21.6.1
DNS: 10.22.5.133
DNS: 10.22.5.3
或者只看DNS,请做
nm-tool | grep DNS