19

(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?

7 Answers 7

36

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.

8
  • 7
    +1. Didn't know about this utility, however, I run Ubuntu 14.04, and my command is nmcli d list. Other than that, great stuff here!
    – Terrance
    Jun 18, 2015 at 5:29
  • 1
    sed has the -E flag for extended regex, allowing r+ instead of rr*
    – Squidly
    Jun 18, 2015 at 9:55
  • 1
    What version is this answer based on? On my Trusty's nmcli version 0.9.8.8 nmcli dev show throws out big curly error messages.
    – Oli
    Jun 18, 2015 at 12:04
  • 5
    @Oli nmcli dev show belongs to nmcli on 15.04. For some reason the old nmcli was deemed unstable , so . . . now they use nmcli that has same flags as Fedora. Probably that is due to the switch to systemd. And because this answer fits for 15.04 but not 14.04, I am strongly tempted to downvote it Sep 26, 2015 at 18:43
  • 1
    I'd like to echo the above comments, this may be correct for 15.04, but is not correct for 14.04, which is the question.
    – Alex
    Nov 13, 2015 at 4:28
7

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 google.com  

In alternative terminal run:

nslookup google.com 

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 google.com                            
tcpdump: listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes
    eagle.29862 > b.resolvers.Level3.net.domain: [udp sum ok] 64057+ [1au] A? google.com. ar: . OPT UDPsize=4096 (39)
    b.resolvers.Level3.net.domain > eagle.29862: [udp sum ok] 64057 q: A? google.com. 11/0/0 google.com. A 173.194.115.64, google.com. A 173.194.115.65, google.com. A 173.194.115.72, google.com. A 173.194.115.66, google.com. A 173.194.115.69, google.com. A 173.194.115.78, google.com. A 173.194.115.70, google.com. A 173.194.115.71, google.com. A 173.194.115.68, google.com. A 173.194.115.67, google.com. A 173.194.115.73 (204)
    eagle.16429 > b.resolvers.Level3.net.domain: [udp sum ok] 38822+ A? google.com. (28)

As you can see , my laptop,eagle, sends packets to my university's dns , b.resolvers.Level3.net.domain. 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 google.com                         
tcpdump: listening on wlan0, link-type EN10MB (Ethernet), capture size 65535 bytes
    10.10.87.145.56474 > 4.2.2.2.53: [udp sum ok] 15606+ A? google.com. (28)
1
  • Why the "-W 1200"? "tcpdump -n port 53" should work OK. Nov 25, 2022 at 18:00
4

If somebody has the same question as me for Ubuntu 18.04LTS:

List all network devices managed through network-manager:

networkctl list

Show configuration of specific device:

networkctl status eth0

Instead of eth0 you have to enter the name of your network device shown in the list before. If there no DNS-entry, your card has no configured nameserver

3

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

example:

nm-tool | grep DNS
    DNS:             192.168.1.1
    DNS:             192.168.10.1
    DNS:             192.168.11.1
1

It is still available by default on version 14.04 as it is bundled with network-manager. It has since been dropped from network-manager (version 15.04 and later) and is not even available through apt-get.

For now, on version 15.04, you can download and extract nm-tool from the old package manually. Run the following commands.

First, create a temp directory to work in:

cd
mkdir APTGET;cd APTGET

Then, download the old version and extract the files:

wget 'http://us.archive.ubuntu.com/ubuntu/pool/main/n/network-manager/network-manager_0.9.8.8-0ubuntu7.1_amd64.deb'
ar xvf *
tar xvf dat*

Make a new directory:

mkdir ~/bin

(if it says file already exists, just ignore the message and proceed).

Copy the file to the new directory:

cp ./usr/bin/nm-tool ~/bin

Return to the home directory and delete the temp directory:

cd ..
rm -R APTGET

Now, set an alias for nm-tool:

cp ~/.bashrc ~/.bashback
echo 'alias nm-tool="~/bin/nm-tool"' | tee -a ~/.bashrc;. ~/.bashrc

The current user should now be able to run nm-tool from the terminal.


Additionally, this may still not accurately provide all the actual DNS resolvers you are using.

You can go to DNSleaktest.com to get a full report. Click on Extended Test to get a full report.

1

Actually, NetworkManager does use /etc/resolv.conf. However, on default settings the DNS server listed in resolv.conf is 127.0.0.1, because NetworkManager uses its own internal DNS service for some obscure technical reasons which are not relevant for many people. This is why you have to use nmcli to see what DNS servers NetworkManager is using internally.

However, it is also possible to disable this behaviour and go back to the old one where the actual DNS server in use is listed in resolv.conf. To do this, simply comment out the line dns=dnsmasq in /etc/NetworkManager/NetworkManager.conf, and reboot. For most people, this should make no difference beyond the fact that the actual DNS server will now be shown in resolv.conf. If you are among the corner cases for which the change was introduced, this should become apparent quickly, and you can revert to the default behaviour by uncommenting the line again.

1

nmcli dev list | grep DNS

it will output something like;
IP4.DNS[1]: 8.8.8.8 IP4.DNS[1]: 8.8.8.8 IP4.DNS[2]: 8.8.4.4

The above command works prior to Ubuntu 16.04
For Ubuntu 16.04 use:
nmcli dev show | grep DNS

2
  • You probably mean nmcli dev show, not nmcli dev list?
    – holmb
    Nov 25, 2016 at 10:02
  • I did some digging, it appears they changed the CLI between Ubuntu 14.04 and 16.04. Apparently nmcli dev list works in 14.04, but not in 16.04.
    – holmb
    Nov 25, 2016 at 10:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .