Howtodojo logo
  • Home 
  • About 
  • Certifications 
  • Sample Database 
  • Cheatsheet 
  • Glossary 
  • Blog 
  • Tags 
  1.   Blog
  1. Home
  2. Blog
  3. How To Get Public IP From Command Line

How To Get Public IP From Command Line

Share via
Howtodojo
Link copied to clipboard

In this tutorial we'll learn how to get Public IP address from terminal or command line.

On this page
Get Public IP From DNS   Get Public IP Using dig to OpenDNS   Get Public IP Using dig to Google DNS   Get Public IP Using dig to Akamai DNS   Using Telnet   Using SSH   Using Curl   icanhazip.com   ifconfig.co   wtfismyip.com  
How To Get Public IP From Command Line

In this tutorial we’ll learn how to get Public IP address from Terminal or Command Line.

This will be useful to find public IP address of a cloud instance like EC2 instance, Lightsail instance, or DigitalOcean Droplets.

We can also use this method to find Public IP of a VPS or any bare metal server that have Public IP Address.

Get Public IP From DNS  

If you’re familiar with dig, you might be wondering why using dig since we usually use dig to interrogate a DNS server. But we can get our public IP using dig.

Get Public IP Using dig to OpenDNS  

dig myip.opendns.com @resolver1.opendns.com +short
```bash

As alternative, we can use nslookup to get public IP from OpenDNS DNS server

```bash
nslookup myip.opendns.com resolver1.opendns.com

Get Public IP Using dig to Google DNS  

We can also get our Public IP by using dig to Google DNS

dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
```bash

As alternative, we can use nslookup to get public IP from Google DNS

```bash
nslookup -type=txt o-o.myaddr.l.google.com ns1.google.com

You can replace ns1.google.com above with ns2.google.com, ns3.google.com or ns4.google.com.

Get Public IP Using dig to Akamai DNS  

The next method is to get Public IP using dig to Akamai DNS

dig whoami.akamai.net. @ns1-1.akamaitech.net. +short
```bash

As alternative, we can use nslookup to get public IP from Akamai DNS.

```bash
nslookup whoami.akamai.net. ns1-1.akamaitech.net.

Using Telnet  

You read it right, telnet, we can get our public IP using telnet

telnet telnetmyip.com
```bash

or we can also use nc to the same server. Please note that telnetmyip.com will give response / output in json so you have to parse the output to the the ip.  
As alternative, you can also use nc to get the Public IP information from telnetmyip.com

```bash
nc telnetmyip.com

Using SSH  

To get our public IP using SSH, we can use the command below

ssh sshmyip.com
```bash

You will be asked to verify server signature

```bash
ssh -o StrictHostKeyChecking=no sshmyip.com

Using Curl  

There are multiple sites which can be used to check our Public IP Address.

icanhazip.com  

To Check your public IP using icanhazip.com you can use the command below.

curl https://icanhazip.com
```bash

### ifconfig.me {#h-ifconfig-me}

To Check your public IP using ifconfig.me you can use the command below.

```bash
curl https://ifconfig.me

ifconfig.co  

To check your public IP using ifconfig.co you can use the command below.

curl https://ifconfig.co
```bash

### checkip.amazonaws.com {#h-checkip-amazonaws-com}

To check your public IP using checkip.amazonaws.com you can use the command below.

```bash
curl https://checkip.amazonaws.com/

wtfismyip.com  

To check your public IP using wtfismyip you can use the command below.

curl https://wtfismyip.com/text
```bash

## Summary {#h-summary}

In this tutorial we learn various methods on how to get public IP address from command line.
 How to Generate Random Data in PostgreSQL
Speedtest CLI on Ubuntu [How To Install] 
On this page:
Get Public IP From DNS   Get Public IP Using dig to OpenDNS   Get Public IP Using dig to Google DNS   Get Public IP Using dig to Akamai DNS   Using Telnet   Using SSH   Using Curl   icanhazip.com   ifconfig.co   wtfismyip.com  
Follow me

We publish tutorials, tips and tricks about Linux, open source, cloud computing, and infrastructure

     
Copyright © 2012 - 2025 howtodojo.com. |
Howtodojo
Code copied to clipboard