How To Get Your Public IP Address with Linux Commands

With this tutorial, you will learn how to see and know your public IP address using commands in Linux.

Thanks to the IP address it is possible to identify a computer in the local network, or global, or detect its location thanks to commands such as ping or similar.

IP addresses are cataloged in two types:

  • IPv4 Address: It is currently used and is composed of four octets (8-bit numbers).
  • IPv6 Address: It is the future of IP addresses, based on 128 bits.

These addresses can be assigned as static or private depending on the worst situation today we will focus on how to know the public IP address in Linux since locating the private address is simple.

Get Public IP using DIG Utility

The dig tool (domain information groper) is a command tool created to test DNS name servers.

If you want to be able to verify public IP addresses, we can use the resolution of by executing the following command:

dig +short

Get Public IP using HOST Utility

The host command is an easy-to-use command line utility for carrying out DNS lookups. With the next command we can see the public IP address of the operating system:

host | grep " has" | awk '{print $4}'

Get Public IP using WGET

The wget command is a powerful command line unloader that supports several protocols such as HTTP, HTTPS, FTP and many more.

It can be used with third-party websites to see the public IP address by running any of the following commands:

wget -qO- | xargs echo
wget -qO -

Get Public IP using CURL

The curl command is a favorite command line tool for uploading or downloading files from a server using any of the supported protocols (HTTP, HTTPS, FILE, FTP, FTPS and others).

The following commands will display the public IP address of the system:

Note: In case of not having curl in the system we can install it by executing the following command:
sudo apt install curl

With these simple options, we can discover the public IP address of our network.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *