Find my public ip address from linux command line

An IP address stands for Internet Protocol Address. Devices are assigned with specified IP Address to identify the device which are connected on internet. Public IP addresses are routable on Internet and are generally provided by an ISP (Internet service provider) which are accessible over the Internet.
Do you know how to find public IP address from Linux command line? There are several ways to find and identify public IP address. For example, we can use third party websites or “shell” commands. This article provides simple methods to find public IP address from command line on Linux.
Public IP addresses are used for Internet web servers, DNS servers, network routers and they are directly connected to computers using a public IP address. The IANA (Internet Assigned Numbers Authority) is responsible to assign IP address to an ISP (Internet Service Protocol) and these providers are entitled to assign a specific IP address to each connected device.
It is the fastest way to identify a public IP address from a Linux command line. To identify a public IP address, use the following command –
$ dig +short myip.opendns.com @resolver1.opendns.com
The output should be like this –
$ dig +short myip.opendns.com @resolver1.opendns.com
183.82.108.59
In the above output 183.82.108.59 is the system IP address.
The below is another alternative method to identify a public IP address with the host command.
Use the following command to identify a public IP address.
$ host myip.opendns.com resolver1.opendns.com
The sample output should be like this –
$ host myip.opendns.com resolver1.opendns.com
Using domain server:
Name: resolver1.opendns.com
Address: 208.67.222.222#53
Aliases:
myip.opendns.com has address 183.82.108.59
Host myip.opendns.com not found: 3(NXDOMAIN)
Host myip.opendns.com not found: 3(NXDOMAIN)
In the above output 183.82.108.59 is the system IP address.
Using “dig” command and Google server, we can find an IP address.
To find the IP address, use the following command-
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
The output should be like this –
$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
183.82.108.59
In the above output 183.82.108.59 is the system IP address.
We can use third party websites to find an IP address from Linux command Linux.
To find the IP address, use any one of the following commands –
$ curl ifconfig.me
$ curl icanhazip.com
$ curl ipecho.net/plain
$ curl ifconfig.co
The sample output should be like this –
tp@linux:~$ curl ifconfig.me
183.82.108.59
tp@linux:~$ curl icanhazip.com
183.82.108.59
tp@linux:~$ curl ipecho.net/plain
183.82.108.59
tp@linux:~$ curl ifconfig.co
183.82.108.59
In the above output 183.82.108.59 is the system IP address.
To store IP address in a shell variable, use the following command –
$ myip="$(dig +short myip.opendns.com @resolver1.opendns.com)"
$ echo "My WAN/Public IP address: ${myip}"
The sample output should be like this –
My WAN/Public IP address: 183.82.108.59
In the above output 183.82.108.59 is the system IP address.
This the simplest solution to find the IP address by clicking on the below links –
https://www.google.co.in/search?q=what+is+my+IP+address
https://duckduckgo.com/?q=ip
http://www.wolframalpha.com/input/?i=what+is+my+ip+address
Congratulations! Now, you know “How to find Public IP address with command line interface and also without command line interface”. We’ll learn more about these types of commands in our next Linux post. Keep reading!