Many times we need to
find out our public IP from the terminal
, which allows us to obtain the IP quickly and without installing any extra programs.
I will divide the article into two sections, one with the
necessary steps to find out our public IP in Linux
and another section where I will explain how to do it on Windows operating systems.
How to find out the public IP from the terminal in Linux?
First we will open a terminal session, whether we have Linux as an operating system or using
PuTTY
if we want to find out the public IP of our remote UNIX / Linux server.
I will show two possible commands that will show us our public IP:
-
dig +short myip.opendns.com @resolver1.opendns.com
-
dig TXT +short oo.myaddr.l.google.com @ns1.google.com
The first thing we should know is that the
dig
command allows us to make DNS requests to obtain information from domain name servers, mail exchangers, etc. This command can be used without installing any additional package in most UNIX / Linux distributions.
The second thing we should observe is that
in the first command we use the Opendns DNS
to obtain our public IP, while
in the second command we use the Google DNS
. Both commands give the same result, but both are facilitated because some users comment that Google's DNS is faster, while others say they are slower, so everyone can make their own decision of which DNS server to use.
How to find out the public IP from the command line in Windows?
Previously we discussed
how to access the terminal or command line in Windows
and now we will show how to use it to obtain the public IP of our PC.
We can use one of the following commands:
-
nslookup myip.opendns.com resolver1.opendns.com
-
nslookup -querytype=TXT oo.myaddr.l.google.com ns1.google.com
As in the case of Linux, we show the commands using different DNS servers, first that of Opendns and secondly that of Google.
Finally, say that it is true that there are many pages or web services that allow us to find out our public IP easily from the browser (
http://icanhazip.com
,
http://ifconfig.co
,
http://ifconfig.me
and many more), but the problem is that these third-party services do not offer us the reliability and speed that a simple terminal command can offer us.