Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.ADDRESS:           192.168.1.110
IP4-SETTINGS.PREFIX:            24 (255.255.255.0)
IP4-SETTINGS.GATEWAY:           192.168.1.1
IP4-DNS1.DNS:                   192.168.1.8
IP4-DNS2.DNS:                   192.168.1.5
IP4-DNS3.DNS:                   24.92.226.11

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:
    Address:         192.168.1.110
    Prefix:          24 (255.255.255.0)
    Gateway:         192.168.1.1

    DNS:             192.168.1.8
    DNS:             192.168.1.5
    DNS:             24.92.226.11
share|improve this answer
    
And what if I do not use NetworkManager? –  Piotr Dobrogost Feb 12 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 at 22:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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