I can get the internal hostname of an instance with the hostname command. How do I get the external host name from within the instance?

Specifically I'm on EY and using the ey ssh command, I want to know what the host name is so I can pass this to scp.


From within the instance, you can hit the Instance Metadata Service:



curl http://instance-data.ec2.internal/latest/meta-data/public-hostname

A wide variety of data is available via this interface.


/opt/aws/bin/ec2-metadata -p will print the public hostname of that instance.


It is very simple by ec2 instance metadata query tool.

run command:

./ec2-metadata --public-ipv4


./ec2-metadata --public-hostname

for more information, just pass --help to ec2-metadata


I don't know what system you use but I assume a Linux. You can either connect directly to your IP address or try a reverse lookup of this ip with for example

host -a <ip_address>

You can find out your IP address if you use the command ifconfig that will print out all information on the network interfaces.


Currently, on EC2 instances you can use:

$ ec2metadata --public-hostname

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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