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 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

3 Answers 3

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

curl http://169.254.169.254/latest/meta-data/public-hostname

or

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

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

It is very simple by ec2 instance metadata query tool.

run command:

./ec2-metadata --public-ipv4

or:

./ec2-metadata --public-hostname

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

share|improve this answer

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.