What DNS servers am I using?
- 9 years ago
You should be able to get some reasonable information in:
$ cat /etc/resolv.conf
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.
This file typically points at 127.0.1.1 on Ubuntu - it's the local DNS cache server, not the actual upstream.
And if you have several upstream server configured ? How to know which one is currently used ?
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.
See the answers by @G32RW or @Lonniebiz for a more robust approach under various circumstances, e.g. when you get an answer like `127.0.0.53`
@Geremia router? I'm on office wifi and I want to verify which DNS server I'm using. Or I'm on VPN and want to verify, similarly. Usually I don't have access to the router.