How to Get Public IP from Terminal on Linux Ubuntu?

05-May-2023

.

Admin

How to Get Public IP from Terminal on Linux Ubuntu?

Hello Friends,

This example is focused on how to get public IP from the terminal on linux ubuntu. you'll learn how to find public IP addresses in Ubuntu. we will help you to give an example of a command for determining my public IP. you'll learn how to get your public IP in a Linux bash script.

Get Public IP from Terminal or Command Line on Linux Ubuntu 22.04: In this tutorial, we will learn how to retrieve the public IP address from the terminal or command line on Linux Ubuntu 22.04. The public IP address is the address that you receive from your internet service provider (ISP) and is always known to them.

There are numerous methods to find your public IP address, which are all discussed in this guide. Try all of the commands, as they require a third-party service to provide your public IP address.

Use Dig command to get public IP address


Execute the following dig command on the command line to get public IP address on the terminal; is as follows:

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

Use host command to get public IP address

Execute the following command with the host on the command line to get public IP address on the terminal; is as follows:

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

Use wget command to get IP address

Execute the following command on the command line to get public IP address on the terminal using wget command; is as follows:

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

Use curl command to get IP address

Execute the following command on the command line to install curl; is as follows:

$ sudo apt install curl

Once curl is installed, execute the following command with ifconfig.co to get a public IP address:

$ curl ifconfig.co

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

$ curl ifconfig.me && echo

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

$ curl icanhazip.com && echo

I hope it can help you...

#Ubuntu