fbpx Find EC2 Public IP in AWS | Certificação Linux

How to Find the Public IP of an EC2 Instance in AWS

📅 11/16/2022 ⏱ 2 min ✍️ Uira Ribeiro
commands
How to Find the Public IP of an EC2 Instance in AWS
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

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. :-)

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp