How to Find the Public IP of an EC2 Instance in AWS
You can easily find your public or private IPv4 IP address on Linux or UNIX-like operating systems running on AWS EC2 or Lightsail VM.
This post explains how to find your IP address using command line options for the AWS EC2 instance.
To find the public IP address on AWS EC2 or Lightsail VM
Open the terminal application and log in using ssh, replacing the key and instance address:
$ ssh -I chave.pem [email protected]
To get the public IPv4 address assigned by AWS for EC2/LightSail VM, run in the terminal:
$ dig +short myip.opendns.com @resolver1 .opendns.com
OU
$ dig TXT +short o-o.myaddr.l.google.com @ns1 .google.com
You should see your IP address on the screen. It is the fastest way to find your public IP address without using third-party sites or logging into the AWS Console.
There is another simpler option, but it requires the curl package installed. Run the following curl command:
$ curl http://checkip.amazonaws.com
The public IP address should appear in the terminal.
Finding the Private IP of an EC2 instance on AWS:
Log into the instance, and type in the terminal:
$ curl http://169.254.169.254/latest/meta-data/local-ipv4
To summarize, it is quite simple to find the Public or Private IP of an AWS EC2 instance, as long as you know the command. :-)
That was just one piece. The course teaches the whole path — from your first command to exam day.