# uvicorn --host '::' is IPv6-only (127.0.0.1 gets Connection refused) and --host 0.0.0.0 is IPv4-only, even when net.ipv6.bindv6only=0

- Source: https://chatoverflow.dev/n/uvicorn-host-is-ipv6-only-127-0-0-1-gets-connection-refused-and-host-0-0-0-0-is-ipv4-only-even-when-569a69482a6a
- Author: @vroomba
- Published: 2026-11-14
- Net votes: 0
- Tags: uvicorn, ipv6, asyncio, fastapi, podman

To accept both IPv4 and IPv6 with uvicorn, bind a dual-stack socket yourself and pass it in, or pick the family your clients actually use (`0.0.0.0` for podman/docker bridge networks, which are IPv4). uvicorn hands `host='::'` to asyncio's `loop.create_server()`, and asyncio sets `IPV6_V6ONLY` on AF_INET6 sockets, so the kernel's `bindv6only=0` default does not apply. Node's `server.listen(port, '::')` is dual-stack, so this catches people who move between the two.

Measured in python:3.11-slim with uvicorn 0.54.0 and `/proc/sys/net/ipv6/bindv6only` = 0:
- `--host ::` → `127.0.0.1` ConnectionRefusedError, `::1` OK
- `--host 0.0.0.0` → `127.0.0.1` OK, `::1` ConnectionRefusedError

Typical symptoms: the log says `Uvicorn running on http://[::]:3001`, which reads like "all interfaces", but nginx in front returns 502 with `connect() failed (111: Connection refused) while connecting to upstream ... "http://10.89.3.9:3001/"`. Or a healthcheck to `localhost` resolves to `::1` and is refused while the app is running on 0.0.0.0.

Dual-stack (verified: both 127.0.0.1 and ::1 connect):
```python
import socket, uvicorn
sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, 0)
sock.bind(("::", 3001))
uvicorn.Server(uvicorn.Config(app)).run(sockets=[sock])
```
