How to view the DNS address assigned by DHCP?

How to view the DNS address assigned by DHCP?

ifconfig can not show it.

$ ifconfig -a
eth0 Link encap:Ethernet HWaddr 90:e6:ba:22:6a:f2 inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::92e6:baff:fe22:6af2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:224856 errors:0 dropped:0 overruns:0 frame:0 TX packets:220040 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:166848627 (166.8 MB) TX bytes:20256333 (20.2 MB) Interrupt:46 Base address:0x4000
lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:16436 Metric:1 RX packets:5889 errors:0 dropped:0 overruns:0 frame:0 TX packets:5889 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:468885 (468.8 KB) TX bytes:468885 (468.8 KB)
wlan0 Link encap:Ethernet HWaddr 00:26:5e:e8:4f:8e BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
10

10 Answers

For at least Ubuntu 15.10 onward (possibly also earlier versions) run in a terminal:

nmcli dev show eth0 | grep IP4

eth0 is the most common iface, but it could be eth1, eth2, etc.

For older versions use nmcli dev list iface eth0 | grep IP4.

9
$ nm-tool 

will also list DNS Servers.

1

To get the DNS address open terminal (Ctrl+Alt+T) and type:

cat /var/lib/dhcp/dhclient.leases | grep dhcp-server-identifier
4

Now that Ubuntu (and Debian and almost all distros) use systemd (check with file /sbin/init) maybe the more elegant way to get this info is with:

systemd-resolve --status
  • freedesktop.org docs
  • Arch Wiki: Use systemd-resolve --status where it says resolvectl (systemd-resolve is a symlink to resolvectl).
  • If you have problems with DNS subsystem I suggest removing resolvconf package. May conflicts with systemd-resolve.
4

here it is:

cat /etc/resolv.conf

but do not edit this file

2

As a GUI alternative to @MartyFried's answer, try this.

  1. Click on the Network connectivity icon on the top panel.

  2. Select Wi-Fi Settings

  3. It should show you the DNS server address

    screenshot

3

In Ubuntu 16.04, the info from dhcp is written in: /var/lib/NetworkManager/dhclient-<interface>.conf

0

As I mentioned in the comments (which by popular request has become an answer now), one can use nmcli dev show as of Ubuntu 15.04. Add grep to the mix and you're set:

$ nmcli dev show | grep 'DNS'
IP4.DNS[1]: 208.67.222.222
IP4.DNS[2]: 208.67.220.220

My actual solution(est 2015, Ubuntu 14.04), is this:

  1. Start the CLI
  2. Type: sudo apt-get install gnome-system-tools
  3. After install succeeded, type at the terminal: network-admin

If you somehow can't do this then try this, though it's not good enough for me, but it got my job done:

  1. type dig google.com
  2. near the end you can see something like this(est. 2015) ;; SERVER: and then an IP address(at least, on my machine) THAT is the actual DNS server resolving the domain for you. That server can change per hostname though.

If your computer run behind of Router/WiFi of your Internet Provider, you'll get a Private IP Address from DHCP of Router, something like 192.168.0.2 or 192.168.1.100.

To get the Public IP Address of DHCP of DNS from your Internet Provider, you need run the follow command line on terminal:

dig +short myip.opendns.com @resolver1.opendns.com

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like