When working with IPv6, checking your public address isn't as straightforward as IPv4. Many services that work well for IPv4 (like ipinfo.io) may not properly return IPv6 addresses or may prioritize IPv4 responses. This is because:
- Dual-stack networks may prefer IPv4 for compatibility
- Some API endpoints aren't IPv6-enabled
- Network configurations might not route IPv6 traffic properly
Here are several command-line approaches to accurately detect your public IPv6 address:
Method 1: Using Specialized IPv6 Services
curl -6 icanhazip.com
curl -6 ifconfig.co
curl -6 ident.me
Method 2: DNS-Based Query
dig +short AAAA myip.opendns.com @resolver1.opendns.com
Method 3: Network Interface Inspection (Linux)
ip -6 addr show | grep inet6 | grep -v ::1 | grep -v fe80
If you're not getting IPv6 responses:
- Ensure your network supports IPv6 (test with
ping6 ipv6.google.com
) - Try forcing IPv6 with the
-6
flag in curl - Check for IPv6 firewalls blocking outbound requests
For scripting purposes, here's a robust solution that falls back to IPv4:
#!/bin/bash
IPV6=$(curl -6 --connect-timeout 5 -s icanhazip.com 2>/dev/null)
if [ -z "$IPV6" ]; then
IPV4=$(curl -4 --connect-timeout 5 -s icanhazip.com 2>/dev/null)
echo "Public IPv4: $IPV4"
else
echo "Public IPv6: $IPV6"
fi
While checking IPv4 addresses is straightforward with services like ipinfo.io
, IPv6 detection requires different approaches because:
- Many ISPs still provide IPv4 by default
- Some API endpoints don't listen on IPv6
- Dual-stack configurations may prioritize IPv4
Method 1: Using Dedicated IPv6 Services
The most accurate way is to query IPv6-specific services:
# Linux/Mac
curl -6 ifconfig.co
curl -6 icanhazip.com
curl -6 api64.ipify.org
# Windows PowerShell
(Invoke-WebRequest -Uri "http://ipv6.icanhazip.com" -UseBasicParsing).Content.Trim()
Method 2: Forcing IPv6 Connection
Some services support both protocols but need explicit IPv6 forcing:
curl --ipv6 ipinfo.io/ip
curl -6 https://ident.me
Method 3: Local Interface Inspection
To check all assigned IPv6 addresses on your machine:
# Linux
ip -6 addr show | grep inet6
# MacOS
ifconfig | grep inet6
# Windows
netsh interface ipv6 show addresses
Verify your system actually has IPv6 connectivity:
ping6 ipv6.google.com
traceroute6 example.com
- If commands hang, your ISP might not provide IPv6
- Try different DNS servers (Google's 2001:4860:4860::8888)
- Check firewall rules for ICMPv6 blocking
Here's a bash function to test multiple IPv6 endpoints:
get_ipv6() {
endpoints=(
"ifconfig.co"
"icanhazip.com"
"ipv6.ident.me"
"v6.ident.me"
)
for endpoint in "${endpoints[@]}"; do
echo "Testing $endpoint:"
curl -6 --connect-timeout 3 "https://$endpoint" || echo "Failed"
echo
done
}