如何查看DHCP分配的DNS地址?

如何查看DHCP分配的DNS地址?

如何查看DHCP分配的DNS地址?

ifconfig 无法显示。

$ ifconfig -a
eth0      Link encap:Ethernet  HWaddr 90:e6:ba:22:6a:f2  
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::92e6:baff:fe22:6af2/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:224856 errors:0 dropped:0 overruns:0 frame:0
          TX packets:220040 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:166848627 (166.8 MB)  TX bytes:20256333 (20.2 MB)
          Interrupt:46 Base address:0x4000 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:5889 errors:0 dropped:0 overruns:0 frame:0
          TX packets:5889 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:468885 (468.8 KB)  TX bytes:468885 (468.8 KB)

wlan0     Link encap:Ethernet  HWaddr 00:26:5e:e8:4f:8e  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

答案1

对于至少 Ubuntu 15.10 及以上版本(也可能是更早版本),在终端中运行:

nmcli dev show eth0 | grep IP4

eth0是最常见的 iface,但也可以是eth1eth2等等。

对于旧版本使用nmcli dev list iface eth0 | grep IP4

答案2

现在 Ubuntu(以及 Debian 和几乎所有发行版)使用systemd(检查file /sbin/init)也许获取此信息的更优雅的方法是:

systemd-resolve --status
# Or 
resolvectl dns

答案3

$ nm-tool 

还将列出 DNS 服务器。

答案4

要获取 DNS 地址,请打开终端(++ Ctrl)并输入:AltT

cat /var/lib/dhcp/dhclient.leases | grep dhcp-server-identifier

相关内容