There are numerous methods/apps available to do this in graphical user mode. Open your web browser and go to WhatIsMyIP.com website. There you can see your public IP. It is one of the most popular method to find out your public IP address, regardless of any Operating system. All you need is an Internet connection and a web browser. But, how to find out public IP address from command line on Linux? That's what we are going to see in this guide.
Find Out Public IP Address From Command Line On Linux
There many commands to find the public IP address. Here I have listed some of them. Try all methods and pick one that suits you. Good luck!
We can find the public IP address using 'dig' and 'host' commands. If dig and host commands are not available in your system, install dnsutils package.
On Arch Linux and derivatives:
$ sudo pacman -S dnsutils
On RHEL, CentOS, Fedora:
$ sudo yum install dnsutils
Or,
$ sudo dnf install dnsutils
On Debian, Ubuntu and its derivatives:
$ sudo apt-get install dnsutils
Now, let us find the public IP.
Method 1:
Let us find out public IP with Google resolvers using dig command:
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed 's/"//g'
Alternatively, use this command to find out the public IP:
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
Can I get the same info with opendns resolvers? Yes, you can!
$ dig +short myip.opendns.com @resolver1.opendns.com
Method 2:
We can get the same info using host command.
$ host myip.opendns.com resolver1.opendns.com
Sample output:
Using domain server: Name: resolver1.opendns.com Address: 208.67.222.222#53 Aliases: myip.opendns.com has address 122.178.32.233 Host myip.opendns.com not found: 3(NXDOMAIN) Host myip.opendns.com not found: 3(NXDOMAIN)
Method 3:
You can use curl command to find the public IP of your system from a third-party websites. I do not recommend finding IP address using third-party sites due to security reasons. Be cautious!
Let me show you some examples.
$ curl ipinfo.io
Sample output:
{ "ip": "122.178.32.233", "hostname": "abts-tn-dynamic-233.32.178.122.airtelbroadband.in", "city": "Coimbatore", "region": "Tamil Nadu", "country": "IN", "loc": "10.9925,76.9614", "org": "AS24560 Bharti Airtel Ltd., Telemedia Services", "postal": "641001"
Here is another one:
$ curl ifconfig.me
One more command...
$ curl ip.sb
curl is installed by default. If it is not installed by any chance, run the following command to install it.
On Arch Linux and derivatives:
$ sudo pacman -S curl
On RHEL, CentOS, Fedora:
$ sudo yum install curl
Or,
$ sudo dnf install curl
On Debian, Ubuntu and its derivatives:
$ sudo apt-get install curl
Here it is another method to find the public IP.
$ curl https://wtfismyip.com/text
Sample output:
122.178.32.233
The other useful methods to find out the public IP address are given below.
$ curl api.ipify.org
$ curl https://ipinfo.io/ip
$ curl ipecho.net/plain
$ curl ifconfig.co
$ curl ident.me
$ curl icanhazip.com
$ curl ip.appspot.com
And, that's all for now. Which method are you using to find the public IP? Let me know in the comment section below. I will check and update this guide.
2 comments
‘curl icanhazip.com’ is the easiest one for me – response is just the ip – no mess, no fuss.
Really great tips here. Only knew about typing “what’s my ip” on google search or using iplocation.net or using opendns resolvers.