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 opendns.com by executing the following command:
dig +short myip.opendns.com @resolver1.opendns.com
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 myip.opendns.com resolver1.opendns.com | grep "myip.opendns.com 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- http://ipecho.net/plain | xargs echo wget -qO - icanhazip.com
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:
curl ifconfig.co curl ifconfig.me curl icanhazip.com
sudo apt install curl
With these simple options, we can discover the public IP address of our network.