Command-line to list DNS servers used by my system
Is there a command to list dns servers used by my system?
$ 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 220.127.116.11 18.104.22.168"
Can I get same information from command line?
I am using Ubuntu 12.04 LTS
What are you trying to find? the DNS servers being used by your system? or are you trying to do a DNS lookup?
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.DNS
Ubuntu <= 14
nmcli dev list iface <interfacename> | grep IP4
In my case,
eth0, which is common, but not always the case.
See if this is what you want.
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.
thanks, yes that seems to be working, ubuntu networking seems to be confusing, so I can set dns servers in resolve.conf/base or in /etc/network/interfaces or in network manager, is there a definitive guide for ubuntu networking?
If you use the GUI, then the best place to set it is by creating profiles in the Network Connections Dialog. I duplicated the default, then edited the duplicate to make the changes I wanted, keeping the default to make sure I always had a working profile. Then, it's easy to switch profiles. I don't know how to do this without the GUI, but there is a user "James Henstridge" who is very knowledgeable on Ubuntu's networking; you might try searching askubuntu for his information. He told me about the command I gave you in this post.
http://www.stgraber.org/2012/02/24/dns-in-ubuntu-12-04/ is a nice article abount DNS resolution in ubuntu 12.04
Are you using 12.04, the version specified? Did you substitute something like "eth0" for ? (My original post actually made it clearer, but someone changed it, and I added the note below). It still works for me, every day.
This doesn't work for me. With a `vpnc` VPN connected, `nmcli dev list iface eth0` shows the original DNS server, but the VPN's DNS server is not listed, even if I use `tun0` for ``. So it might work some of the time but is not reliable in every case.
It would be great to figure out a way to do this without network-manager, which would be preferable for servers. Actually, as suggested by one of the below answers, it looks like `cat /etc/resolv.conf` does exactly that. I have the DNS servers configured in `/etc/network/interfaces` and they do land in `resolv.conf` as expected.
Seems `nmcli` has changed its syntax. Command `nmcli dev list iface` no longer works. I have written an answer to similar question for Ubuntu 14.04 and later: https://askubuntu.com/questions/637893/how-to-know-what-dns-am-i-using-in-ubuntu-14-04
It still works for me using 14.04. You do need to add the device at the end, of course (ie, eth0, eth1, or whatever device you are using).
By the way, `nmcli dev show` doesn't work for 14.04. That's the version I have, so I can't speak for future versions
@vcardillo: the original question stated: "I am using Ubuntu 12.04 LTS". It's been 5 years since I posted my answer. Nothing lasts forever.
I would like to warn readers that the information provided by nmcli and nm-tool might not be correct. In testing my router setup, I changed the DHCP server to configure a DNS. On my client (linux mint 17.3) I did `sudo dhclient -r; sudo dhclient` to renew IP configuration. At this point both commands I mentioned showed the old DNS, not the new one. `cat /etc/resolv.conf` did work for me, but according to op it did not work for him. The only reliable way to figure out which DNS is used appears to be to a lookup with for example dig, but I doubt dig will show you all configured DNS.
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
You 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.3
Or to see just the DNS do
nm-tool | grep DNS
just wanted to add-up, going to `nm-applet`'s connection information menu will also work :)
Yes, same info, but nmcli is easier to parse if you want to extract it out for a different presentation, such as conky, or simply a summary like my grep.
This doesn't work for me. With a `vpnc` VPN connected, `nm-tool` shows the original DNS server, but the VPN's DNS server is not listed. So it might work some of the time but is not reliable in every case.
this installs a *[email protected]#$load* of packages. Is there a light weight cli tool?
The two top-scoring answers,
nmcli dev list iface <interfacename> | grep IP4and
nm-toolboth 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.
So: First check if 127.0.0.1/localhost is used. This could be done with
> 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: 22.214.171.124
But if 127.0.0.1/localhost is not used, then
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: 126.96.36.199
digis 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
188.8.131.52doesn't know about.
This is because after connecting to a VPN with
vpnc, it puts a line in
/etc/resolv.confso 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 184.108.40.206 nameserver 127.0.0.1 search MyDomain
Thank you. Some of us out here do not use NM and that is good for the community.
cat /etc/resolv.confshould show your DNS servers.
You may not modify the
resolv.confdirectly with Ubuntu 12.04. If you need to change them though, you can add new DNS servers in your
/etc/network/interfacesfile by adding the following:
dns-nameservers x.x.x.x x.x.x.x
xis 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.
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
systemd-resolve --statuswill 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 eth0will give you all that information in an easy-to-read form (assuming you're interested in the
Seems to be managed by network manager. Have a look here http://manpages.ubuntu.com/manpages/precise/man5/NetworkManager.conf.5.html
for a large explanation.
Or the short version it to look in