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
As alternative, we can use nslookup to get public IP from OpenDNS DNS server
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
As alternative, we can use nslookup to get public IP from Google DNS
nslookup -type=txt o-o.myaddr.l.google.com ns1.google.com
You can replace
ns1.google.com above with
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
As 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
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
To get our public IP using SSH, we can use the command below
You will be asked to verify server signature
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.
To Check your public IP using ifconfig.me you can use the command below.
To check your public IP using ifconfig.co you can use the command below.
To check your public IP using checkip.amazonaws.com you can use the command below.
To check your public IP using wtfismyip you can use the command below.
In this tutorial we learn various methods on how to get public IP address from command line.