Get Public IP from Terminal on Ubuntu 22.04 Example

Jul 15, 2022

.

Admin

Get Public IP from Terminal on Ubuntu 22.04 Example

Hi Guys,

This tutorial shows you Get Public IP from Terminal on Ubuntu 22.04 Example. I would like to show you How to Get Public IP from Terminal on Ubuntu 22.04?. In this article, we will implement a 4 Ways to Find Server Public IP Address in Linux Terminal. Here you will learn Methods to Find Your Public IP address in Ubuntu 20.04 LTS ?. Follow bellow tutorial step of Command to Get the Public IP address of a router.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Step 1: Use Dig command to get public IP address


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

Step 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

Step 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

Step 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

To construct the virtual environment, run the following command inside the directory:

$ 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

#Ubuntu