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 myip.opendns.com @resolver1.opendns.com
As you can see, the output of the “dig” command displayed “18.104.22.168” 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 myip.opendns.com resolver1.opendns.com
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- http://ipecho.net/plain | xargs echo
Using wget command with icanhnazip.com
Use the “icanhazip.com” zip service with wget command to get the Public IP address as follow:
$ wget -qO- icanhazip.com
Using wget command with ifconfig.co
There is another service “ifconfig.co” is used to get the Public IP address utilizing the wget command. Execute the given-below command:
$ wget -qO- ifconfig.co
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 ifconfig.co
The curl is installed with using the provided command the following command with “ifconfig.co” to get the Public IP address:
$ curl ifconfig.co
Using curl command with icanhazip.com
Use the “icanhazip.com” service to view your device Public IP address with the curl command:
$ curl icanhazip.com && 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 myip.opendns.com @resolve1.opendns.com” command, host “$ host myip.opendns.com resolver1.opendns.com” command, wget “$ wget -qO- http://ipecho.net/plain | 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.
The Best Linux Tutorials Website