Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)
share|improve this question
    
What is returned by: ifconfig | grep 'inet addr:' ? – david6 Sep 22 '12 at 3:28
    
@david6 inet addr:192.168.1.111 Bcast:192.168.1.255 Mask:255.255.255.0 inet addr:127.0.0.1 Mask:255.0.0.0 – Victor S Sep 22 '12 at 3:48
    
This should help you cat /var/lib/dhcp3/dhclient.leases | grep dhcp-server-identifier – devav2 Sep 22 '12 at 3:53
    
@devav2 $ cat /var/lib/dhcp/dhclient-529bed02-363e-4e97-bd5d-9f63f42f17f2-eth0.lease |grep dhcp-server-identifier option dhcp-server-identifier 192.168.1.1; option dhcp-server-identifier 192.168.1.1; option dhcp-server-identifier 192.168.1.1; option dhcp-server-identifier 192.168.1.1; option dhcp-server-identifier 192.168.1.1; – Victor S Sep 22 '12 at 4:01
    
@devav2 192.168.1.1 is my router address. – Victor S Sep 22 '12 at 4:02
up vote 19 down vote accepted

Run nmcli dev list iface eth0 | grep IP4 in a terminal.
eth0 is the most common iface, but it could be eth1, eth2, etc.

This is still the command to use in Ubuntu 14.04 (LTS).

For at least Ubuntu 15.10 onwards (possibly also earlier versions), the command is nmcli device show eth0 [or your iface ]| grep IP4.

share|improve this answer
1  
Awesome answer! Appreciate your sharing! I got it. – Victor S Sep 22 '12 at 4:42
    
Glad it helped. I found it when I wanted a way to get that info, then parse it to display on demand, as i had 3 different possible DNS servers (ISP, Google, and OpenDNS). – Marty Fried Sep 22 '12 at 15:40
3  
As of 15.04, the command is nmcli dev show – Serg Jun 18 '15 at 22:06
    
+1 to the above comment, thanks! – Bealer Oct 1 '15 at 14:15
$ nm-tool 

will also list DNS Servers.

share|improve this answer
1  
+1 because this has been tested working up to 14.04 release. For 15.04 and newer release, use nmcli as suggested by the other answer instead. – clearkimura Dec 4 '15 at 4:12

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

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

  2. Select Connection information

  3. It should show you the DNS server address

    enter image description here

share|improve this answer
3  
My Ubuntu has no any GUI desktop. – Victor S Sep 22 '12 at 4:44
    
@VictorS it shows the same information as the other answer. I checked it – Anwar Shah Sep 22 '12 at 4:46
1  
Thanks for your answer, it is convenient for gnome or KDE users. – Victor S Sep 22 '12 at 4:51

To get the DNS address

Open terminal(Ctrl+Alt+T) and type cat /var/lib/dhcp/dhclient.leases | grep dhcp-server-identifier

share|improve this answer
    
There is nothing in the /var/lib/dhcp/dhclient.leases, it is empty. – Victor S Sep 22 '12 at 5:36
    
$ file /var/lib/dhcp/dhclient.leases /var/lib/dhcp/dhclient.leases: empty – Victor S Sep 22 '12 at 5:38
    
try /var/lib/dhcp/dhclient.eth0.leases – frag Jan 24 '15 at 20:15

here it is:

cat /etc/resolv.conf

but do not edit this file

share|improve this answer
    
In recent Ubuntu releases (post 2012 I think) it won't be useful, since it will contain nameserver 127.0.1.1, referring to localhost dnsmasq installation. It's better to query NetworkManager as written by @anwar-shah and @marty-fried – gerlos Jan 14 at 10:44

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(because Linux) 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.
share|improve this answer

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
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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