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

I'm writing a bash script that needs to use the instance's public dns name. What's the easiest way to obtain it from inside the running instance?

share|improve this question
up vote 7 down vote accepted

You can fetch data about the running instance from a little http API using curl like this:

public_name=$(curl -s
echo $public_name

Other values you can fetch include:

  • ami-id
  • hostname
  • instance-id
  • local-ipv4
  • local-hostname
  • public-hostname
  • public-ipv4

There are more but those are some of the most useful. Things like the SSH keys you specify at instance launch can also be retrieved from there.

share|improve this answer
Note that the DNS name for that API is instance-data.ec2.internal if you'd prefer to use that. – ceejayoz Jun 10 '11 at 20:24

Your Answer


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.