Get Public IP from Terminal on Ubuntu 22.04

Public IP address is also known as an Internet Protocol address that is utilized to uniquely identify your device in between the list of other devices. Basically, it is a numerical representation of your device that is assigned by an Internet Service Provider to separate your device from other devices which are connected to the internet or local network.

This blog will teach you the procedure of getting Public IP on Ubuntu 22.04 Terminal.

Getting Public IP on Ubuntu 22.04 Terminal

There exist many methods to fetch the Public IP address of your device that is connected to the internet. Here, we will discuss some majorly used commands for getting the Public IP address on Ubuntu 22.04 using the terminal. So, let’s start!

Method 1: Get Public IP using dig Command

In Linux-based systems such as Ubuntu 22.04, the “dig” (Domain Information Groper) command permits the users to fetch the information related to DNS records, name servers, and mail exchanges. More specifically, you can utilize this command for getting Public IP from the terminal.

Run the given-below “dig” command for the specified purpose:

$ dig +short

As you can see, the output of the “dig” command displayed “” as our Public IP:

The next section will demonstrate the method to get Public IP from the terminal using “host command” on ubuntu 22.04.

Method 2: Get Public IP using host Command

host” command is commonly used for performing DNS lookups, finding the domain name, and converting it into an IP address on Ubuntu 22.04. You can also utilize this command to view the public IP address of your device.

Execute the following “host” command on the terminal to check your Public IP address terminal:

$ host

Now, check out the third method to get Public IP from terminal using “wget” command on ubuntu 22.04.

Method 3: Get Public IP using wget Command

To download the files using FTP, HTTPS, and HTTP protocols “wget” command-line is used. You can also fetch the Public IP address through the given-below command.

Run the given below “wget” command in combination with “xargs” to view your Public IP address:

$ wget -qO- | xargs echo

Using wget command with

Use the “” zip service with wget command to get the Public IP address as follow:

$ wget -qO-

Using wget command with

There is another service “” is used to get the Public IP address utilizing the wget command. Execute the given-below command:

$ wget -qO-

Let’s take a look at another useful command to get Public IP from the terminal.

Method 4:Get Public IP using curl Command

curl is a command-line tool that is used for downloading or uploading the files from the server through any supported protocol including HTTP, HTTPS, FTP, FTPS, and others. It is also utilized to get the Public IP.

To do so, first, you need to install the curl through the following command:

$ sudo apt install curl

Now moves to the next instruction.

Using curl command with

The curl is installed with using the provided command the following command with “” to get the Public IP address:

$ curl

Using curl command with

Use the “” service to view your device Public IP address with the curl command:

$ curl && echo

How to uninstall curl with its dependencies from Ubuntu 22.04

If you want to uninstall the curl command with its dependencies from your Ubuntu 22.04 system, utilize the given below command:

$ sudo apt-get autoremove curl

Following output indicates that the curl is successfully removed from Ubuntu 22.04:

That was the brief process related to Get Public IP from Terminal on Ubuntu 22.04.


There are numerous ways of getting Public IP on Ubuntu 22.04 Terminal. You can find using the dig “$ dig +short” command, host “$ host” command, wget “$ wget -qO- | xargs echo” command, or curl command using different services. In this post, we have learned multiple ways to Get Public IP on Ubuntu 22.04 Terminal.