{
    "slug": "ipv6_basics",
    "term": "IPv6 for Web Developers",
    "category": "networking",
    "difficulty": "intermediate",
    "short": "The successor to IPv4 with 128-bit addresses — effectively unlimited address space, mandatory in modern infrastructure, with some practical differences for web applications.",
    "long": "IPv4 has ~4 billion addresses, exhausted. IPv6 provides 340 undecillion addresses. Format: eight groups of four hex digits (2001:0db8:85a3::8a2e:0370:7334). Key differences for web devs: IPv6 addresses in URLs need brackets (http://[::1]:8080), socket code needs AF_INET6, nginx and PHP need explicit IPv6 configuration. Dual-stack deployments support both. The PHP_EOL of IPv4-only hosting is approaching — major cloud providers require explicit IPv4 which costs extra; IPv6 is free.",
    "aliases": [
        "IPv6",
        "dual-stack",
        "IPv4 exhaustion"
    ],
    "tags": [
        "networking",
        "infrastructure",
        "ipv6"
    ],
    "misconception": "IPv6 is optional for modern applications — AWS now charges for IPv4 addresses; IPv6-only or dual-stack is increasingly the default and required for cost efficiency.",
    "why_it_matters": "IPv4 addresses now cost money on AWS and other clouds — IPv6 is the path to lower infrastructure costs and future-proof networking.",
    "common_mistakes": [
        "Hardcoding IPv4 assumptions — code that uses AF_INET exclusively breaks on IPv6-only hosts.",
        "Not bracketing IPv6 addresses in URLs — http://::1:8080 is invalid; must be http://[::1]:8080.",
        "Firewall rules that only block IPv4 — attackers on IPv6 bypass IPv4-only rules.",
        "Not testing dual-stack deployments — IPv4 and IPv6 code paths can behave differently."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "tcp_ip_model",
        "dns_resolution",
        "cloud_computing_models"
    ],
    "prerequisites": [
        "tcp_ip_model",
        "dns_record_types",
        "linux_networking_tools"
    ],
    "refs": [
        "https://www.rfc-editor.org/rfc/rfc2732"
    ],
    "bad_code": "// IPv4-only socket — breaks on IPv6-only infrastructure:\n$socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);\nsocket_bind($socket, '0.0.0.0', 8080); // IPv4 only\n\n// IPv6 address in URL without brackets — invalid:\n$url = 'http://' . $ipv6Addr . ':8080/api'; // Broken",
    "good_code": "// Dual-stack: bind to all interfaces including IPv6:\n$socket = socket_create(AF_INET6, SOCK_STREAM, SOL_TCP);\nsocket_setopt($socket, IPPROTO_IPV6, IPV6_V6ONLY, 0); // Dual-stack\nsocket_bind($socket, '::', 8080);\n\n// IPv6 in URL needs brackets:\n$url = 'http://[' . $ipv6Addr . ']:8080/api'; // Correct",
    "quick_fix": "Add AAAA DNS records alongside A records; ensure Nginx listens on [::]:443; PHP curl handles IPv6 automatically when the OS supports it",
    "severity": "low",
    "effort": "medium",
    "created": "2026-03-15",
    "updated": "2026-04-19",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/ipv6_basics",
        "html_url": "https://codeclaritylab.com/glossary/ipv6_basics",
        "json_url": "https://codeclaritylab.com/glossary/ipv6_basics.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[IPv6 for Web Developers](https://codeclaritylab.com/glossary/ipv6_basics) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/ipv6_basics"
            }
        }
    }
}