How To Get Public IP From Command Line
Posted on June 20, 2021 • 3 min read • 457 wordsIn this tutorial we'll learn how to get Public IP address from terminal or 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.
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.
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
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
.
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.
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
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
There are multiple sites which can be used to check our Public IP Address.
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
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/
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.