BudiBadu Logo
Samplebadu

cURL by Example: IPv6 Only

Latest

Force cURL to use IPv6. Resolves DNS to IPv6 addresses only.

Code

# Force IPv6 connection
curl -6 https://example.com

# Verify IPv6 connectivity
curl --ipv6 -v https://ipv6.google.com

Explanation

The -6 flag (or --ipv6) forces cURL to exclusively use IPv6 addresses and the IPv6 protocol stack for all network operations. When this flag is active, cURL will resolve hostnames to their IPv6 addresses (AAAA DNS records) and establish connections using IPv6, ignoring any available IPv4 addresses entirely. This is essential for testing IPv6 connectivity, ensuring applications work correctly in IPv6-only environments (increasingly common in mobile networks and modern data centers), verifying dual-stack server implementations, or explicitly using IPv6 for privacy or routing benefits.

IPv6 Connectivity Testing: Using -6 is the definitive way to verify whether you have working IPv6 connectivity. Try curl -6 https://ipv6.google.com or curl -6 https://test-ipv6.com dedicated IPv6 test sites. If this succeeds, your IPv6 is working; if it fails with "Network is unreachable" or "Cannot assign requested address", IPv6 isn't properly configured on your system or network. Many modern mobile carriers use IPv6-only networks with NAT64 translation for IPv4 destinations, making IPv6 testing crucial for mobile app development. Combine with verbose mode to see detailed IPv6 connection information: curl -6 -v https://example.com shows the IPv6 address resolved (like 2606:2800:220:1:248:1893:25c8:1946) and the connection process.

IPv6-Only Environments: Some next-generation networks operate IPv6-only to conserve IPv4 address space (which is exhausted globally) and improve routing efficiency. Testing your applications with -6 ensures they'll work in these environments. Cloud platforms like AWS and Google Cloud increasingly support and encourage IPv6-only workloads for cost and performance reasons. If a hostname doesn't have an IPv6 address (no AAAA record), cURL will immediately fail with a resolution error—this is expected and helps identify services that don't yet support IPv6. For comprehensive dual-stack testing, run tests with both -4 and -6 to ensure your application works regardless of which protocol is used.

IPv6 Benefits and Considerations: IPv6 offers several advantages: a vastly larger address space eliminating NAT necessity, improved routing efficiency through simplified address hierarchy, better multicast support, and mandatory IPSec support in the core protocol (though rarely used). However, IPv6 also has considerations: addresses are longer and more complex (128 bits vs 32 bits), some older firewall and monitoring tools don't properly handle IPv6, and geographic variability in IPv6 deployment means users in some regions may not have it at all. Using -6 during development and testing helps you understand these tradeoffs. Note that even when a system has IPv6 connectivity, not all destinations support it—attempting curl -6 ipv4-only-server.com will fail because the destination lacks IPv6, which is distinct from your local IPv6 being broken.

Code Breakdown

2
-6 restricts DNS resolution to AAAA records.
5
--ipv6 is the long form alias.
All
Fails if no IPv6 address is available.