The two top-scoring answers, nmcli dev list iface <interfacename> | grep IP4
and nm-tool
both assume that network-manager is in control. Which it is - on desktop machines most of the time at least. But the fuller answer is that sometimes network-manager is not in control. E.g. vpnc
messes with /etc/resolv.conf
directly.
So: First check if 127.0.0.1/localhost is used. This could be done with dig
:
> dig something.unknown | grep SERVER:
;; SERVER: 127.0.0.1#53(127.0.0.1)
Now you know that we are using localhost. Go ahead with one of the popular answers. I like:
> nm-tool | grep DNS:
DNS: 8.8.8.8
But if 127.0.0.1/localhost is not used, then nm-tool
's and nmcli
's output will be misleading:
> dig something.unknown | grep SERVER:
;; SERVER: 172.22.216.251#53(172.22.216.251)
> nm-tool | grep DNS:
DNS: 8.8.8.8
Here, dig
is correct and nm-tool
's information is misleading. In reality addresses local to the environment I've VPN-ed into are resolved correctly. All of which Google's DNS 8.8.8.8
doesn't know about.
This is because after connecting to a VPN with vpnc
, it puts a line in /etc/resolv.conf
so it looks like:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 1.2.3.4
nameserver 127.0.0.1
search MyDomain