---
name: ipv6-localhost-bind
description: >
  Use when configuring listen or bind addresses, local health checks, containers,
  or 127.0.0.1 / 0.0.0.0 / :: / localhost. Distinguishes unsafe IPv4-only listen
  from acceptable client dials to 127.0.0.1 when loopback IPv4 remains.
---

# IPv6 localhost and bind

## Instructions

1. Treat **listen** and **connect** separately.
2. For servers: avoid binding only to `127.0.0.1` when local IPv6 clients may use `::1`. Prefer `localhost`, dual loopback (`127.0.0.1` and `::1`), or explicit dual-stack listen per platform API.
3. Prefer `::` (with correct `IPV6_V6ONLY` policy) over `0.0.0.0` when dual-stack or IPv6-only listen is required.
4. Health probes must use a family the listener actually accepts — do not curl an IPv4 literal against an IPv6-only socket.
5. Ensure container `/etc/hosts` and service discovery include IPv6 entries when tests assume `localhost` → `::1`.

## Gotchas

- Binding `127.0.0.1` is IPv4 loopback only; clients resolving `localhost` to `::1` fail even "on the same host."
- Client dials to `127.0.0.1` often still work when IPv4 loopback stays on `lo` (common even on IPv6-mostly hosts). Do not mass-rewrite those without a reason; prioritize listen bugs.
- `0.0.0.0` vs `::` semantics differ by stack and `IPV6_V6ONLY`.
- IPv4-only health checks against IPv6-only services create false "healthy" or false "down" signals.

## Sibling skills

- `ipv6-ready-coding`
- `ipv6-name-resolution`
- `ipv6-code-review`

## Source

- Hub: https://www.peachymango.org/ipv6
- Draft anchor: `#localhost-pitfalls`
- https://datatracker.ietf.org/doc/draft-martin-deploying-ipv6-data-center/
