Return the private IP of an EC2 instance from within the EC2 instance
7
votes
2
answers
13493
views
What specific syntax can be used to return the private IP address of an Amazon Linux EC2 instance from the command line within that instance?
So far, I have come up with the following:
# Get private IP from inside the instance by filtering inside the following:
instanceid=$(curl http://169.254.169.254/latest/meta-data/instance-id)
echo $instanceid
aws ec2 describe-instances --instance-id $instanceid --region us-west-2
However, as you can see if you type these commands inside an EC2 instance yourself, the above 3 lines result in a massive output, which would be a mess to filter through manually.
Can someone suggest one or two lines of code to return simply the private ip of the instance and NO other information?
Asked by CodeMed
(5357 rep)
Jun 8, 2019, 12:49 AM
Last activity: Apr 9, 2025, 01:38 PM
Last activity: Apr 9, 2025, 01:38 PM