find public ip address of server

How to Find Public IP Address of Server in Linux

Every public facing server has a public IP address. A public IP address allows other computers on the internet to connect to your computer. It also allows them to allow connection from your server, by configuring their firewall rules based on your server’s public IP address. This public IP address can be static or dynamically assigned. Sometimes you may not know or you may want to find public IP address of server in Linux. There are several ways to do this. In this article, we will look at 5 different ways to find public IP address in Linux.


How to Find Public IP Address of Server in Linux

Here are the different ways to find public IP address of server in Linux. Run the following commands from within your server, and not client workstation, to get the correct IP address.


1. Dig utility

You can use dig utility to easily discover your server’s IP address with the help of openDNS. Here is a command to find out your server’s public IP.

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

54.43.32.21


2. Host Command

Similarly, you can also use Host command to lookup your server’s public IP. It also uses opendns.com like the above command.

$ host myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com has" | awk '{print $4}'

54.43.32.21


3. Using wget command

wget command is a popular utility to download files over various protocols such as http, https, ssh, ftp and more. It can also be used to ping third party websites. There are many third party website you can ping to get your public IP address.

$ wget -qO- http://ipecho.net/plain | xargs echo
$ wget -qO - icanhazip.com

54.43.32.21


4. Using cURL

cURL is also another popular command to transfer or download files & folders from a server using any of the popular protocols such as http, https, ssh, ftp, and more. Like wget, you can also use it to determine public IP of your server, by pinging third party websites.

$ curl ifconfig.co
$ curl ifconfig.me
$ curl icanhazip.com

54.43.32.21


5. Using Google

You can also find your server’s public ip by visiting google.com and searching for ‘what is my ip’. In this case, you need to log into your server, open a browser, visit google, and enter the above mentioned search string. Then you will get the public IP of your server. If you search for ‘what is my ip’ from your own laptop/workstation, then it will display IP address of your machine and not the server.

That’s it. In this article, we have looked at different ways to determine public IP of server.

Also read:

How to Find Folder Name in Linux
How to Check Open Ports in UFW
How to Debug Shell Script
How to Sort Text File in Python
How to Check UFW Log & Status

Leave a Reply

Your email address will not be published. Required fields are marked *