The curl command on Linux systems is commonly used to download and upload files to or from a remote server. Another interesting thing we can use it for is to determine the public IP address of our system.
To do this, we can use curl to query websites that are configured to do nothing more than return the IP address of whichever system is connecting to it. This is one of the quickest and easiest ways to get your public IP address on the Linux command line. Follow along with us below and we’ll show you a few examples.
In this tutorial you will learn:
- How to install curl on major Linux distros
- How to use curl to get public IP address
|Category||Requirements, Conventions or Software Version Used|
|System||Any Linux distro|
|Other||Privileged access to your Linux system as root or via the
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Although curl is a common utility, it’s not included on every single Linux distro. Specifically, it may be missing from more desktop oriented distros. Just in case it’s not already installed, you can use the appropriate command below to install it through your system’s package manager.
$ sudo apt install curl
$ sudo dnf install curl
$ sudo pacman -S curl
Use curl to get public IP address
There are many websites that have been configured to show someone’s public IP address. Use one or more of the following examples below to determine yours.
- This site will also work with the
-6curl options, if you need to retrieve your IPv4 or IPv6 address specifically.
$ curl icanhazip.com OR $ curl -4 icanhazip.com OR $ curl -6 icanhazip.com
$ curl ifconfig.me
$ curl api.ipify.org
$ curl bot.whatismyipaddress.com
$ curl ipinfo.io/ip
$ curl ipecho.net/plain
Of course, other sites also exist that can do the same thing, but these should be enough to cover your needs. In the future, some sites may stop working and new ones will fill their place, so keep in mind that any website on the list may not be permanent.
In this guide, we saw how to retrieve the public IP address of a system by using curl on the Linux command line. This relies on third party public websites to show us our IP address, but it proves to be one of the quickest and easiest ways to see our public IP on the command line.