How to find Public IP Address on Linux?

There are many ways to find public IP address on Linux.Here Step by Step instruction to find public ip on linux.
What is IP Address?

An IP address is used to identify devices.Each device is connected through an IP address.

Dig command is a network administrator command line tool for determining public IP address and for network troubleshooting. To find a public IP address, open your terminal application on Linux and enter the following command

$ dig +short myip.example.com @resolver1.example.com

The output will be like

11.11.11.11

Find IP address using Host Command:-

$ host myip.example.com resolver1.example.com

The output will be like as bellow

Using domain server:
Name: resolver1.example.com
Address: 11.11.11.11#50
Aliases: 

myip.example.com has address 11.11.11.11
......

Find IP address using Google Server:-

$ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'

The output will be like as bellow

11.34.111.11

Store IP address in a shell variable:-
The bellow command is used to store the IP address in a shell variable

$ myip="$(dig +short myip.example.com @resolver1.example.com)"
$ echo "My WAN/Public IP address: ${myip}"

The output will be like as bellow

My WAN/Public IP address: 11.11.11.11

Similar Posts