Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Possible Duplicate:
Finding the Public IP address in a shell script

I'm currently doing this in a script:

EXTERNAL_IP=`curl -s`

There's got to be a built in linux command or something for this, no?

share|improve this question

marked as duplicate by Zoredache, mailq, Scott Pack, Steven Monday, quanta Dec 1 '11 at 2:35

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

What is your precise definition of "external IP address"? If you mean the IP address that other sites on the Internet see your web requests as coming from (possibly the address of your HTTP proxy), then you are doing it the right way. If that's not what you mean, then maybe not. – David Schwartz Nov 30 '11 at 21:44
up vote 1 down vote accepted

No, there is no built-in command, and even the command you suggest may not give you what you want if your NAT device is doing anything more complex then a simple masquerading.

share|improve this answer

If you mean your source address as the rest of the Internet sees it, then the way you're doing it now is pretty much it. A machine behind a firewall or other device doing NAT will be happily unaware of any address translation done further along.

You might find that is a bit cleaner for what you're after - have a look under the Command Line Interface section on the front page.

share|improve this answer
On EC2 you can also query the metadata: curl – Josh Nankin Nov 30 '11 at 21:48
Interesting - will remember that one for future reference! – Andy Smith Nov 30 '11 at 22:00

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