If I check with google, I can see my public IP. Is there something on the Ubuntu command-line which will yield me the same answer?
|
If you are not behind a router, you can find it out using If you are behind a router, then your computer will not know about the public IP address as the router does a network address translation. You could ask some website what your public IP address is using
or shorter
|
|||||||||||||||||||||
|
|
For finding the external ip, you can either use external web-based services, or use system based methods. The easier one is to use the external service, also the Finding external IP using external servicesThe easiest way is to use an external service via a commandline browser or download tool. Since
Courtesy: You could also use Using
For a better formatted output use:
A faster (arguably the fastest) method using
|
|
@Z9iT, Sure.. It should work in any linux distribution provided that you have wget installed. As said if you have either curl or lynx already available please use that instead. You would need root permission to install so use
sudo apt-get install wget
– saji89
Jun 1 '12 at 12:19
|
||
|
The commands with ifconfig do only work, if you are not behind a NAT.
– lukassteiner
Jan 23 '13 at 15:52
|
||
|
|||
|
This proposal using dig is pretty nice unix.stackexchange.com/questions/22615/…
– binaryanomaly
Mar 14 '15 at 15:31
|
||
|
@saji
ifconfig if obsolete, please use iproute2 ;^). The command would be ip -o -4 a s eth0 | awk '{sub(/\/.*/, "", $4);print $4}'.
– bufh
Jun 11 '15 at 21:28
|
|
My favorite has always been :
simple, easy to type. You will have to install curl first ;) If ifconfig.me is down try icanhazip.com and or ipecho.net
or
|
|||||||||||||||||||||
|
|
icanhazip.com is my favorite.
You can request IPv4 explicitly:
If you don't have
|
||||
|
I've found everything to be annoying and slow, so I wrote my own. It's simple and fast. Its API is on http://api.ident.me/ Examples:
|
|||||||||||||||||
|
|
You could use a DNS request instead of HTTP request to find out your public IP:
It uses |
|||||||||||||
|
|
The one i'm using is :
Yes, you can have ip :-) |
|||||
|
|
Amazon AWS
Sample output:
I like it because:
|
||||
|
|
|
Type in this exactly, press Enter where indicated:
This manually submits a HTTP request, which will return your IP at the bottom of a Example output:
|
|||||||||
|
|
Another fast one (might well be the fastest, relatively)
|
||||
|
|
|
I have a stupid service for this by telnet. Something like this:
Feel free to use it. |
||||
|
|
|
For this, STUN was invented. As a client you can send a request to a publicly available STUN server and have it give back the IP address it sees. Sort of the low level whatismyip.com as it uses no HTTP and no smartly crafted DNS servers but the blazingly fast STUN protocol. Using
|
|
|
+1 for the geekiest and actually most apropos technology. The http query works, which is what I've been using all my life, but I like that there's actually been some thought put into the question. I didn't know this. Thanks!
– Mike S
Oct 18 '16 at 17:47
|
|
You can read a web page using only bash, without
|
||||
|
|
|
Use cURL with ipogre.com (IPv4 and IPv6 are supported). IPv4
IPv6
|
|||
|
|
|
For those of us with login access to our routers, using a script to ask the router what its' WAN IP address is is the most efficient way to determine the external IP address. For instance the following python script prints out the external IP for my Medialink MWN-WAPR300N router:
Note that this is not very secure (as is the case with plaintext credentials & logging in to most routers), and is certainly not portable (needs to be changed for each router). It is however very fast and a perfectly reasonable solution on a physically secure home network. To customize the script for another router, I recommend using the tamperdata addon in firefox to determine what HTTP requests to make. |
|||||
|
These will get the local IPs:
or for shorter output:
also
and probably:
This should get the external IP
N.B. If you don't mind to installing
|
||||
|
If you have installed lynx in Ubuntu type
|
|||||
|
|
use
then look for the relevant adapter (not |
|||||
|
|
Many home routers can be queried by UPnP:
Then, grep the ip address from the answer.
|
|||
|
|
|
If you are using DD-WRT then this works for me:
or
|
||||
|
|
|
A command with no dependencies except 8.8.8.8 being a GOogle DNS:
|
|||||||||||||
|
|
Simply issue a traceroute for any website or service..
Line 2 always seems to be my public IP address after it gets past my router gateway.
So, make a bash command.
And the output...
I don't think relying on PHP scripts and the sort is good practice. |
|||||||||||||||||
|
protected by Seth♦ Feb 28 '14 at 4:30
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
notify-send. – PJ Brunet Dec 2 '16 at 19:36