How can I tell which DNS servers DNSMasq is using to resolve a name to an IP address? I can't figure it out. All of the existing questions here seem to just go as far as telling users that they are using DNSMasq.

  • Add this to your config: log-facility=/var/log/mydnsmasq.log and then run a nslookup on your domain and tail the log file, you will see which server was used.
    – Shayan
    Oct 11, 2021 at 14:37

7 Answers 7


For a more generic answer when you are using dnsmasq without network manager and with several upstream DNS :

sh# kill -USR1 <PID OF DNSMASQ>
sh# tail /var/log/syslog

Upon receiving SIGUSR1, dnsmasq will log various statistics, including the number of DNS request send to each upstream server. Based on that, you can easily determine the most frequently used DNS server on your system.

  • 4
    Also, when any changes are made to the connection (e.g. connecting to VPN), dnsmasq logs these to /var/log/syslog: dnsmasq[xxx]: setting upstream servers from DBus dnsmasq[xxx]: using nameserver 10.xx.xx.xx#53(via tun0) dnsmasq[xxx]: using nameserver 192.xx.xx.x#53(via wlp2s0) Aug 28, 2017 at 23:45
  • This is a better answer because it tells you which servers were actually used as opposed to just which servers are configured to be used. Sep 12, 2017 at 16:20
  • Thanks, your answer gave me a hint to look into the logs, I used sudo journalctl -b -u dnsmasq | grep nameserver.
    – selurvedu
    Jan 12, 2018 at 21:21

You can find the DNS servers with the NetworkManagerCLI (nmcli) tool:

nmcli dev show | grep DNS
IP6.DNS[1]:                             2a01:4f0:400c:1::1

Ubuntu 14.04 and older

The command is slightly different in older (<15.04) versions of Ubuntu:

> nmcli dev list | grep DNS
IP6.DNS[1]:                             2a01:4f0:400c:1::1
  • Don't you mean nmcli dev show?
    – einpoklum
    Jan 29, 2016 at 17:34
  • @einpoklum: No. On my 14.04 box, nmcli dev show gives: Error: 'dev' command 'show' is not valid. Jan 29, 2016 at 18:42
  • On my Lubuntu 15.10 I get the opposite.
    – einpoklum
    Jan 29, 2016 at 18:42
  • Note that this answer assumes that dnsmasq is managed by NetworkManager. You can verify this in pstree: the dnsmasq process should be a child of NetworkManager. This is the case at least on Ubuntu 16.04 Desktop, but I'm not certain about older or newer versions, or the Server edition.
    – Thomas
    Feb 18, 2021 at 8:26

Generally, for the system using systemd, the DNS servers dnsmasq is using can be found via

journalctl -u dnsmasq

  • 2
    This does not work when dnsmasq is launched by NetwokrManager (and configuration is passed via dbus) Sep 27, 2018 at 5:17

It's also possible to ask NetworkManager by DBus directly. (This is what nmcli does under the hood). For example, on Ubuntu 14.04 or later, run (without the leading $):

$ env -i gdbus introspect -y -o /org/freedesktop/NetworkManager/IP4Config -d org.freedesktop.NetworkManager | perl -ne 'if (m@^  node (\d+) [{]$@) { $_ = readpipe("env -i gdbus introspect -y -o /org/freedesktop/NetworkManager/IP4Config/$1 -d org.freedesktop.NetworkManager\n"); while (m@ Nameservers = \[(?!\])((?=\d)[\d, ]*\d)\]@g) { for (split(m@, *@, $1)) { print join(".", unpack("C4", pack("I", $_))), "\n" } } }'

For a more indirect approach, use ActiveConnection instead of IP4Config.


In package:

network-manager amd64 

The command is:

root@D-MIS-001:~# nmcli dev show | grep DNS

This is what seems to be the current package version for Ubuntu 14.04 LTS. The correct command for 15.* may have changed.

  • You probably mean show instead of list, since list is not a valid command Dec 13, 2021 at 9:40

On Ubuntu 15.04 the command is:

$ nmcli dev show | grep DNS

I'm expanding the answers given by others, showing sligthly longer commands, which print only the DNS servers.

Ubuntu 14.04 has nmcli in the network-manager package. The list of DNS servers is within the output of nmcli -f IP4 -t -m tabular dev list. To get only the list of DNS servers, run (without the leading $):

$ env -i nmcli -f IP4 -t -m tabular dev list | perl -ne 'chomp; my @l = split(m@:@, $_); if (@l > 3) { $_ = $l[3]; if (m@^\d+(?=[.])[\d. |]+[.]\d+$@) { for (split(m@ *[|] *@, $_)) { print "$_\n" } } }'

Ubuntu 15.04 or later also has nmcli in the network-manager package, but expects different command-line arguments. The list of DNS servers is within the output of nmcli -f IP4.DNS -t -m tabular dev show. To get only the list of DNS servers, run (without the leading $):

$ env -i nmcli -f IP4.DNS -t -m tabular dev show | perl -ne 'if (m@^\d+(?=[.])[\d. |]+[.]\d+$@) { chomp; for (split(m@ *[|] *@, $_)) { print "$_\n" } }'

Since nmcli connects to NetworkManager via DBus, the command above works for any connections managed by NetworkManager, even for those which don't use dnsmasq. However, not all connections are managed by NetworkManager. The list of DNS servers should be extracted from the file /etc/resolv.conf, and if it contains addresses starting with 127.0., NetworkManager should be consulted. Here is how to extract:

$ perl -ne 'print "$1\n" if m@^\s*nameserver\s+(\S+)\s*$@' /etc/resolv.conf

Please note that (and possibly others) indicates dnsmasq, and indicates systemd-resolved.

If the current active connection is not managed by NetworkManager (and systemd-resolved), then the DNS servers will be enumerated in the file /etc/resolv.conf.

You must log in to answer this question.

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