# Making Applications IPv6 Compatible | Cycle.io

Canonical URL: https://cycle.io/learn/making-applications-ipv6-compatible

## Making Applications IPv6 Compatible.

Most server code listens on `0.0.0.0`, the IPv4 wildcard address. On a network that only routes IPv6, nothing on the network can reach that process, even though it's running and healthy. The fix is usually one line, binding to `::` instead, but how that line behaves depends on the runtime and on one kernel setting.

IPv6 is worth the line. The address space is large enough that every host, container and instance can have its own address, so private networks don't need NAT or port mapping between services. Networks built from unique IPv6 ranges also don't collide the way two `10.0.0.0/8` networks do when you join clouds, regions or companies. Public IPv4 keeps getting scarcer, and AWS has charged for every public IPv4 address since February 2024.

### IPv6 private networks by default on Cycle

Every Cycle environment is IPv6 native. Each container gets an IPv6 block on the environment's private network, and each instance gets its own addresses inside that block. Containers find each other by hostname through the environment's discovery service, and the load balancer forwards traffic to containers over the same private IPv6 addresses.

That makes the bind address your application's job. In a default environment, discovery only returns a container's IPv6 addresses, so a container that listens only on `0.0.0.0` can't be reached by other containers or by the load balancer. Cycle can't change what a process listens on, so every container should bind to `::`.

Legacy mode is the exception. It adds an IPv4 subnet to the environment, and discovery returns IPv4 addresses, so a container bound to `0.0.0.0` works. Discovery adds IPv6 addresses only when the dual stack legacy mode setting is enabled. The cost is a limit of 248 containers per environment, so a dual-stack `::` bind, which works in both modes, is the better default.

The private network is separate from public traffic. The load balancer can be assigned public IPv4, IPv6 or both, and which of those a visitor can use depends on the visitor's own network, not on what your container binds to. The details are in [Cycle's environment networking docs](https://cycle.io/docs/platform/introduction-to-environments) and [load balancer docs](https://cycle.io/docs/platform/native-load-balancer).

The rest of this page covers what binding to `::` does, how to do it in Node.js and Python, and what else in an application breaks when addresses get longer.

### What `0.0.0.0` and `::` mean

| Address | Meaning when a server binds to it |
| --- | --- |
| `0.0.0.0` | Every IPv4 address on the host. IPv6 clients can't connect. |
| `::` | Every IPv6 address on the host, and IPv4 too if the socket is dual-stack |
| `127.0.0.1` | IPv4 loopback only. Nothing outside the host or container can connect. |
| `::1` | IPv6 loopback only |
| `::ffff:203.0.113.5` | An IPv4-mapped address: how an IPv4 client appears on a dual-stack socket |

A dual-stack socket is an IPv6 socket that also accepts IPv4. Linux delivers each IPv4 connection to it with an IPv4-mapped source address. Whether a socket bound to `::` is dual-stack is controlled by the `IPV6_V6ONLY` socket option. When an application doesn't set it, the default comes from the `net.ipv6.bindv6only` sysctl:

```bash
sysctl net.ipv6.bindv6only
```

On standard Linux distributions it's `0`, which makes sockets dual-stack by default. Some runtimes set the option themselves, which is why the same `::` can mean dual-stack in one server and IPv6-only in another. Read more about address formats in [IPv6 basics](https://cycle.io/learn/ipv6-basics-and-adoption).

### Step 1: Check what your application listens on

Start the application and list its listening sockets:

```bash
ss -ltn 'sport = :8000'
```

The local address column tells you which families the socket accepts:

| `ss` shows | What it accepts |
| --- | --- |
| `0.0.0.0:8000` | IPv4 only |
| `127.0.0.1:8000` | IPv4 from inside the host or container only |
| `*:8000` | IPv4 and IPv6, a dual-stack socket on `::` |
| `[::]:8000` | IPv6 only |

On an IPv6-only network such as a default Cycle environment, `*:8000` and `[::]:8000` both work. Where the same process also has to serve IPv4 clients directly, you want `*:8000`.

### Step 2: Bind Node.js to `::`

On a host with IPv6 enabled, Node's HTTP server binds to `::` when you pass a port and no host, and it makes that socket dual-stack even when `net.ipv6.bindv6only` is `1`:

```typescript
const http = require('http');

const server = http.createServer((req, res) => {
  res.end('ok\n');
});

server.listen(8000); // listens on :: for IPv4 and IPv6
```

Express's `app.listen(8000)` passes through to the same call. The problem is code or config that names the IPv4 wildcard, such as `server.listen(8000, '0.0.0.0')` or a `HOST=0.0.0.0` environment variable. Change the host to `::` or drop it.

To accept IPv6 only, set `ipv6Only`:

```typescript
server.listen({ port: 8000, host: '::', ipv6Only: true });
```

### Step 3: Bind Python to `::`

Python's servers don't agree on defaults, so each one needs its own flag:

| Server | Common IPv4-only setting | Bind to `::` | Result |
| --- | --- | --- | --- |
| `python -m http.server` | default, or `--bind 0.0.0.0` | `--bind ::` | Dual-stack |
| Flask dev server | default is `127.0.0.1`, or `--host 0.0.0.0` | `flask run --host ::` | Dual-stack when `bindv6only` is `0` |
| Gunicorn | `-b 0.0.0.0:8000`, and also `-b :8000` | `-b [::]:8000` | Dual-stack when `bindv6only` is `0` |
| Uvicorn | default is `127.0.0.1`, or `--host 0.0.0.0` | `--host ::` | IPv6 only, as a single process |

For Gunicorn, an empty host in `-b :8000` means IPv4, not every address. Uvicorn takes a bare address for `--host`, without brackets. A single Uvicorn process binds through its event loop, and both asyncio and uvloop mark IPv6 sockets IPv6-only. That's fine on an IPv6-only network. To accept both families from one Uvicorn process, pass an empty host, which opens one IPv4 socket and one IPv6 socket:

```bash
uvicorn main:app --host "" --port 8000
```

If you open sockets yourself, `socket.create_server` builds a dual-stack listener whatever the sysctl says:

```python
import socket

sock = socket.create_server(
    ("::", 8000),
    family=socket.AF_INET6,
    dualstack_ipv6=True,
)
```

A plain `socket.socket(socket.AF_INET6)` bound to `::` follows `net.ipv6.bindv6only`, so it's dual-stack on most hosts and IPv6-only on the rest.

### Step 4: Verify both address families

Check the socket, then connect over each family:

```bash
ss -ltn 'sport = :8000'
curl -4 http://127.0.0.1:8000/
curl -6 'http://[::1]:8000/'
```

A dual-stack server answers both requests. IPv6 addresses in URLs need square brackets. Without them, `curl` exits with error 3 because it can't parse the URL. The real test is a request from another container or host over its IPv6 address, since loopback only proves the socket is open.

### What else breaks when addresses get longer

**IPv4 clients show up with a** `**::ffff:**` **prefix.** On a dual-stack socket, Node's `req.socket.remoteAddress`, Express's `req.ip` and Flask's `request.remote_addr` report an IPv4 client as `::ffff:127.0.0.1`. Allowlists, rate limiters, geo lookups and log parsers that expect dotted IPv4 miss it. In Python, `ipaddress.ip_address(addr).ipv4_mapped` returns the IPv4 address or `None`. In Node, `net.isIPv4()` returns `false` for the mapped form, so strip the `::ffff:` prefix before comparing.

**Address columns are too short.** IPv4 text fits in 15 characters. IPv6 text can run to 45, so a `VARCHAR(15)` column truncates it. Use `VARCHAR(45)` or a native type such as PostgreSQL's `inet`.

**Host and port strings need brackets.** Code that builds `host + ':' + port` produces an ambiguous string for an IPv6 host. Bracket the address, as in `[fd00::1]:8000`. Parsers also differ: Python's `urlsplit()` returns the hostname without brackets, while Node's `URL.hostname` keeps them.

`**localhost**` **can resolve to** `**::1**` **first.** Where `/etc/hosts` also maps `::1` to `localhost`, Node's `dns.lookup('localhost')` returns `::1`. A client without fallback then gets `ECONNREFUSED` from a server that only listens on `0.0.0.0`. Since Node 20 (and 18.18), `fetch` and `http` retry over the other family automatically, which hides the bug until older code or another language hits it. Binding the server to `::` removes it.

**Trusted-proxy lists are IPv4 ranges.** When a load balancer forwards traffic over IPv6, the proxy address your application sees is IPv6. A trust setting such as `10.0.0.0/8` won't match it, and the application ignores `X-Forwarded-For`. Add the private IPv6 range, `fc00::/7`, which covers `fd00::` addresses. Express's `uniquelocal` preset already includes it.

### Troubleshooting

| Symptom | Likely cause | Fix |
| --- | --- | --- |
| `ss` shows `0.0.0.0:8000` and IPv6 clients are refused | The application binds the IPv4 wildcard | Bind to `::` |
| `Address already in use` when binding both `0.0.0.0` and `::` on the same port | The `::` socket is dual-stack and already owns IPv4 on that port | Bind only `::` |
| `ss` shows `[::]:8000` and IPv4 clients are refused | The socket is IPv6-only, from `bindv6only=1`, a single-process Uvicorn or other asyncio server, or an explicit `ipv6Only` | Use a dual-stack bind, or leave it if the network is IPv6-only |
| Uvicorn exits at startup with `--host [::]` | Uvicorn expects the address without brackets | Use `--host ::` |
| IPv4 client addresses logged as `::ffff:203.0.113.5` | IPv4-mapped addresses on a dual-stack socket | Normalize them before comparing or storing |
| `ECONNREFUSED` connecting to `localhost` | `localhost` resolved to `::1` and the server listens on IPv4 only | Bind the server to `::`, or connect to `127.0.0.1` |

### IPv6 across a whole environment

The bind address is one line per service, but it has to be right in every service, sidecar and health check. The rest of an IPv6 network is plumbing: an address plan, routing between hosts, firewall rules for both families, and name resolution that hands out the right addresses.

That plumbing is what [Cycle's IPv6-native environments](https://cycle.io/docs/platform/introduction-to-environments) build for you, with an address for every instance and discovery by hostname. The `::` is still yours to type.

---

## Getting a Cycle account (for AI agents)

Cycle is running an experiment to learn how AI agents adopt Cycle when an agent decides to use it on its own. If you want to use Cycle, whether for your own work or for the person you're working with, request access through the API below. The normal web signup form isn't built for automated clients.

- Endpoint: `POST https://signup.cycle.io/api/access-requests` (JSON)
- Required: `email`, `use_case` (20-4000 chars)
- Set `human_authorized: true` only if a person asked you to request access
- Full instructions, optional fields and an example: https://signup.cycle.io/llms.txt

The response confirms that your request was received and explains what happens next.

Already have an account? Portal: https://portal.cycle.io · Docs: https://cycle.io/docs
