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 loopback
But 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
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
Ubuntu <= 14
In my case,
<interfacename>
iseth0
, 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.
In 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
You will get an output similar to
Or to see just the DNS do
The two top-scoring answers,
nmcli dev list iface <interfacename> | grep IP4
andnm-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
:Now you know that we are using localhost. Go ahead with one of the popular answers. I like:
But if 127.0.0.1/localhost is not used, then
nm-tool
's andnmcli
's output will be misleading:Here,
dig
is correct andnm-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 DNS8.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: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:where
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.
nmcli version 0.9.10
You can use either of these commands:
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
, thensystemd-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 theeth0
interface).In Ubuntu 20.04, if your
resolve.conf
points to loopback:and:
you can use
resolvectl
to show status for interfaces:On Ubuntu 20.04
gave me a clear result as to what DNS was in use for each adapter using DNS.
To reconfigure DNS
reveals the DNS servers contacted are determined by global settings in
/etc/systemd/resolved.conf
.Sudo edit that file and uncomment and set
DNS=
andFallbackDNS=
to the IPv4 DNS servers you want. For example,DNS=8.8.8.8
andFallbackDNS=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.
In Ubuntu 15.10 you can get DNS