IP address is unique protocol, that define address host or server. In this post is how to find out your own public IP address using command line options on an Ubuntu, Debian, CentOS Linux, macOS/OS X and Unix bash shell. A computer or server can be connected to other servers around the world because there is a public IP address and they are interconnected. This post explain about show public IP from terminal linux.
Why Need Know Public IP
Main reason why we need to know the public ip of our server is:
Troubleshooting.
Big reason is for troubleshooting. For example in cases like this.
There is a server using local ip address, under the NAT network. The server cannot access the API on the opposing server. Even though the original public server IP has been allowed or whitelisted.
This is important to know the public IP. Whether the public ip that is allowed for API access is correct or not. Perhaps we gave wrong information public IP to the API developer.
How to Know Public IP
Use Browser to Show Public IP
If our server supports the GNOME desktop and there is a browser, use a browser. Search google and Open url ip public check. Example https://whatismyipaddress.com
Use Terminal to Show Public IP
This is an option if we only have a terminal console available. Use several powerfull command in this sub section.
1. Use Dig Command
Open the Terminal application. Type the following dig
(domain information groper) command
dig +short myip.opendns.com @resolver1.opendns.com
or
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com
Result output is :
2. Use host command
host myip.opendns.com resolver1.opendns.com
3. Use the Google Server using dig
dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{ print $2}'
That is simply method linux show public IP. Hope it’s helpful, please feel free to leave a comment if you have any questions and I’ll appreciate it. Or if there is another method to be able to show linux public ip, you can also add it in the comments, I will mention you and add a backlink to your website.
See you in the next article. Big thanks and bye.