Layer 4 TCP UDP Proxy: Origins, DDoS, BYOIP, and Load Balancing
How Cloudflare Spectrum proxies TCP and UDP apps: origins, edge TLS, Proxy Protocol, BYOIP, load balancing limits, and troubleshooting.
This page summarizes Cloudflare Spectrum documentation: a global Layer 4 reverse proxy that adds security and acceleration for TCP and UDP workloads when HTTP(S) proxying is not enough.
Spectrum provides security and acceleration for any TCP or UDP based application.
— Cloudflare, Cloudflare Spectrum
Spectrum is available on paid plans; custom TCP/UDP applications typically require Enterprise with Spectrum as a paid add-on. See Protocols per plan and Settings by plan.
Layer 4 proxy vs HTTP CDN: what Spectrum can and cannot do
Section titled “Layer 4 proxy vs HTTP CDN: what Spectrum can and cannot do”Spectrum answers the question “how do I put a non-web protocol (SSH, game servers, MQTT, SMTP) behind the same kind of edge protection as a website?” It terminates TCP/UDP sockets at the edge but does not inspect or rewrite application-layer payloads.
Spectrum is a global TCP and UDP proxy running on Cloudflare’s edge nodes. It does not terminate the connection in the application-layer sense. However, at Layer 4, Spectrum does terminate the TCP and UDP sockets in both directions. The L4 payloads of TCP segments and UDP datagrams are passed back and forth as-is, without modifications.
— Cloudflare, Configuration options
Implications:
| Need | TCP/UDP traffic_type |
HTTP/HTTPS Spectrum app |
|---|---|---|
| WAF, Bot Management, CDN cache | Not on raw TCP/UDP | Set application type to HTTP/HTTPS |
| Convert HTTP client to HTTPS origin | No automatic upgrade | Configure Edge TLS Termination |
| See Cloudflare HTTP headers at origin | Headers are HTTP-only | Use HTTP/HTTPS app or Proxy Protocol |
This means Spectrum does not inspect, modify, or upgrade application-layer protocols. For example, Spectrum cannot convert an HTTP connection to HTTPS, add HTTP headers, or apply WAF rules to TCP traffic. To add Layer 7 functionality such as CDN, Workers, or Bot Management, set the application type to HTTP/HTTPS.
— Cloudflare, Configuration options
For L3/L4 DDoS posture, Spectrum acts as a reverse proxy that must complete a legitimate TCP handshake before forwarding:
Spectrum works as a layer 4 reverse proxy, therefore a proper TCP connection must be first established before traffic is proxied to the origin. This moves any impact of SYN or SYN-ACK reflection attacks to the Cloudflare global network. Additionally, by using Spectrum in front of your application, your origin IP is concealed — preventing attackers from targeting your origin server directly.
— Cloudflare, DDoS Protection for Spectrum
Create a Spectrum application: IP, CNAME, load balancer, or private origin
Section titled “Create a Spectrum application: IP, CNAME, load balancer, or private origin”Applications can be created in the dashboard or via the Spectrum API. Common origin patterns from Get started:
| Pattern | When to use | Key fields |
|---|---|---|
| Direct IP | Public origin you control | origin_direct |
| DNS hostname origin | Origin behind a name in your zone | origin_dns, origin_port (Enterprise for origin_dns) |
| Load Balancer | Failover and steering to pools | Origin = Load Balancer in dashboard |
| Virtual network | Private IP via Tunnel or WAN | virtual_network_id, single origin_direct IP and port |
Do not reuse the same hostname for both a Spectrum application and an existing Load Balancing hostname if that would break DNS resolution (Get started).
Edge IP addresses: dynamic, static, and BYOIP
Section titled “Edge IP addresses: dynamic, static, and BYOIP”By default, each app gets anycast IPv4/IPv6 addresses that may change; the Spectrum DNS name always reflects current edge IPs (Configuration options).
Static IP (Enterprise, API only): Cloudflare commits not to change the IP for the DNS name; apps sharing a hostname share that static IP (Static IP).
BYOIP migrates your prefix to Cloudflare; you must bind IPs to Spectrum apps (often dns.type = ADDRESS and edge_ips.type = static) (BYOIP). Minimum prefix sizes: /24 IPv4, /48 IPv6. Switching from non-BYOIP to BYOIP requires deleting and recreating existing Spectrum apps.
For HTTPS without SNI on your own IPs, address maps can support non-SNI; control the responding IP via edge_ips on the Spectrum app (About address maps).
Account quota: by default 10 unique IPv4 hostnames per account unless you use BYOIP, IPv6-only apps, gray-cloud CNAME aliases to one app, or SaaS custom hostnames (Limitations).
Port ranges and virtual network origins
Section titled “Port ranges and virtual network origins”Edge and origin port ranges must align one-to-one (e.g. edge :1005 → origin offset in range) (Configuration options).
Virtual network origins (TCP/UDP only) require exactly one origin_direct address, a single port, routable IP in the virtual network, and proxy_protocol = off. HTTP/HTTPS apps cannot use this path; use Application Services for Private Origins for private HTTP with full proxy stack (Get started, Error codes e.g. 11043).
Edge TLS termination on TCP Spectrum apps
Section titled “Edge TLS termination on TCP Spectrum apps”“Port 443” does not imply HTTPS through Spectrum when TLS is off (Passthrough): payloads are forwarded unchanged.
Spectrum operates at Layer 4 and forwards TCP payloads as-is. If Edge TLS Termination is set to off (Passthrough), Spectrum will not upgrade an HTTP connection to HTTPS, even if your origin listens on port 443.
— Cloudflare, Edge TLS Termination
Modes: flexible, full, full (strict naming in API as full and strict variant). Edge TLS applies to TCP applications; minimum TLS 1.1 when enabled, with documented cipher suites (Configuration options).
Universal SSL is not compatible with Spectrum; use advanced or custom certificates (Limitations).
Proxy Protocol: real client IP at the origin
Section titled “Proxy Protocol: real client IP at the origin”Without Proxy Protocol, the origin sees Cloudflare edge IPs (important for SMTP and FTP).
Because Cloudflare intercepts packets before forwarding them to your server, if you were to look up the client IP, you would see Cloudflare’s IP rather than the true client IP.
— Cloudflare, Enable Proxy protocol
| Transport | Options | Notes |
|---|---|---|
| TCP | Proxy Protocol v1 (text) or v2 (binary) | Enterprise; configure in dashboard |
| UDP | Proxy Protocol v2 or Simple Proxy Protocol | Simple requires origin to prepend replies too |
| Magic WAN egress | — | Proxy Protocol not supported |
Cloudflare recommends Proxy Protocol for SMTP (Configuration options). SMTP may fail reverse-DNS checks because Spectrum apps lack rDNS; MX pointing at Spectrum can also cause rejections.
Proxy Protocol is not supported with virtual network origins or Private Network Load Balancing on-ramp (Limitations).
Load balancing with Spectrum: health checks and hard limits
Section titled “Load balancing with Spectrum: health checks and hard limits”You can select a load balancer as the Spectrum origin for TCP/UDP resilience (Cloudflare Load Balancing, Add load balancing to Spectrum).
TCP monitors use method = connection_established (TCP health checks). Without health checks, traffic goes to all endpoints in the first pool.
Not supported with Spectrum load balancing (Requirements and limitations, Custom load balancing rules):
- Session affinity (except hash endpoint steering on Spectrum L4 load balancers per Load Balancing Reference Architecture)
- Failover across pools
- Custom load balancing rules
UDP health checks require public monitoring; TCP supports public and private monitoring. Feature requires Enterprise (Cloudflare Load Balancing).
Ingress port is fixed: traffic on edge port 22 is steered to origin port 22 (Load Balancing Reference Architecture).
IP Access rules, filtering, and health check gotchas
Section titled “IP Access rules, filtering, and health check gotchas”For TCP/UDP Spectrum apps, IP Access rules (allow/block on IP, country, ASN) are the supported IP filter—not custom WAF rules (Configuration options, Limitations).
Network Analytics does not reflect IP Access rule outcomes; use Spectrum event logs (Configuration options).
When the Spectrum app is the target of a health check or LB monitor, allowlist Cloudflare IP ranges if you use an allowlist model—or move access control to the origin (Spectrum Troubleshooting).
FTP, SFTP, and protocol-specific notes
Section titled “FTP, SFTP, and protocol-specific notes”- SFTP: Spectrum on TCP/22 typically needs no extra FTP-style setup (FTP).
- FTP: Passive mode only; EPSV works without origin changes; PASV requires advertising the Spectrum hostname/IP and often one Spectrum app per data port in the passive range (FTP).
- UDP: Fragmented UDP packets are dropped at the edge (Limitations).
- Tunnel integration: Spectrum + Tunnel DNS/LB origin is documented for HTTP/HTTPS only on the Tunnel integration page; TCP/UDP private access uses virtual network origins instead (Integrations).
Event logs, status codes, and common mistakes
Section titled “Event logs, status codes, and common mistakes”Spectrum connection lifecycle is logged via Logpush spectrum_events (Event logs). Status codes such as 521 (origin refused) and 522 (origin timeout) are Spectrum connection codes, not HTTP CDN codes—444/499 differ from HTTP semantics (Event logs, Troubleshooting).
| Mistake | Why it fails |
|---|---|
| Expect WAF on TCP app | Use IP Access rules or HTTP/HTTPS app type |
| Allowlist-only IP rules without Cloudflare IPs | Health checks mark endpoint unhealthy |
| Pay-as-you-go, multiple apps same protocol | Error 11034—one app per protocol unless add-on enabled (Error codes) |
| BYOIP edge IP already used | Error 11033—orphaned legacy app (Error codes) |
| Clients hit L7 CDN IP with Spectrum hostname | Traffic may appear in L7 analytics; use WAF to block unwanted L7 paths (Layer 7 analytics) |
Regional services, static IPs, and data localization
Section titled “Regional services, static IPs, and data localization”Regionalized Spectrum Applications assign a dedicated IP and process traffic in a configured region (one region per zone). Static IPs and BYOIP work with regionalized Spectrum; shared anycast Regional Hostnames do not support Static IPs (Regionalized Spectrum Applications, Data localization FAQ). Setup is account-team enabled.
How to check this on your site
Section titled “How to check this on your site”- Confirm DNS for your Spectrum hostname resolves to the expected edge IPs (dynamic lookup or your static/BYOIP assignment per Static IP and Configuration options).
- From an allowed client network, open a TCP or UDP session to the configured edge port and verify the origin receives traffic (and Proxy Protocol headers if enabled) per Enable Proxy protocol.
- If using load balancing, check monitor health in the dashboard and review TCP monitor settings against Cloudflare Load Balancing.
- For allow/block issues, inspect Spectrum event logs rather than Network Analytics alone (Configuration options).
- You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact statement you are asking about.