How to Get Your IPv4 and IPv6 Address Using cURL
Learn how to use cURL commands to check your public IPv4 and IPv6 addresses quickly and easily from the command line.
Airyland
October 28, 2024
If you need to quickly check your public IP addresses from the command line, cURL is a powerful and convenient tool that comes pre-installed on most operating systems. This guide will show you how to use cURL to get both your IPv4 and IPv6 addresses.
Getting Your IPv4 Address
To check your public IPv4 address using cURL, you can use this simple command:
curl -4 ip.network
This command will return your IPv4 address in plain text format. Alternatively, you can use other IP checking services:
curl -4 ifconfig.me
curl -4 icanhazip.com
curl -4 ipinfo.io/ip
Getting Your IPv6 Address
If you want to check your IPv6 address, simply use the -6
flag instead:
curl -6 ip.network
Or try these alternatives:
curl -6 ifconfig.me
curl -6 icanhazip.com
Getting Detailed IP Information
For more detailed information about your IP address, you can use these commands:
# Get JSON format with detailed information
curl ipinfo.io
# Get specific fields
curl ipinfo.io/city
curl ipinfo.io/country
Tips and Troubleshooting
- If you get a connection error with
-6
, your system or network might not support IPv6 - Add the
-s
flag (e.g.,curl -4s ip.network
) to suppress the progress meter - Use
curl -4 -L ip.network
if you need to follow redirects
Conclusion
These cURL commands provide a quick and easy way to check your public IP addresses directly from the terminal. They're especially useful for scripting and automation tasks where you need to programmatically obtain your public IP address.
Remember that different IP checking services might have rate limits or may become unavailable. It's good practice to have multiple services as fallback options in your scripts.