Ubuntu – How to know what DNS am I using in Ubuntu from 14.04 onwards

dnsnetwork-managernetworking

(A follow up to similar question for 12.04.)

Prior to Ubuntu 12.04, you may see the active DNS in /etc/resolv.conf. In Ubuntu 12.04, NetworkManager no longer works with the file. You have to directly consult the command line tool nm-tool.

Interestingly, nm-tool is no longer installed by default in 14.04 and later. Although you may still install through apt-get install, you can't assume all Ubuntu to have that out of the box.

So the question remains. How do you know, by default installation, the DNS you're using by command line?

Best Answer

Quick Answer

A new NetworkManager tool nmcli is installed by default now. The command line tool is very powerful but a bit harder to learn. Stick to our question, the short answer is:

nmcli dev show | grep DNS

or, to have cleaner output

nmcli dev show | grep DNS | sed 's/\s\s*/\t/g' | cut -f 2


Explain

If you have time, I can explain the above jumbo-mumble:

  1. nmcli dev show

    Works a bit like the old nm-tool command. It elaborate the current networking info.

    You may also learn the setting of a certain interface by adding the interface name. For example, to learn the information of eth0, you may use nmcli dev show eth0.

  2. grep DNS

    Obviously grep only the lines with the text "DNS" in it.

  3. sed 's/\s\s*/\t/g' | cut -f 2

    This is only to clean up the output. The cut may select the output by column, but it takes only 1 character as separator (while nmcli uses MANY SPACE). The sed turns the spaces, in original output, into TAB.

Related Question