Skip to content
Tutorials Center
My learning

Topics

Lesson 29 of 36 ยท Zero Trust

Cloudflare Tunnel, WARP and Gateway Explained

Publish a private server with Cloudflare Tunnel and cloudflared, write a tunnel config, then filter outbound traffic with WARP and Gateway DNS and HTTP policies.

This lesson covers the other three Zero Trust pieces. Cloudflare Tunnel connects a server to Cloudflare without opening any inbound port. WARP is the client on laptops and phones. Gateway is the filtering service that WARP sends traffic to. Together they handle both directions: reaching private apps, and keeping users safe on the internet.

None of this can run on the site. Commands and configuration are read-only; runnable stand-ins evaluate a tunnel config and Gateway rules.

Cloudflare Tunnel

A tunnel is created by cloudflared, a small daemon you run next to your application. It opens outbound connections to Cloudflare, and traffic for your hostname flows back through them. Because nothing connects inbound, you can close every firewall port, and the origin's real IP stays hidden.

flowchart LR
  V["Visitor"] --> CF["Cloudflare edge"]
  CF <-->|"outbound-only tunnel connections"| D["cloudflared"]
  D --> APP["Local app<br/>localhost:3000"]
  D --> SSH["SSH<br/>localhost:22"]

cloudflared dials out; Cloudflare routes visitors to the services listed in its config.

Create a tunnel from the command line

Terminal
cloudflared tunnel login                              # authorizes against a zone
cloudflared tunnel create web-tunnel                  # creates credentials JSON and a tunnel id
cloudflared tunnel route dns web-tunnel app.example.com   # makes a proxied CNAME to the tunnel
cloudflared tunnel run web-tunnel                     # starts it

Install as a service so it survives reboots: cloudflared service install. In the dashboard you can create a remotely managed tunnel instead (Networks, Tunnels): you copy one install command and manage the routes in the browser, which suits most teams.

A config file

For a locally managed tunnel, config.yml lists the ingress rules. They are checked in order, and the last rule must be a catch-all:

YAML
tunnel: 6ff42ae2-765d-4adf-8112-31c55c1551ef
credentials-file: /etc/cloudflared/6ff42ae2-765d-4adf-8112-31c55c1551ef.json

ingress:
  - hostname: app.example.com
    service: http://localhost:3000
  - hostname: api.example.com
    path: ^/v1/
    service: http://localhost:8080
  - hostname: ssh.example.com
    service: ssh://localhost:22
  - service: http_status:404          # required catch-all

Validate it with cloudflared tunnel ingress validate and test a URL against it with cloudflared tunnel ingress rule https://app.example.com.

JS Ingress rule matcher (stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Notice api.example.com/v2/x falls to the catch-all 404 because its path does not match ^/v1/, exactly as in the real file.

Private networks and high availability

A tunnel can also expose a private network range (for example 10.0.0.0/24) so that WARP users reach internal IPs without a VPN. Run several cloudflared replicas of the same tunnel on different hosts: Cloudflare spreads traffic and survives one host failing. Update cloudflared regularly, because old versions stop being supported.

WARP

WARP is installed on laptops and phones (Windows, macOS, Linux, iOS, Android). Enrolled devices:

  • Send DNS and web traffic through Cloudflare, where Gateway policies apply.
  • Prove device posture: OS version, disk encryption, firewall on, a file or process present, or a third-party security tool reporting healthy. Access policies can then require "compliant device".
  • Reach private networks published through tunnels.

Enrollment rules decide who may register a device (by email domain or IdP group). Roll out through your management tool (MDM) so users never type settings.

Gateway policies

Gateway has three policy types, each with ordered rules and an action:

Type Looks at Example
DNS The domain being resolved Block malware and phishing categories
HTTP Full URL, upload/download, file types (needs TLS inspection) Block uploads to personal file-sharing sites
Network IP and port Block SSH to anything outside your ranges

Actions include Allow, Block, Isolate (open in remote Browser Isolation), Do Not Inspect and, for DNS, Override. Rules can match who (user, group), where (location), what (domain category, application, URL) and device posture. Lower precedence numbers run first and the first matching rule wins.

Gateway DNS has its own DNS locations: an endpoint (including a DNS-over-HTTPS URL) for an office or home router, so you can filter networks where WARP is not installed.

JS Gateway rule evaluation (stand-in)

Press Run (or Ctrl + Enter) to see the console output here.

No output.

HTTP inspection and certificates

To apply HTTP policies to HTTPS traffic, Gateway must decrypt and re-encrypt it, which requires installing Cloudflare's root certificate on devices (distribute it via MDM). Add Do Not Inspect rules for sites that break under inspection, such as banking apps or certificate-pinned software, and tell users what is inspected: this is a privacy and legal decision as much as a technical one.

Logs and review

Gateway logs record every DNS query and HTTP request with the user, device and the rule that matched. Review them to spot blocked-but-needed sites (false positives) and unusual destinations, and export with Logpush for long-term storage.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does Cloudflare Tunnel not need inbound firewall ports?

    The daemon dials out, so the origin only needs outbound internet access and no public IP.
  2. 2. What must the last ingress rule in a tunnel config be?

    cloudflared requires a final rule without hostname or path to handle everything unmatched.
  3. 3. Which Gateway policy type can block by domain category without decrypting HTTPS?

    DNS policies act on the domain at resolution time and need no TLS inspection.
  4. 4. Why distribute Cloudflare's root certificate to devices?

    TLS inspection re-encrypts traffic with a Cloudflare certificate, which devices must trust.

Summary

  • Tunnel (cloudflared) publishes web, SSH and private-network services through outbound-only connections; ingress rules route hostnames and paths and must end with a catch-all.
  • WARP enrolls devices, sends their traffic through Gateway and reports posture for Access policies.
  • Gateway policies come in DNS, HTTP and Network types; first matching rule by precedence wins; HTTP inspection needs a trusted root certificate.
  • Run several cloudflared replicas for availability and review logs regularly.

Next: Analytics, Logs and Observability