10

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.

12

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.

7

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

2

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

1

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.

1

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.