How to find Public IP address AWS EC2 or Lightsail VM

I need to get public IPv4 address on current EC2 or Lightsail VM Linux/Unix instance. How do I find Public IP address AWS EC2 or Lightsail VM?

One can easily find out their public or private IPv4 IP address on a Linux or Unix-like operating systems running on AWS EC2 or Lightsail VM. This page explains how to find out your IP address using command-line options for AWS EC2 instance.


Find Public IP address AWS EC2 or Lightsail VM

  1. Open the terminal application and login using ssh: ssh ec2-user@my-aws-instanace-name
  2. To get public IPv4 address assigned by the AWS for EC2/Lightsail vm, run:
    dig +short
    dig TXT +short
  3. You should see your IP address on the screen. It is the fastest way to find out your public IP address without using 3rd party site.
  4. Another option, run curl

Let us see all commands and options in details.

Use dig command to find EC2 or Lightsail VM IP address

Type the following dig command:
dig +short
## or ##
dig TXT +short

My IP address of AWS EC2 vm is as follows:

We can use the host command too:
$ host

Get public IP address of current EC2 instance

One can use the following curl command to get private IPv4:
And, to get public IPv4, run:

Of course, you can use third party web sites too:

My aws Lightsail IP address:

Find and store public IP address on current EC2 instance

Here is how to store is using bash shell:
Display it back using the echo command/printf command:
echo "AWS EC2 IP - $my_ip"

Finding public IP address AWS EC2 or Lightsail VM using aws cli

First, make sure your aws cli configured, run:
aws configure
You need to input your AWS API access token and key. See this page about aws cli. For Lightsail VM, try the following command to obtain information about all static IPs in your account:
aws lightsail get-static-ips
We can get information about a specific static IP. For example, find info about a static IP named “my-www-static-ip1”
aws lightsail get-static-ip --static-ip-name my-www-static-ip1

Find IP address AWS EC2 Lightsail instacne using Linux command

Various command to find your EC2 or Lightsail VM instant public IP address running on AWS cloud

For EC2 instance try the following (feel free to replace {YOUR_ID_HERE} with actual EC2 instance ID):
aws ec2 describe-instances --instance-ids {YOUR_ID_HERE} --query 'Reservations[*].Instances[*].PublicIpAddress' --output text


You learned how to obtain the static IP addresses of AWS EC2 or Lightsail instance running either Linux or Unix/FreeBSD operating system.

This entry is 1 of 2 in the Find IP Address Tutorial series. Keep reading the rest of the series:
  1. How to find Public IP address AWS EC2 or Lightsail VM
  2. Find My Public IP Address From Command Line On a Linux

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallCentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.