I want to know which DNS servers are in effect when I run commands like nslookup, dig, host, ping, etc.

The general answer is to cat /etc/resolv.conf, or to look at NetworkManager, but that's only going to show me the list of servers that I normally use. It won't show me any DNS servers that got pushed to me when I connect to a VPN.

Is there a way to get an in-order list of DNS servers that commands like nslookup, dig, host, ping, etc will attempt to use?


If you're using NetworkManager you can use the command line tool that's part of it, nmcli to get this list:

$ nmcli dev list iface wlan0 | grep IP4
IP4-SETTINGS.PREFIX:            24 (

You have to change the bit, wlan0 to whatever is your network interface. You can make it a bit more dynamic by using the iwgetid command:

$ nmcli dev list iface $(iwgetid | awk '{print $1}') | grep IP4

You can also use nm-tool to get a full report:

$ nm-tool 
  IPv4 Settings:
    Prefix:          24 (

  • And what if I do not use NetworkManager? – Piotr Dobrogost Feb 12 '14 at 22:29
  • @PiotrDobrogost - ask your Q on the main site. This Q specifically dealt with NetworkManager. Notice it was tagged as such by the OP? – slm Feb 12 '14 at 22:32
  • When I try to use nmcli on the tunneling interface "tun0" setup by my vpn, I get "Error: Device 'tun0' not found." – lreeder Dec 5 '16 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.