SSD Nodes Learn Hosting plans →
Guides Matt ConnorBy Matt Connor

UFW and IPv6: the open door on your VPS

Your cloud firewall or handwritten iptables may only cover IPv4, leaving services wide open on IPv6. See why it happens on a VPS and how to close the gap.

The IPv6 firewall trap in one sentence

Your firewall protects IPv4. Your VPS may also have a public IPv6 address, and many services listen on it by default. If your firewall only covers IPv4, or if you lean on a cloud firewall that filters IPv4 only, those services can be reachable over IPv6 while your IPv4 side looks locked down. You test a port with curl, see a refused connection, and feel safe. An attacker connects to the same port over IPv6 and walks in.

This guide shows where that gap comes from on a normal Ubuntu 24.04 VPS, how to see exactly what you are exposing, and how to close it. UFW is not the villain here. On a modern Ubuntu install UFW already handles IPv6 once you enable it. The exposure comes from the layers around it, and from services you did not know were listening.

Why your VPS is on IPv6 in the first place

Many VPS providers give a server a public IPv6 address, often a whole /64, alongside its IPv4 address. At some providers it is optional rather than assigned by default: DigitalOcean's Droplet creation docs, checked on 2026-11-23, say that in the Control Panel "By default, Public IPv4 address is selected and Public IPv6 address is cleared." So do not assume either way. Check yours:

ip -6 addr show scope global
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> ...
    inet6 2001:db8:2a::1/64 scope global

If the command prints nothing, the server has no global IPv6 address yet, and the rest of this guide matters the day you add one. The 2001:db8:2a::1 in this guide is a placeholder from 2001:db8::/32, a prefix reserved for documentation that is never routed on the internet. An address printed with scope global is not proof of internet reachability: unique local addresses in fc00::/7 also have global scope and are not expected to be routed on the global internet. Confirm that your provider routes the address publicly, then test reachability from outside. Now look at what is listening:

sudo ss -tlnp
State   Recv-Q  Local Address:Port   Process
LISTEN  0       0.0.0.0:22           sshd
LISTEN  0       [::]:22              sshd
LISTEN  0       127.0.0.1:5432       postgres
LISTEN  0       [::]:8080            docker-proxy

Read the Local Address column closely. 0.0.0.0:22 means "listen on every IPv4 address." [::]:22 means "listen on every IPv6 address." 127.0.0.1:5432 is bound to loopback and is not public at all, so the Postgres line is safe. The two [::] lines listen on every IPv6 address, but routing and firewall rules still determine who can connect; the docker-proxy one is the kind you forget you started.

On Linux a :: socket accepts IPv4 as well when IPv4-mapped addresses are enabled, which is the kernel default; applications can override that with IPV6_V6ONLY. Check each service's listeners rather than assuming a fresh server answers on both stacks everywhere. A firewall that sees only one stack leaves the other stack's public listeners unprotected by those rules.

Where the IPv6 gap actually comes from

There are three common sources. On a given box you may have one of them or several at once.

1. A cloud firewall that filters IPv4 only. Provider firewall rules can distinguish IPv4 and IPv6 sources, so check both address families. If your only firewall is the one in the provider dashboard and it does not cover IPv6, it does not protect your [::] services over IPv6, whatever it says about port 22 on IPv4. Read your provider's firewall documentation and look for the word IPv6 specifically.

2. Hand-rolled iptables with no ip6tables. The iptables command touches the IPv4 tables only. IPv6 has a completely separate command, ip6tables, with its own separate rules. If you wrote a firewall script full of iptables -A INPUT ... lines and never wrote the matching ip6tables rules, those rules do not filter IPv6, and an empty INPUT chain with a default ACCEPT policy allows everything that reaches that chain:

sudo ip6tables -L INPUT -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination

That output shows an IPv6 INPUT chain that accepts traffic without filtering; it does not show any filtering elsewhere in the packet's path.

3. Docker publishing ports straight past your firewall. When you run docker run -p 8080:80, Docker inserts its own rules ahead of UFW's, so a published port is reachable even when ufw status says that port is denied. Docker also publishes to the host's IPv6 addresses by default; with no host address specified and the default userland proxy enabled, IPv6 connections can reach even a container on an IPv4-only bridge network. Why Docker bypasses UFW, and how to filter container ports properly explains the mechanism and the fixes. See the basics of Docker Compose on a VPS for how these published ports get declared.

A note on UFW's IPv6 switch. UFW does handle IPv6, and the switch lives in one file. Check it:

grep IPV6 /etc/default/ufw

Modern Ubuntu ships IPV6=yes, which turns on IPv6 filtering in UFW. A rule with no address in it, such as ufw allow 22/tcp, then applies to both stacks. A rule that names a specific IPv4 or IPv6 address applies only to that address family, so an IPv4-only allow rule does not open the same port over IPv6, and the reverse. If you see IPV6=no, from an old image or an old guide, IPv6 is not left open. With that setting an active UFW drops all IPv6 traffic except on the loopback interface, so the problem runs the other way: anything you meant to serve over IPv6 stops answering. Set it to yes if you want UFW to filter IPv6 with your rules instead of blocking it outright.

See exactly what you are exposing

Do not guess. Measure it from the outside. First list your listeners and note every one bound to :::

sudo ss -tlnp | grep '::'

Then, from a different machine, connect to the server's public IPv6 address and try a port you believe is closed:

curl -6 -v http://[2001:db8:2a::1]:8080/

If that returns a page or a banner, the port is open on IPv6. Connection refused or a timeout means the connection failed, but a timeout does not establish that the port is closed. Those two failures are not the same signal, and the difference between refused and timed out explains why: a refusal is an explicit rejection, while a timeout can reflect filtering, routing trouble, or packet loss. For a full picture, scan the IPv6 address with nmap from off the server:

nmap -6 2001:db8:2a::1

Every port nmap reports as open over IPv6 is reachable over IPv6 from the machine you scanned from, whatever your IPv4 scan showed. Nmap's port states describe how the port looks from that vantage point, not a fixed property of the port, so a rule that allows only certain source addresses can give a different result from somewhere else. Scan from a machine outside any allowlist you set. Comparing the IPv4 and IPv6 scans side by side is the fastest way to find the gap, as long as you read the states carefully. A port that is open on -6 but filtered on IPv4 shows different reachability from the scanner; filtering could be on the host, a router, or a provider firewall, and the IPv6 access could be intentional. A port that is open on -6 but closed on IPv4 also shows different reachability: a closed result does not prove that no service is listening, because a firewall can reject probes with TCP resets that look like replies from the destination host. Check the service's listeners and firewall rules on both stacks; decide whether it should be public at all, then make sure an IPv6 rule covers it.

Close the gap

Make UFW cover both stacks, and default to deny. UFW is disabled on a fresh Ubuntu install, so it filters nothing on either stack until you enable it. Confirm the switch, then set a default-deny inbound policy, allow only what you need, and turn it on:

sudo sed -i 's/^IPV6=no/IPV6=yes/' /etc/default/ufw
sudo ufw default deny incoming
sudo ufw allow 22/tcp
sudo ufw enable
sudo ufw status verbose

If UFW was already active when you flipped IPV6=yes, the change does not take effect until you run sudo ufw reload.

A rule that covers both address families, like 22/tcp here, appears twice in ufw status, once plain and once with a (v6) suffix. A rule tied to a specific IPv4 address has no (v6) twin, and an IPv6-only rule shows up only as a (v6) line. When you see the (v6) lines, UFW is filtering IPv6:

22/tcp                     ALLOW IN    Anywhere
22/tcp (v6)                ALLOW IN    Anywhere (v6)

If you manage iptables by hand, mirror every rule in ip6tables, or move to nftables, whose inet tables handle IPv4 and IPv6 in one place. An inet table still needs rules that cover both families: an IPv4-specific rule does not affect IPv6 traffic, and the reverse. A single nftables inet filter table is the cleanest fix when you are writing rules yourself. If your VPS runs Rocky or AlmaLinux rather than Ubuntu, firewalld is the usual front end to manage instead, with support for both stacks.

Bind services you do not want public to loopback. A database, an admin panel, or a metrics endpoint rarely needs a public address at all. Bind it to 127.0.0.1 and ::1 so it never listens on a routable address in the first place. For Postgres, set listen_addresses = 'localhost'. For an app server, bind it to 127.0.0.1 and put a reverse proxy in front. Closing the listener beats firewalling it, because then there is nothing to reach.

Do not trust UFW to guard Docker's published ports. Publish container ports to a specific address rather than every interface, for example -p 127.0.0.1:8080:80, so the port is reachable only from the host and whatever you deliberately proxy to it. Docker releases older than 28.0.0 have an exception: hosts on the same network segment can reach ports published to localhost. When a container genuinely must be public, put it behind a Traefik reverse proxy and publish only the proxy, not each app.

Add IPv6 rules to your provider firewall, or accept that it is not your firewall for IPv6 and let UFW or nftables on the host do that job instead.

Verify you are actually closed

Run the same outside test again after your changes:

curl -6 -v http://[2001:db8:2a::1]:8080/
nmap -6 2001:db8:2a::1

The port that answered before should now refuse or time out, and nmap should report it filtered or closed. If a port is still open, walk back through the three sources above: a service still bound to :: with no rule in front, a Docker rule sitting ahead of UFW, or a provider firewall that never saw IPv6 at all.

Keeping sensitive services off the public internet entirely is stronger still. Put SSH and admin panels behind a WireGuard VPN and firewall their ports so they answer only on the tunnel, and the IPv6 exposure question stops applying to them. To slow the brute-force scans that hit whatever stays public, layer Fail2ban in front of SSH on top of a default-deny firewall.

If ports themselves are new to you, what ports are and how services listen is the primer to read first.

FAQ

Does UFW block IPv6 by default?

Only once you enable it. Ubuntu 24.04's ufw manual says UFW is disabled on installation, so until you run sudo ufw enable it filters nothing on either stack. IPV6=yes in /etc/default/ufw, which Ubuntu ships, turns on IPv6 support within UFW. With UFW active, its default deny incoming policy covers IPv6 too, rules with no specific address apply to both IPv4 and IPv6, and ufw status shows the IPv6 side with a (v6) suffix. A rule that names a specific address applies only to that address family. The trap appears when you rely on a provider firewall that only filters IPv4, when hand-written iptables rules have no ip6tables twin, or when Docker publishes a port past UFW. IPV6=no (from an old image or an old tutorial) does not open IPv6: with it, an active UFW drops all IPv6 traffic except on loopback. Check the switch with grep IPV6 /etc/default/ufw.

How do I check what my VPS is exposing on IPv6?

Run sudo ss -tlnp and note every listener whose local address starts with [::], which means it listens on every IPv6 address, subject to routing and firewall rules. Then, from a different machine, test the server's public IPv6 address directly with curl -6 -v http://[YOUR:IPV6::ADDR]:PORT/, or scan it with nmap -6 YOUR:IPV6::ADDR. A port open on the IPv6 scan but filtered on IPv4 shows different reachability from that scanner, not proof of a missing host firewall rule; check filtering along both paths and whether the difference is intentional. One open on IPv6 but closed on IPv4 does not prove that the service listens only on IPv6: a firewall can return TCP resets that make the IPv4 port appear closed. Check the service's listeners and firewall rules on both stacks, then check that it should be public and that an IPv6 rule covers it.

Why can I reach my Docker container's port when UFW says it is blocked?

Docker inserts its own firewall rules ahead of UFW's when you publish a port with -p, so the published port is reachable even though ufw status lists it as denied. This happens on IPv4 and IPv6; with no host address specified and the default userland proxy enabled, the host's IPv6 addresses can forward connections to a container on an IPv4-only bridge network too. Publish to a specific address such as -p 127.0.0.1:8080:80, or put the container behind a reverse proxy and publish only the proxy.

Do I still need an IPv6 firewall if my IPv4 firewall is solid?

Yes. IPv4-specific firewall rules do nothing for IPv6 traffic; tools such as UFW and nftables can also create rules that cover both families. If your VPS has a public IPv6 address, a service listening on :: can be reachable over IPv6 wherever routing and filtering allow it. Some providers leave IPv6 off unless you choose it, so check with ip -6 addr show scope global, confirm the address is publicly routed rather than unique local, and add the IPv6 rules before you turn it on.

How do I make a service listen on IPv4 only, or on localhost only?

Set the service's bind address in its own config. Bind to 127.0.0.1 for IPv4 loopback only, or 0.0.0.0 for all IPv4 addresses with no IPv6 listener. Postgres uses listen_addresses, SSH uses ListenAddress, and most app servers expose a host or bind flag. Confirm the result with sudo ss -tlnp and check that the Local Address no longer shows [::].

Was this article useful?