Categories: Ubuntu

How to Get Public IP from Terminal on Ubuntu 22.04

An Internet Protocol commonly referred as IP address is a numerical representation of a device identification number connected with the Internet. It’s a unique ID that separates one device from another connected to the network thus is different for each device. There are usually two types of IP address; private and public. The private IP address is the address that router assigns to each device while public IP address is assigned by Internet Service Provider (ISP).

In this guide, we will check out how to get public IP from a terminal on Ubuntu 22.04.

Get Public IP from Terminal on Ubuntu 22.04

Sponsored

There are lots of ways to get the IP address of a device which is connected to the Internet. Here we are finding the public IP from the terminal on Ubuntu.

So, let’s discuss several ways through which you can get public IP from the terminal on Ubuntu 22.04.

1: Use Dig command to get public IP address

Dig is an excellent utility that allows Linux users to get public IP from a terminal. The Dig along with the OpenDNS will help you in getting your public IP address on the terminal. The below-given command will be used for this purpose:

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

2: Use host command to get public IP address

You can also find the IP address using the host command that gives you a public IP address through DNS lookups. Run the following host command to get a public IP address:

$ host myip.opendns.com resolver1.opendns.com

3: Use wget command to get IP address

You can also get a public IP address using the wget piped with xarg command which is shown below:

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

Or use the following command incanzip service to get a public IP address:

$ wget -qO- icanhazip.com

There is another service as well that utilizes the wget command to provide you the public IP address:

$ wget -qO- ifconfig.co

Sponsored

You can also utilize wget command with ifconfig.me service to get the public IP address:

$ wget -qO- ifconfig.me | xargs echo

4: Use curl command to get IP address

Another way to get a public IP address from the terminal on Ubuntu is using the curl command. However, first you will need to install curl using the following command:

$ sudo apt install curl

Once curl is installed, you can then use the following command with ifconfig.co to get a public IP address:

$ curl ifconfig.co

You can also use the curl command with ifconfig.me and it will give the public IP address on the terminal:

$ curl ifconfig.me && echo

Or you can use the following curl command with icanhazip service to get public IP on your Ubuntu 2.04 terminal:

$ curl icanhazip.com && echo

Conclusion

The public IP address is an address that you received from the internet service provider. It is always known to the IPS. There are numerous methods to find the public IP address, all are discussed in this guide. Try all those commands as they need a third-party service to provide your public IP address.

Ubuntu Server Admin

Recent Posts

Canonical Releases Ubuntu 25.04 Plucky Puffin

The latest interim release of Ubuntu introduces “devpacks” for popular frameworks like Spring, along with…

2 days ago

Ubuntu 25.04 (Plucky Puffin) Released

Ubuntu 25.04, codenamed “Plucky Puffin”, is here. This release continues Ubuntu’s proud tradition of integrating…

3 days ago

Extended Security Maintenance for Ubuntu 20.04 (Focal Fossa) begins May 29, 2025

Ubuntu released its 20.04 (Focal Fossa) release 5 years ago, on March 23, 2020. As…

3 days ago

Ubuntu 20.04 LTS End Of Life – activate ESM to keep your fleet of devices secure and operational

Focal Fossa will reach the End of Standard Support in May 2025, also known as…

4 days ago

Ubuntu MATE 25.04 Release Notes

Ubuntu MATE 25.04 is ready to soar! 🪽 Celebrating our 10th anniversary as an official…

5 days ago

Ubuntu Weekly Newsletter Issue 887

Welcome to the Ubuntu Weekly Newsletter, Issue 887 for the week of April 6 –…

6 days ago