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

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


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.

Packet analysis would be an alternative method that works regardless of NetworkManager or other network connection tool that you use. Basic idea is to send a dns query with nslookup and in a second terminal check where the packets go.

For that we'd need to connect to the network for the first time, so that there is nothing cluttering the connections, and run the following command:

sudo tcpdump -vv -i wlan0 -W 1200 | grep  

In alternative terminal run:


Once you get packets listing from the tcpdump , check where do they go from your IP address.

For example,

$ sudo tcpdump -vv -i wlan0 -W 1200 | grep                            
tcpdump: listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes
    eagle.29862 > [udp sum ok] 64057+ [1au] A? ar: . OPT UDPsize=4096 (39) > eagle.29862: [udp sum ok] 64057 q: A? 11/0/0 A, A, A, A, A, A, A, A, A, A, A (204)
    eagle.16429 > [udp sum ok] 38822+ A? (28)

As you can see , my laptop,eagle, sends packets to my university's dns , If you want to see the IP address, you can use the -n flag with tcpdump.

For example:

$ sudo tcpdump -n -vv -i wlan0 -W 1200 | grep                         
tcpdump: listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes > [udp sum ok] 15606+ A? (28)

check your network connections :

ls /etc/NetworkManager/system-connections/

and choose the connection you want to configure.

 sudo cat /etc/NetworkManager/system-connections/Internet | grep dns

Replace "Internet" without your connection name

Use can still use nm-tool:

nm-tool | grep DNS

Install it for U14.04 and later using

sudo apt-get install nm-tool


nm-tool | grep DNS