I know they're defined in /etc/resolv.conf
, but what if it's not there? And more specifically, how do you find the DNS server returned by DHCP?
In GNOME you can use the NetworkManager applet to see the primary DNS for any connection, so how would you do the same from the command line?
Usually dhclient.leases file is located at
/var/lib/dhcp3/dhclient.leases
, type the following command:less /var/lib/dhcp3/dhclient.leases
OR
cat /var/lib/dhcp3/dhclient.leases
OR
You can just use grep command to get DHCP server address, enter:
grep dhcp-server-identifier /var/lib/dhcp3/dhclient.leases
OR
dhclient eth0
I recently had this problem where my
dhcpcd
was misconfigured as was not setting DNS servers. I found out that I can query which nameservers are available by DHCP with the following command:The command will output a bunch of network connection information. Look for the line beginning with
new_domain_name_servers
.From here I was able to manually set the nameservers.
One more solution to query the DHCP server:
The output tells you the name server offered by the DHCP server:
I found my DHCP lease info at
/var/lib/dhclient/dhclient-eth0.leases
in case anyone can't find it at/var/lib/dhcp3/dhclient.leases
well, why not simply dig that?
look at the last lines: ;; SERVER: 192.168.1.15#53(192.168.1.15)
If there is nothing in /etc/resolv.conf, DNS resolution (that is, resolution using dns as defined in /etc/nsswitch.conf) will not work. This is what dig, host and the libc routines use to do DNS resolution. If there is nothing specified in this file, DNS resolution will not work (though host resolution may work via other means, if another host resolution method is configured, such as NIS (this is unlikely)).
this command show the DNS server on your net
dig | grep SERVER: | awk -F# '{ print $1 }' | awk -F: '{ print $2 }'
172.17.0.1
If you are using NetworkManager, to get ipv4 DNS servers for YourConnectionName connection, you can use something like
Use
nmcli connection show YourConnectionName
to get all possible options and values.Read
/etc/resolv.conf
. That's all.man resolv.conf
is useful, too.In modern distributions it is looks like
where 91.193.220.7 is my ISP's DNS server