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.
17 Answers
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/syslogUpon 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.
3You can find the DNS servers with the NetworkManagerCLI (nmcli) tool:
nmcli dev show | grep DNS
IP4.DNS[1]: 172.22.216.251
IP6.DNS[1]: 2a01:4f0:400c:1::1Ubuntu 14.04 and older
The command is slightly different in older (<15.04) versions of Ubuntu:
> nmcli dev list | grep DNS
IP4.DNS[1]: 172.22.216.251
IP6.DNS[1]: 2a01:4f0:400c:1::1 4 Generally, for the system using systemd, the DNS servers dnsmasq is using can be found via
1
journalctl -u dnsmasq
In package:
network-manager 0.9.8.8-0ubuntu7.2 amd64 The command is:
root@D-MIS-001:~# nmcli dev list | grep DNS
IP4.DNS[1]: 172.16.10.173
IP4.DNS[2]: 172.16.10.133This is what seems to be the current package version for Ubuntu 14.04 LTS. The correct command for 15.* may have changed.
1It'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" } } }'
12.34.56.78
90.123.45.6For a more indirect approach, use ActiveConnection instead of IP4Config.
On Ubuntu 15.04 the command is:
$ nmcli dev show | grep DNS
IP4.DNS[1]: 8.8.8.8 I'm expanding the answers given by others, showing sligthly longer commands, which print only the DNS servers.
Ubuntu 14.04 has nmcli 0.9.8.8 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" } } }'
12.34.56.78
90.123.45.6Ubuntu 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" } }'
12.34.56.78
90.123.45.6Since 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
127.0.1.1Please note that 127.0.1.1 (and possibly others) indicates dnsmasq, and 127.0.0.53 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.