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 want some way of identifying which instance that I'm on when I ssh into a Linux ec2 instance. I would like to be able to uniquely identify the instance from the command-line and correlate this to

Any of the following would be helpful:

  Private DNS
  Public DNS

I'm using Ubuntu and Red Hat instances.

share|improve this question
up vote 8 down vote accepted

I'm assuming you want to do this from the bash shell rather than with the boto python library or similar...

You should be able to query the metadata service on



You can get a listing of what meta-data is available with:


This is documented at

Note: I am more familiar with openstack's metadata service, but that was modelled on the Amazon EC2 service. The quantity and types of data available are different, but accessing it is the same.

share|improve this answer
Perfect! Thanks @Craig_Sanders! – Rob Bednark Jul 24 '12 at 15:54

Personally, i just run facter. (Part of puppet)

ec2_ami_id => ami-ffffff
ec2_ami_launch_index => 0
ec2_ami_manifest_path => (unknown)
ec2_block_device_mapping_ebs1 => /dev/sda
ec2_block_device_mapping_ebs3 => /dev/sdf
ec2_block_device_mapping_ephemeral0 => /dev/sdb
ec2_block_device_mapping_ephemeral1 => /dev/sdc
ec2_block_device_mapping_ephemeral2 => /dev/sdd
ec2_block_device_mapping_ephemeral3 => /dev/sde
ec2_block_device_mapping_root => /dev/sda1
ec2_hostname =>
ec2_instance_id => i-e999fff4
ec2_instance_type => m1.medium
ec2_kernel_id => aki-a9999af4
ec2_local_hostname =>
ec2_local_ipv4 =>
ec2_placement_availability_zone => ap-southeast-1b
ec2_profile => default-paravirtual
ec2_public_hostname =>
ec2_public_ipv4 =>
share|improve this answer
A note - facter gets this from the metadata service @CraigSanders mentions. – ceejayoz Jul 24 '12 at 15:54

Maybe something like this?

Simple Command-Line Access to Amazon EC2 and Amazon S3

share|improve this answer

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.