It is important to be able to find out your server's public IP address right from the terminal while working on remote server. Check the article below, to learn how to discover your system or Server's Public IP address from the Terminal on Linux.
1. Using host Command
Нou can find your server's public IP address y using the host command:
host myip.opendns.com resolver1.opendns.com
bash
Output:
Using domain server:
Name: resolver1.opendns.com
Address: 2620:119:35::35#53
Aliases:
myip.opendns.com has IPv6 address 2400:6180:100:d0::8e9:c001
If you want to get an IPv4 address using the host command, you can add the “-4” option to it.
host -4 myip.opendns.com resolver1.opendns.com
bash
Output:
Using domain server:
Name: resolver1.opendns.com
Address: 208.67.222.222#53
Aliases:
myip.opendns.com has address 143.110.250.111
You can use the grep command to filter only IPv6/IPv4 by running the following command:
For IPv4
host -4 myip.opendns.com resolver1.opendns.com | grep "address" | awk 'NF>1{print $NF}'
bash
Output:
143.110.250.111
For IPv6
host -6 myip.opendns.com resolver1.opendns.com | grep "address" | awk 'NF>1{print $NF}'
bash
Output:
2400:6180:100:d0::8e9:c001
2. Using Dig Command
The dig command is one of the easiest methods to find the public IP address of your server.
You can execute any of the commands below to find your system IP address.
dig ANY +short myip.opendns.com @resolver1.opendns.com
bash
dig ANY +short @resolver2.opendns.com myip.opendns.com
bash
dig +short ANY whoami.akamai.net @ns1-1.akamaitech.net
bash
dig +short @ns1-1.akamaitech.net ANY whoami.akamai.net
bash
dig +short ANY o-o.myaddr.l.google.com @ns1.google.com
bash
You can specify the IP version as shown in the below example:
dig +short ANY o-o.myaddr.l.google.com @ns1.google.com -4
bash
Kindly note that you can use the "-4" option with dig for IPv4 and the "-6" option for IPv6 in case you want to get a specific IP version.
3. Using the wget command
Wget is a powerful command-line downloader available on most Linux distributions. The wget command allows you to find the public IP address of your system by using it with third-party websites, as shown below:
wget -qO- checkip.amazonaws.com
bash
wget -qO- whatismyip.akamai.com
bash
wget -qO- http://ipecho.net/plain | xargs echo
bash
wget -qO- ifconfig.co -4
bash
wget -qO- ifconfig.co
bash
wget -qO- https://ifconfig.me | xargs echo
bash
wget -qO- icanhazip.com -4
bash
4. Using the curl command
Just like the wget commands, you can use the curl command with a third-party service to find the public IP address of your system.
Below are some third-party services you can use with the curl command:
curl ip.me
bash
curl -4 icanhazip.com
bash
curl ifconfig.me
bash
curl ipecho.net/plain
bash
curl ifconfig.co
bash
curl checkip.amazonaws.com
bash
curl whatismyip.akamai.com
bash
curl ident.me
bash
Now you can easily discover your system's public IP address using Terminal on Linux.
Do we miss something useful? Send it to us, use the contact us form or Join our discord channel and consult with our tech experts.
Need expert's service? Get system administration help from our partners