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:
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.
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
Output:
143.110.250.111
For IPv6
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.
You can specify the IP version as shown in the below example:
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:
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:
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