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" ..
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.
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.
Sep 15, 2015 at 5:51
ifconfig
gives informations about your network adapters.eth0
is the first (and probably only) ethernet adapter. It's current IP address is listed asinet address
.