Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a way to get my IP address using the command prompt in Linux. I know when you type "ifconfig" you can get your local IP address (i.e. 192.168.0.103), but I'm looking for my IP address that I get from my ISP. How can I get this from Linux without having to visit some website?

share|improve this question
add comment

4 Answers

up vote 4 down vote accepted

If your machine is assigned a local IP address, it may not know your public-facing address. You can query a server not on your local network to discover your public-facing address.

$ curl whatismyip.org
share|improve this answer
1  
if you get a proxy ip address (IE, a wrong one) try checkip.dyndns.com:8245 –  Journeyman Geek Apr 4 '10 at 2:40
    
The question specifically said "without having to visit some website". –  David Schwartz Jan 7 '13 at 6:22
add comment

You can use one of the several services that tell you your own address:

dig +short myip.opendns.com @resolver1.opendns.com
curl corz.org/ip
curl ip.uostas.net

(I still haven't found one that supports IPv6.)

share|improve this answer
    
+1, that's really useful for an external-facing ip... pity about the lack of IPv6 services but you'd need an IPv6 connection to the net and most ISPs/broadband routers don't seem to support it. –  Ninefingers Apr 4 '10 at 17:10
add comment

If your computer is on e.g. a corporate LAN with an address-translating firewall there is unfortunately no information on your computer about the externally visible address. For all your computer knows it has a local IP (e.g. 192.168.0.103) that can be used to connect to any host on the Internet. The address-translating firewall is completely transparent from your computer's point of view.

The only way is to use an external "observer" such as whatismyip.org to help. If you don't like having to access it through a full web browser curl is an alterantive as pointed out by Samuel K

share|improve this answer
add comment

Add this to your ~/.bashrc file on Linux or ~/.bash_profile on Mac.

alias myip='wget http://automation.whatismyip.com/n09230945.asp -O - -q ; echo'

Then run

source ~/.bashrc

or:

source ~/.bash_profile

Source will activate the changes you made to your bash file. It's only required once.

Now type 'myip' from command line, and you get the public IP address.

:# myip
23.23.133.111
share|improve this answer
add comment

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.