June 20, 2021 in Tutorial3 minutes

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 +shortAs alternative, we can use nslookup to get public IP from OpenDNS DNS server
nslookup myip.opendns.com resolver1.opendns.comWe can also get our Public IP by using dig to Google DNS
dig TXT +short o-o.myaddr.l.google.com @ns1.google.comAs alternative, we can use nslookup to get public IP from Google DNS
nslookup -type=txt o-o.myaddr.l.google.com ns1.google.comYou 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. +shortAs alternative, we can use nslookup to get public IP from Akamai DNS.
nslookup whoami.akamai.net. ns1-1.akamaitech.net.You read it right, telnet, we can get our public IP using telnet
telnet telnetmyip.comor 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
nc telnetmyip.comTo get our public IP using SSH, we can use the command below
ssh sshmyip.comYou will be asked to verify server signature
ssh -o StrictHostKeyChecking=no sshmyip.comThere 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.comTo Check your public IP using ifconfig.me you can use the command below.
curl https://ifconfig.meTo check your public IP using ifconfig.co you can use the command below.
curl https://ifconfig.coTo check your public IP using checkip.amazonaws.com you can use the command below.
curl https://checkip.amazonaws.com/To check your public IP using wtfismyip you can use the command below.
curl https://wtfismyip.com/textIn this tutorial we learn various methods on how to get public IP address from command line.