Is there a command to list dns servers used by my system?
I tried
$ 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 loopbackBut it doesn't list any servers, if I go to "Network Manager GUI Tool", in Wireless section it lists "DNS 192.168.1.1 8.8.8.8 8.8.4.4"
Can I get same information from command line?
I am using Ubuntu 12.04 LTS
512 Answers
resolv.conf isn't really used anymore, unless you implement it yourself. The network manager does it now. I created an alias to list the DNS servers on my system, as I sometimes switch from OpenDNS to Google's open DNS.
Ubuntu >= 15
nmcli device show <interfacename> | grep IP4.DNSUbuntu <= 14
nmcli dev list iface <interfacename> | grep IP4In my case, <interfacename> is eth0, which is common, but not always the case.
See if this is what you want.
EDIT:
I think resolv.conf is actually used indirectly, because the network manager creates the server that listens on 127.0.0.1, but I was told that this is an implementation detail that should not be counted on. I think that if you enter DNS addresses before this entry, they might get used, but I'm not sure exactly how this works. I think it's best to use the network manager in most cases, when possible.
18In Ubuntu 18.04 and 20.04 you can use systemd-resolve --status
This is valid for Ubuntu 13.10 and earlier. For Ubuntu 14.04 and above, see Koala Yeung's answer to: How to know what DNS am I using in Ubuntu from 14.04 onwards
Use
nm-toolYou will get an output similar to
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.3Or to see just the DNS do
nm-tool | grep DNS 8 The two top-scoring answers, nmcli dev list iface <interfacename> | grep IP4 and nm-tool both assume that network-manager is in control. Which it is - on desktop machines most of the time at least. But the fuller answer is that sometimes network-manager is not in control. E.g. vpnc messes with /etc/resolv.conf directly.
So: First check if 127.0.0.1/localhost is used. This could be done with dig:
> dig something.unknown | grep SERVER:
;; SERVER: 127.0.0.1#53(127.0.0.1)Now you know that we are using localhost. Go ahead with one of the popular answers. I like:
> nm-tool | grep DNS: DNS: 8.8.8.8But if 127.0.0.1/localhost is not used, then nm-tool's and nmcli's output will be misleading:
> dig something.unknown | grep SERVER:
;; SERVER: 172.22.216.251#53(172.22.216.251)
> nm-tool | grep DNS: DNS: 8.8.8.8Here, dig is correct and nm-tool's information is misleading. In reality addresses local to the environment I've VPN-ed into are resolved correctly. All of which Google's DNS 8.8.8.8 doesn't know about.
This is because after connecting to a VPN with vpnc, it puts a line in /etc/resolv.conf so it looks like:
# 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 1.2.3.4
nameserver 127.0.0.1
search MyDomain 4 cat /etc/resolv.conf should show your DNS servers.
You may not modify the resolv.conf directly with Ubuntu 12.04. If you need to change them though, you can add new DNS servers in your /etc/network/interfaces file by adding the following:
dns-nameservers x.x.x.x x.x.x.xwhere x is the DNS servers you wish to use.
If I were you, I would uninstall network-manager. In my opinion it's a pile of crap.
You can accomplish everything you need to do manually without worrying about changing your settings, especially if you have multiple NICs on the computer.
3nmcli version 0.9.10
You can use either of these commands:
nmcli -t -f IP4.DNS device show eth0
IP4.DNS[1]:192.168.1.1
IP4.DNS[2]:8.8.8.8
nmcli -t -f IP4.DNS connection show conn-name
IP4.DNS[1]:192.168.1.1
IP4.DNS[2]:8.8.8.8 Amazing how many ways there are to do it. On an Ubuntu Server 18.04, if you don't want to install anything extra like nm-tool, then systemd-resolve --status will work out of the box for DNS information.
If you're interested getting not only your DNS servers, but also default gateway, IP address, network mask, etc, then netplan ip leases eth0 will give you all that information in an easy-to-read form (assuming you're interested in the eth0 interface).
In Ubuntu 15.10 you can get DNS
nmcli device show <interface name> On Ubuntu 20.04
systemd-resolve --status | grep -B 9 -A 6 "Current DNS Server"gave me a clear result as to what DNS was in use for each adapter using DNS.
To reconfigure DNS
man systemd-resolvedreveals the DNS servers contacted are determined by global settings in /etc/systemd/resolved.conf.
Sudo edit that file and uncomment and set DNS= and FallbackDNS= to the IPv4 DNS servers you want.
For example, DNS=8.8.8.8 and FallbackDNS=8.8.4.4 would use Google Public DNS.
Restart the machine to apply the change.
@PLA, thank you for this answer which led me down this path.
On systems where systemd-resolved is NOT installed :
$ host -v something.unknown | awk -F "[ #]" '/Received /{print$5}' | uniq
192.168.1.1On systems where NetworkManager is running :
$ ( nmcli -f IP4.DNS,IP6.DNS dev list || nmcli -f IP4.DNS,IP6.DNS dev show ) 2>/dev/null | awk '/DNS/{print$NF}'
192.168.1.1 In Ubuntu 20.04, if your resolve.conf points to loopback:
$ sudo cat /run/systemd/resolve/resolv.conf
nameserver 127.0.0.53
options edns0 trust-adand:
$ ss -plnt | grep ':53'
LISTEN 0 4096 127.0.0.53%lo:53 0.0.0.0:* you can use resolvectl to show status for interfaces:
$ resolvectl status
Global
LLMNR setting: no
MulticastDNS setting: no DNSOverTLS setting: no DNSSEC setting: no DNSSEC supported: no DNSSEC NTA: 10.in-addr.arpa
....
Link 4 (wlo1) Current Scopes: DNS
DefaultRoute setting: yes LLMNR setting: yes
MulticastDNS setting: no DNSOverTLS setting: no DNSSEC setting: no DNSSEC supported: no Current DNS Server: 10.128.128.128 DNS Servers: 10.128.128.128 DNS Domain: ~. Seems to be managed by network manager. Have a look here
for a large explanation.
Or the short version it to look in
/etc/NetworkManager/NetworkManager.confor
<SYSCONFDIR>/NetworkManager/NetworkManager.conf 1