Skip to main content
Servers Are Up
Virtual Datacenter
PricingFree Tools
Sign inBrowse catalog
Servers Are Up
Virtual Datacenter
PricingFree Tools
Sign inBrowse catalog

Loading…

Servers Are Up

Your apps, automation and data on hardware we own. Build a private stack with predictable capacity and access through your dashboard, API or SSH.

SLA with service creditsOwned hardwareUS-based

Make room for your next idea

Explore the capacity, apps and access options that fit your workload. Check current availability and your total before you buy.

Sign up freeView Pricing

Products

  • Linux VPS
  • Windows VPS
  • Cloud & SaaS Services
  • Cloud Storage (Azure)
  • Virtual Datacenter
  • AI & Agent Hosting
  • Containers
  • Instant Apps
  • Software Platforms
  • Network builder
  • Game Servers
  • Free Game Servers
  • Pricing

Resources

  • Free Network Tools
  • 2026 Pricing Benchmark
  • Live SVG Badges
  • Latency & Speed Test
  • Guides & Tutorials
  • Documentation
  • API Reference
  • MCP Server
  • CLI & SDKs
  • OpenAPI & llms.txt
  • Use Cases
  • Free Migration
  • Uptime & Reliability
  • Datacenter
  • System Status
  • Network
  • Provider Comparisons Hub
  • Compare Providers

Company

  • About Us
  • Enterprise
  • Security Architecture
  • Trust Center
  • Blog
  • FAQ
  • Compliance
  • Startup Program
  • Open-Source Sponsorship
  • Press & Media Kit
  • Referral Program
  • Help Center
  • Contact Us
© Servers Are Up
TermsPrivacySLARefund PolicyDPAAcceptable Use
Service information
Docs
  • Documentation Hub
  • Technical Knowledge Library
    Runbooks & 187 Blueprints
  • Choose a Product
    VMs, Containers & Cloud
  • First Linux Server
    SSH, Firewall & Apps
  • Windows Server 2025
    BYOL & Remote Desktop
  • Remote Access
  • Troubleshooting
  • FAQ
  • All Product Guides
    29 Step-by-Step Guides
  • Cloud & SaaS Catalog
    112 Cloud & SaaS Offerings
  • Azure Cloud Storage
    Hot/Cool/Archive & WORM
  • Resource Manager & RBAC
    Groups, Tags & Locks
  • Multi-Model Cloud DB
    JSONB, SQL & pgvector
  • Cloud Identity & ZTNA
    OIDC, SCIM & PIM
  • Key Vault & KMS
    Secrets & Envelope Keys
  • Cloud SIEM, SOAR & DLP
    Posture & Threat Response
  • API Gateway & Cloud DNS
    Edge WAF & DNS Zones
  • Serverless, Workflows & IoT
    Functions, Queues & DAGs
  • SaaS, Governance & Vault
    Budgets & Off-Host GRS
  • Linux Systems & Kernel
    SSH, UFW, sysctl & OOM
  • Self-Hosted Apps & Stacks
    Caddy, Nextcloud & Auth
  • Build Web Apps with AI
  • Next.js and React
  • TypeScript and Node.js
  • npm and Tooling
  • Data and APIs
  • Deploy and Operate
  • Tutorials
  • Infrastructure
  • Automation & Regions
  • API Overview
  • API v1 Reference
    Endpoints & 23 Scopes
  • MCP Server
    129 AI Agent Tools
  • Swagger / OpenAPI 3.1
  • API Playground
  • Versioning & Sunset
  • API Token Security
    Authentication & Tokens
  • Instances API
    Compute Resources
  • Networking API
    Networks & Ports
  • Storage API Availability
    Volumes & Backups
  • Webhooks & Events
    Event Notifications
  • Rate Limits & Best Practices
    Throttling & Retries
  • sau CLI Reference
    34 Commands (v0.2)
  • Browser Web CLI
  • SDKs
  • Infrastructure as Code
    Terraform & Ansible
  • Code Examples
  • CLI & SDK Guides
  • Security Guides
  • Security at a Glance
  • Zero Trust Architecture
  • Live Trust Center
  • Compliance
Need help?

Loading documentation...

Documentation/linux systems

Fix Docker UFW bypasses with DOCKER-USER and nftables

Prevent Docker published ports from bypassing UFW using loopback bindings, daemon.json defaults, persistent DOCKER-USER iptables rules, and CrowdSec.

Advanced
30 min
Updated 2026-11-23

Deploy Ready-to-Run Infrastructure in Seconds

Linux VMs from $6/mo · Pooled Virtual Datacenters from $12/mo · Use code WELCOME20 for 20% off your first order.

Browse ServersView Pricing

Commands checked on 2026-11-23 with Docker Engine 27+, UFW 0.36+, nftables 1.0+, Ubuntu 24.04.

What you will have at the end

A Docker host where internal databases, vector stores, and admin panels are never exposed on public network interfaces, UFW no longer misleads you about published container ports, and CrowdSec firewall blocks apply to container traffic too.

Before you start

  • Root or sudo access on a Linux host running Docker Engine (docker version) and UFW or nftables; see Managed Docker first stack.
  • Understanding that Docker inserts DNAT rules in PREROUTING and routes packets through the FORWARD chain before UFW's INPUT rules run.

Steps

1. Audit which container ports are exposed to 0.0.0.0

Check live listening sockets and published Docker mappings:

docker ps --format "table {{.Names}}\t{{.Ports}}"
sudo ss -tulpn | grep -E ':(5432|6379|6333|7700|9000|8080|11434)\b'

Any mapping showing 0.0.0.0:5432->5432/tcp or :::5432 is reachable from outside regardless of ufw deny 5432.

2. Bind internal services strictly to 127.0.0.1 or internal networks

In docker-compose.yml, remove ports: completely for backend services talked to by a reverse proxy or sibling container on a shared Docker bridge network, or bind strictly to loopback:

services:
  postgres:
    image: postgres:17-alpine
    ports:
      - "127.0.0.1:5432:5432"

Set a defensive daemon-wide default in /etc/docker/daemon.json so forgotten -p 8080:80 flags default to 127.0.0.1 instead of 0.0.0.0:

sudo tee /etc/docker/daemon.json >/dev/null <<'EOF'
{
  "ip": "127.0.0.1",
  "log-driver": "json-file",
  "log-opts": {
    "max-size": "20m",
    "max-file": "5"
  },
  "default-address-pools": [
    { "base": "172.24.0.0/14", "size": 24 }
  ]
}
EOF
sudo systemctl reload docker || sudo systemctl restart docker

Note that setting custom default-address-pools also prevents bridge CIDR collisions with Kubernetes pod/service CIDRs or overlapping corporate VPN ranges.

3. Enforce egress/ingress policy on DOCKER-USER in /etc/ufw/after.rules

When a container must publish public ports (such as Caddy/Traefik on 80/443), Docker evaluates DOCKER-USER before its own DOCKER forwarding rules. Append a DOCKER-USER chain block at the bottom of /etc/ufw/after.rules (using eth0 or your actual WAN interface from ip route show default):

*filter
:DOCKER-USER - [0:0]
-A DOCKER-USER -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A DOCKER-USER -i lo -j RETURN
# Allow traffic arriving from Docker bridges back out to containers/internet
-A DOCKER-USER ! -i eth0 -j RETURN
# Allow public HTTP/HTTPS on WAN interface to reach reverse proxy container
-A DOCKER-USER -i eth0 -p tcp -m multiport --dports 80,443 -j ACCEPT
# Drop unauthorized external packets targeting forwarded container ports
-A DOCKER-USER -i eth0 -j DROP
COMMIT

Reload UFW cleanly without dropping active SSH sessions:

sudo ufw reload
sudo iptables -L DOCKER-USER -n -v

4. Align CrowdSec firewall bouncers with Docker FORWARD traffic

Ensure CrowdSec inspects DOCKER-USER (or nftables forward hook / ipset) rather than only host INPUT, otherwise banned scanners still hit published container ports:

grep -E 'mode|iptables_chains' /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml 2>/dev/null || true

When using iptables mode, include DOCKER-USER in iptables_chains: and restart crowdsec-firewall-bouncer.

Check that it works

Never test firewall exposure from the same machine (localhost traffic skips external NIC paths). Run nmap from a second host against YOUR_SERVER_IP:

nmap -Pn -p 22,80,443,5432,6379,11434 YOUR_SERVER_IP

Expected result: 80 and 443 report open, while 5432, 6379, and 11434 report filtered or closed.

What can go wrong

  • Containers lose outbound DNS or apt connectivity inside docker build. You forgot -A DOCKER-USER ! -i <WAN_IFACE> -j RETURN or -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT, which drops reply packets to bridge interfaces (docker0, br-*).
  • ufw reload fails with iptables-restore syntax error. Check interface name (ip -br link) and verify iptables-restore -t < /etc/ufw/after.rules before reloading.
  • Public website works on HTTP/HTTPS, but a self-hosted git container needs SSH on port 2222. Add explicit allow rule -A DOCKER-USER -i eth0 -p tcp --dport 2222 -j ACCEPT before the final DROP line, or bind Gitea SSH cleanly.

Good practice

  • Keep only your reverse proxy container publishing 80/443 and let backend databases communicate exclusively over an internal Docker network (internal: true).
  • Combine host DOCKER-USER filtering with external perimeter firewall controls in Firewall and port forwarding.
  • Bound Docker log files in /etc/docker/daemon.json (max-size: 20m, max-file: 5) so noisy containers never fill /var/lib/docker.

Where to go next

  • Reverse proxy patterns with Caddy and Traefik
  • Harden OpenSSH and sandbox systemd services cleanly
  • Diagnose Linux OOM kills, sysctl limits, and disk spikes

Related Articles

Diagnose Linux OOM kills, sysctl limits, and disk spikes

Read more

Harden OpenSSH and sandbox systemd services cleanly

Read more

Administer Ubuntu, Debian, Rocky, and AlmaLinux servers cleanly

Read more

Frequently Asked Questions

What does the Fix Docker UFW bypasses with DOCKER-USER and nftables documentation guide cover?
Prevent Docker published ports from bypassing UFW using loopback bindings, daemon.json defaults, persistent DOCKER-USER iptables rules, and CrowdSec. It is rated advanced difficulty (30 min) and applies to Servers Are Up infrastructure and workflows.
Can I manage or automate these steps through the Servers Are Up dashboard, REST API v1, or MCP server?
Yes. Every Servers Are Up server includes browser-based SSH, WebRDP, and VNC console access in the dashboard, plus programmatic control via the REST API v1 (/api/v1) and hosted Model Context Protocol server (/api/mcp/v1) using a scoped Personal Access Token.

Need hands-on help with Fix Docker UFW bypasses with DOCKER-USER and nftables?

Every Servers Are Up virtual machine and container includes an integrated HTML5 browser-based SSH, RDP, and VNC console in your dashboard, default-off inbound firewall rules with per-IP allow-lists, and full programmatic control via REST API v1 and Model Context Protocol (MCP). Explore our Virtual Datacenter Plans or reach out to Servers Are Up Support.

Was this article helpful?

On this page

What you will have at the endBefore you startSteps1. Audit which container ports are exposed to 0.0.0.02. Bind internal services strictly to 127.0.0.1 or internal networks3. Enforce egress/ingress policy on DOCKER-USER in /etc/ufw/after.rules4. Align CrowdSec firewall bouncers with Docker FORWARD trafficCheck that it worksWhat can go wrongGood practiceWhere to go next
Need Live Commands?

Open Aria in Wide Engineering Mode for distro-specific commands, compose tweaks, and isolated environment troubleshooting.

Knowledge Library