4 Ways to Find Server Public IP Address in Linux Terminal

In computer networking, an IP (Internet Protocol) address is a numerical identifier assigned permanently or temporarily to every device connected to a network that uses the Internet Protocol for communication. Its two major functions are to identify a network or host on a network and also serve for location addressing.

Read Also: How to Set Static IP Address and Configure Network in Linux

There are currently two versions of IP addresses: IPv4 and IPv6, which can either be private (viewable within an internal network) or public (can be seen by other machines on the Internet).

Additionally, a host can be assigned a static or dynamic IP address depending on the network configurations. In this article, we will show you 4 ways to find your Linux machine or server public IP address from the terminal in Linux.

1. Using dig Utility

dig (domain information groper) is a simple command line utility for probing DNS name servers. To find your public IP addresses, use the opendns.com resolver as in the command below:

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

120.88.41.175

2. Using host Utility

host command is an easy-to-use command line utility for carrying out DNS lookups. The command below will help to display your systems public IP address.

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

120.88.41.175

Important: The next two methods employ third party websites to display your IP address on the command line as described below.

3. Using wget Command Line Downloader

wget is a powerful command line downloader that supports various protocols like HTTP, HTTPS, FTP and many more. You can use it with third party websites to view your public IP address as follows:

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

120.88.41.175

4. Using cURL Command Line Downloader

curl is a popular command line tool for uploading or downloading files from a server using any of the supported protocols (HTTP, HTTPS, FILE, FTP, FTPS and others). The following commands displays your public IP address.

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

120.88.41.175

That’s It! You may find these following articles useful to read.

  1. 5 Linux Command Line Based Tools for Downloading Files and Browsing Websites
  2. 11 Ways to Find User Account Info and Login Details in Linux
  3. 7 Ways to Determine the File System Type in Linux (Ext2, Ext3 or Ext4)

That’s all! If you have any questions or other methods to share in relation to this topic, use the feedback form below to write back to us.

Hey TecMint readers,

Exciting news! Every month, our top blog commenters will have the chance to win fantastic rewards, like free Linux eBooks such as RHCE, RHCSA, LFCS, Learn Linux, and Awk, each worth $20!

Learn more about the contest and stand a chance to win by sharing your thoughts below!

Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

13 Comments

Leave a Reply
  1. I found ipaddress.ai to be the easiest one.

    You don’t need to parse/grep/cut anything, you can simply run;

    curl ipaddress.ai
    
    Reply
    • @Jackie,

      I appreciate the recommendation! ipaddress.ai does seem straightforward to know the IP address of the system.

      Thanks for sharing this handy tool!

      Reply
  2. I like option 2 but grep doesn’t need to be part of it.

    You can shorten it to:

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

    *Cheers*

    Reply
    • @Mike

      Here, we explained how you can get your own public IP address, say on a laptop, from the terminal. Sometimes a ping doesn’t show your public IP address, and nslookup is not appropriate for this, unless you are finding the IP address associated to a domain name.

      Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.