How to Find Public IP Address in Linux From Command Line

In the vast world of Linux, having a reliable way to identify your public IP address is crucial for various networking tasks. Whether you’re troubleshooting connectivity issues, configuring a server, or setting up remote access, knowing your public IP address can be a lifesaver.

In this blog post, we’ll explore several simple and effective methods to find your public IP address from the command line in a Linux environment. So, let’s dive in!

Method 1: Find Public IP address using Curl Command

One of the easiest and most popular ways to retrieve your public IP address is by leveraging external web services like “” or “” or “” These services provide your public IP address in response to a simple HTTP request. Here’s how to use “curl” to fetch your public IP:

First, open your terminal application. You can do this by searching for “Terminal” in the application launcher or by pressing “Ctrl + Alt + T” (depending on your Linux distribution).

Type the following command and hit Enter:

$ curl
$ curl
$ curl

This will send a request to the “” service, and you will receive your public IP address as a response.


Method 2: Get Public IP Address via ‘dig’ Command

The ‘dig’ command is another valuable tool for querying DNS-related information, including your public IP address. To use ‘dig’ for this purpose, follow these steps:

Open the terminal and run following dig command

$ dig +short


The ‘dig’ command queries the ‘’ domain at the ‘’ DNS server, which responds with your public IP address.

Method 3: Download Public IP Address via ‘wget’ & ‘’

In this method, we’ll use the ‘wget command‘ to download our IP address information from the ‘’ service. Here’s how:

Type the following command and hit Enter:

$ wget -qO - --timeout=20
$ publicip=$(wget -qO - --timeout=20)
$ echo $publicip

The ‘-qO’ flag ensures a quiet output, and ‘’ provides your public IP address as plain text.



Knowing how to find your public IP address in Linux using the command line is an essential skill for any Linux user. Whether you’re a system administrator, developer, or just an everyday user, these methods will help you quickly and effortlessly retrieve your public IP address. From troubleshooting network issues to securing your connections, this information will prove valuable in various scenarios. So, the next time you need to access your public IP address, remember these command-line techniques to get the job done swiftly!

Also Read: Learn IP Command to Manage Networking on Linux

Leave a Comment

fourteen + two =