-1

How to get my dhcp ip address, whether i am in a local network?

I.e. if we have internet access in local network, but i want to know my dhcp server IP .. like " what is my IP" ..

  • ifconfig gives informations about your network adapters. eth0 is the first (and probably only) ethernet adapter. It's current IP address is listed as inet address. – Nephente Sep 15 '15 at 05:45

2 Answers2

2

Edit Your question was worded in slightly confusing way. Getting your public IP form terminal can be done with curl https://diagnostic.opendns.com/myip. Open DNS has web service that tells you your IP address, which is pretty much just a web page , with only one text - your IP. Effectively, you are downloading a web page that tells you your IP.

Original

Typically dhcp server is located on the router. Thus , your main goal then is to get address of the router, which in networking terms would be default gateway. Thus , effectively your question can be solved by the multiple solutions as described in my answer here. The simplest method is to use netstat -nr command.

There is another method as well: nmcli dev list | grep -i dhcp_server_identifier (Ubuntu 14.04 and earlier). Sample output for that would be:

$ nmcli dev list | grep -i dhcp_server_identifier                              
DHCP4.OPTION[13]:                       dhcp_server_identifier = 192.168.0.1

With Ubuntu 15.04 the nmcli version is different, hence you have to enter slightly different command:

nmcli dev show | \grep 'gw ='

Side note : grep in my install of 15.04 is aliased to grep --color=auto which prints colorized output. If we want just to see the particular lines, we need to use simple grep, which the forward slash instructs the shell to use.

Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
1

What is my ip shows you the public IP of your gateway. If this is what you are looking for you wan use:

nslookup myip.opendns.com
  • dhcp server is a different term from public IP address. The dhcp server is what assigns a local IP address to a machine. For example, if my IP address on the network is 192.168.0.69 then where does it come from ? From the router, meaning that dhcp server is located at address 192.168.0.1, which is router local IP. – Sergiy Kolodyazhnyy Sep 15 '15 at 05:51
  • I know, and you are totally right. Otoh, if you google 'what is my ip' you get your public ip address. In typical home broadband connections the router acts as a dhcp server and a gateway (as, most likely, you already know) so I think this is what OP was asking. –  Sep 15 '15 at 06:01