The curl command on Linux systems serves as a versatile tool for downloading and uploading files to remote servers. Beyond file transfers, you can use curl to quickly determine your system’s public IP address. This method connects to specialized websites that return only your IP address – making it one of the fastest ways to check your public IP from the command line. This tutorial will show you several reliable methods to get your public IP address using curl.
In this tutorial you will learn:
- How to install curl on major linux distributions
- Multiple methods to find your public IP address with curl
- Advanced options for IPv4 and IPv6 addresses
- Tips for automating IP address checks

| Category | Requirements, Conventions or Software Version Used |
|---|---|
| System | Any Linux distribution |
| Software | curl utility |
| Other | Standard user privileges (root access only required for curl installation) |
| Conventions | # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
Installing Curl for IP Address Queries
While curl comes pre-installed on many Linux systems, some distributions (especially desktop-focused ones) might not include it by default. Before you can check your IP address with curl, make sure it’s installed on your system using the appropriate command below.
Using apt install curl on Debian-based systems is straightforward.
To install curl on Ubuntu, Debian, and Linux Mint:
$ sudo apt install curl
On CentOS, Fedora, AlmaLinux, and Red Hat curl can be installed:
$ sudo dnf install curl
To install curl on Arch Linux and Manjaro:
$ sudo pacman -S curl
How to Get Your Public IP Address with Curl
Several websites are designed specifically to return your public IP address when accessed. These services make it easy to check your external IP from the command line. Here are the most reliable options:
- icanhazip.com – This versatile service supports both IPv4 and IPv6 addresses. You can use the
-4or-6options to get specific IP versions:$ curl icanhazip.com $ curl -4 icanhazip.com $ curl -6 icanhazip.com
- ifconfig.me – A simple and reliable service:
$ curl ifconfig.me
- ipify.org – Fast API-based service that’s great for automation:
$ curl api.ipify.org
- whatismyipaddress.com – Bot-friendly endpoint:
$ curl bot.whatismyipaddress.com
- ipinfo.io – Provides IP information services:
$ curl ipinfo.io/ip
- ipecho.net – Returns plain text IP address:
$ curl ipecho.net/plain
- httpbin.org – Testing service with IP endpoint:
$ curl httpbin.org/ip
- checkip.amazonaws.com – Amazon’s reliable IP checking service:
$ curl checkip.amazonaws.com
Learn more about HTTP testing services and explore additional IP address tools for comprehensive network diagnostics.
Advanced Curl Options for IP Queries
Curl offers several options to customize your IP address requests and make them more reliable or suitable for specific use cases.
Timeout and Retry Options
$ curl --connect-timeout 10 icanhazip.com $ curl --max-time 15 ifconfig.me $ curl --retry 3 api.ipify.org
Silent Mode and Output Formatting
$ curl -s icanhazip.com $ curl -s ifconfig.me | tr -d '\n'
IPv4 and IPv6 Specific Queries
$ curl -4 icanhazip.com # Force IPv4 $ curl -6 icanhazip.com # Force IPv6
Troubleshooting Common Issues
If you’re having trouble getting your IP address with curl, here are some solutions to try:
- Network connectivity: Verify your internet connection is working
- Firewall restrictions: Check if outbound HTTP/HTTPS requests are blocked
- Service availability: Try multiple services as some may be temporarily unavailable
- DNS issues: Test with alternative DNS servers if domain resolution fails
Security Considerations
When using external services to check your IP address, keep these security aspects in mind:
- External services can log your IP address and request information
- Always use HTTPS versions of services when available for encrypted communication
- Avoid using untrusted or unknown IP checking services
- Consider running your own IP checking service for sensitive environments
- Be cautious about automated scripts that frequently check your IP
For enhanced security, explore DNS security practices and consider to learn more about various VPN protocols for additional privacy protection.
Automating IP Address Checks
You can incorporate these curl commands into scripts for automated IP monitoring. Here’s a simple example:
#!/bin/bash # Simple script to check and log public IP IP=$(curl -s icanhazip.com) echo "$(date): Public IP is $IP" >> ip_log.txt
Closing Thoughts
This guide showed you several ways to get your public IP address using curl on Linux systems. While these methods rely on third-party websites, they’re among the fastest and most convenient ways to check your external IP from the command line. The various services listed provide backup options, so you’ll always have a working method even if one service goes down.
Keep in mind that your public IP address may change depending on your internet provider’s setup, making these techniques useful for ongoing network troubleshooting and system administration. For additional resources, check out the curl manual pages and explore other network diagnostic tools.