How can I check which DNS server am I using (in Linux)? I am using network manager and a wired connection to my university's LAN. (I am trying to find out why my domain doesn't get resolved)

11 Answers 11

up vote 154 down vote accepted

You should be able to get some reasonable information in:

$ cat /etc/resolv.conf 
  • 25
    However, please be aware that (on modern Linuxen) the contents of /etc/nsswitch.conf dictate what name services are used (DNS, LDAP, etc) and in what order. Say fgrep hosts: /etc/nsswitch.conf. If it only references DNS, /etc/resolv.conf is the right place to look for your nameservers. But chances are you're also using mDNS (aka ZeroConf, aka Avahi, aka Bonjour, etc), etc. In that case, things depend on what you're using. – Alexios Jan 12 '12 at 13:35
  • 18
    This file typically points at 127.0.1.1 on Ubuntu - it's the local DNS cache server, not the actual upstream. – Barry Kelly Mar 8 '16 at 10:24
  • 2
    @BarryKelly Check what your router uses, then – Geremia Mar 11 '16 at 17:10
  • 1
    And if you have several upstream server configured ? How to know which one is currently used ? – Sylvain Leroux Nov 24 '16 at 23:31
  • 1
    I would suggest to mention that file is a link and dynamically generated for systems using resovconf (like Ubuntu). I've seen this answer millions of times and until today is that I think it is correct, because I understand now that it is actually a dynamically generated file. – jgomo3 Dec 26 '17 at 18:00

Here's how I do it:

nmcli dev show | grep DNS

This worked previous to the way above:

nm-tool | grep DNS
  • 9
    This one is usefull if you are using VPN and NetworkManager. Your /etc/resolv.conf will point to your machine, with dnsmasq resolving names as configured by NetworkManager. – Grzegorz Żur May 30 '13 at 11:32
  • 4
    On Debian this requires the network-manager package. – TranslucentCloud Feb 3 '15 at 19:44
  • 2
    nm-tool is not available in newer linuxes. for example it is not in the 'network-manager' package of debian 8. – don bright Oct 31 '15 at 15:06
  • nm-tool | grep DNS No command 'nm-tool' found, did you mean: Command 'dm-tool' from package 'lightdm' (main) nm-tool: command not found – chovy Aug 31 '16 at 7:22
  • I've updated the answer to reflect what's working for me in 2016. – Lonniebiz Sep 1 '16 at 16:36

I think you can also query DNS and it will show you what server returned the result. Try this:

dig yourserver.somedomain.xyz

And the response should tell you what server(s) returned the result.

You can also tell dig to query a specific DNS server by using dig @server_ip

  • 6
    On Debian this requires the dnsutils package. – Faheem Mitha Jan 14 '12 at 20:54
  • 2
    If you use any DNS masking/caching service that is run on your local machine, it will hide the real DNS servers. – karatedog Sep 7 '15 at 9:12

Just do an, nslookup. Part of its results include the server that it's using.

In the example below, it shows that the DNS server used is at 8.8.8.8.

$ nslookup google.com
Server:     8.8.8.8
Address:    8.8.8.8#53

Non-authoritative answer:
Name:   google.com
Address: 172.217.22.174
  • 1
    can you give an example of what to enter in the prompt? – chovy Jan 14 '16 at 6:41
  • Example: $ nslookup www.google.com – Ren Feb 13 '16 at 23:50
  • 4
    On Debian this requires the dnsutils package. – Gayan Weerakutti Aug 13 '17 at 7:00
  • 2
    On a recent Ubuntu, this again points to the local cache server 127.0.0.1 as already hinted at in this comment – FriendFX Dec 1 '17 at 1:50
  • In CentOS 7 it quits with error, but it is a vm so I did nslookup google.com in the Windows host and I found the nameserver. Add it in /etc/resolv.conf like: nameserver xx.xx.xx.xx and restart service network, and all is fine. Praise you. – WesternGun May 3 at 15:22

With the new network-manager command nmcli, do this:

nmcli --fields ipv4.dns,ipv6.dns con show <connection_name>

On newer versions of network-manager (such as in Ubuntu 16.04), the field names are slightly different:

nmcli --fields ip4.dns,ip6.dns con show <connection_name>

If you don't know the connection name, use:

nmcli -t --fields NAME con show --active

For example:

$ nmcli --fields ip4.dns,ip6.dns con show 'Wired connection 1'
IP4.DNS[1]:                             172.21.0.13
IP4.DNS[2]:                             172.21.0.4
  • My results: order «con» «show» is not valid. – Sopalajo de Arrierez Jan 30 '16 at 22:03
  • It works fine for me with network-manager 1.0.4 on Ubuntu 15.10. Maybe you have an older version? – Sameer Mar 17 '16 at 5:40
  • The tabular format is pretty bad. I hope to get a column like format similar to Powershell. – CMCDragonkai Mar 14 '17 at 6:42
  • 1
    Returns Error: invalid field 'ip4.dns'; allowed fields: NAME,UUID,TYPE,TIMESTAMP,TIMESTAMP-REAL,AUTOCONNECT,AUTOCONNECT-PRIORITY,READONLY,DBUS-PATH,ACTIVE,DEVICE,STATE,ACTIVE-PATH. – FriendFX Dec 1 '17 at 1:53

If you are using network manager probably you get all network parameters from your dhcp server at your university.

If you don't want use your shell to check your dns settings (as described by hesse and Alexios), you can see them from the panel "Network information".

You can reach this panel by pressing right mouse button on network manager icon and selecting "Connection Information" from the menu.

to get the first DNS SERVER (IP only) :

cat /etc/resolv.conf |grep -i '^nameserver'|head -n1|cut -d ' ' -f2
  • cat will output DNS config
  • grep filters only nameserver
  • head will keep only the first row/instance
  • cut take the ip part of the row (second column with ' ' as separator)

To put DNS ip in an environment variable, you could use as follow:

export THEDNSSERVER=$(cat /etc/resolv.conf |grep -i '^nameserver'|head -n1|cut -d ' ' -f2)
  • 1
    grep -m 1 stops matching after first match so you don't have to use head – sshow Jul 28 '17 at 8:30
  • To lighten the pipeline even more, capture groups with Perl regexp is very neat, and grep takes a file argument: grep -Pom 1 '^nameserver \K\S+' /etc/resolv.conf. Just wrote up Capture groups with grep perl regular expression – sshow Jul 28 '17 at 9:04

On systems running systemd use:

systemd-resolve --status
  • 1
    systemd-resolve: unrecognized option '--status' – A-B-B Apr 1 at 18:03
  • @A-B-B system? systemd version? – G32RW Apr 1 at 20:21
  • 229-4ubuntu21.2 – A-B-B Apr 1 at 23:34
  • Says Failed to get global data: Unit dbus-org.freedesktop.resolve1.service not found. – xji Apr 12 at 11:19
  • 1
    This is the new default way to do it in Ubuntu 18.04 Bionic Beaver - get used to it, everybody! – AveryFreeman Apr 24 at 20:32

The command

 nmcli dev list iface <interfacename> | grep IP4

Replace "interfacename" with yours.

examlpe

 nmcli dev list iface eth0 | grep IP4

This will list all DNS servers(If you use more than one).

  • nmcli dev list iface [devicename] is the correct command – sebix May 18 '15 at 17:33
  • I haven't noticed <interface> is hidden since i use <> – Maythux May 19 '15 at 5:53
  • 1
    On debian i get an error--- $ nmcli dev list iface eth0 Error: 'dev' command 'list' is not valid. – don bright Oct 31 '15 at 15:00
  • nmcli is a RH specific command. – Rui F Ribeiro Nov 16 '15 at 7:42
  • This is correct answer! – VAdaihiep Aug 10 at 8:00

I have Fedora 25 and also had similar slow response on command line to sudo commands.

nmcli dev show | grep DNS 

showed that only one of my 3 adapters (two active) had DNS entries. By adding DNS entries to the one active card that didn't have an entry - presto! All is good and response time is immediate.

In CentOS, you can use:

/usr/sbin/named -v

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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