Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

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.

share|improve this answer

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

share|improve this answer

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

share|improve this answer

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.

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.