Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

1 Answer 1

up vote 6 down vote accepted

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

#/bin/bash
public_name=$(curl -s http://169.254.169.254/latest/meta-data/public-hostname)
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
1  
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

 
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.