Linux

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

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:

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:

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

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.

Source link

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button