How to find Public IP address AWS EC2 or Lightsail VM

last updated in Categories , , ,

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 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 dig command:
dig +short
## or ##
dig TXT +short

My IP address of AWS EC2 vm is as follows:

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:

How to use awk cli to obtain information

First, make sure your asw 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

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Notable Replies

Continue the discussion

4 more replies


Historical Comment Archive