4 Linux Commands to Get Public IP Address – Best Commands

In this guide from the Orcacore website, you will learn 4 Linux Commands to Get Public IP Address. The public IP address is used to be seen by other machines on the internet. Also, you may need your public IP for some configurations. So we try to show you how you can find your public IP if you don’t have it.

4 Linux Commands to Get Public IP Address

In this guide, we use the 4 Linux Commands to Get Public IP Address in Linux distros:

  • dig Utility
  • host Utility
  • wget command
  • curl command

Proceed to the following steps to see how you can use 4 Linux Commands to Get Public IP Address.

Command 1 – Use Dig utility to Find Public IP Address

Dig utility which stands for domain information groper, is a command-line tool that can be used for probing DNS name servers. You can use this utility to get your public IP in Linux distros by the opendns.com resolver option. First, you must install the Dig utility on your Linux server. To do this, you can use the following commands:

On Debian-based distros, you can run the command below:

sudo apt install dnsutils

And for RHEL-based distros, you can use:

sudo dnf install bind-utils

Now you can run the following dig command to get your public IP:

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

In your output, you will see your public IP address.

Command 2 – Use Host utility to Find Public IP Address

Another command line utility that can help you get your public IP address is the host command. This utility is included in the bind-utils package like the dig command. To find the IP address, you can use the command below:

host myip.opendns.com resolver1.opendns.com
Output
Using domain server:
Name: resolver1.opendns.com
Address: 
Aliases:

myip.opendns.com has address your-ip-address

Command 3 – Find Public IP Address with Wget Command

At this point, you can use the wget command to get your IP. To install this utility, you can use the command below:

On Debian and Ubuntu, you can use:

sudo apt install wget

On RHEL-based distros, you can use:

sudo dnf install wget

Then, use the following wget commands to get your server’s IP address:

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

Command 4 – Use Curl Command to Find the Server IP

Another tool that you can find your server’s IP address is to use the curl command. This tool must be installed by default on your Linux distros. To get the public server IP, you can use the following commands:

# curl ifconfig.co
# curl ifconfig.me
# curl icanhazip.com

By running one of the above commands, you will find your server’s IP address.

Conclusion

At this point, you have learned to use 4 different Linux Commands to get and find your public IP address including dig, host, wget, and curl commands. These methods provide flexibility depending on your needs. Mastering these commands ensures you can always stay informed about your network’s public-facing information, improving overall control and security.

Hope you enjoy it. You may be interested in these articles:

Install Scala 3 in RHEL 9 using Terminal

PHP 8.3 Installation on AlmaLinux 9 / Rocky Linux 9

Hide Files and Directories in Linux Terminal Command Line

Newsletter Updates

Enter your email address below and subscribe to our newsletter

2 Comments

Leave a Reply

Stay informed and not overwhelmed, subscribe now!