Skip to content
AnswerWell geo Documentation

Research · 8 min read · Answerwell

TCP and UDP Port Fields, Gateway Policies, and Log Datasets

How Cloudflare exposes source and destination port numbers in rules, firewalls, Gateway policies, origin overrides, and LogPush datasets.

Most of this page summarizes Cloudflare documentation on port numbers at the edge: which fields mean source vs destination, how HTTP rules differ from packet-level firewall fields, how Zero Trust Gateway matches ports, how Origin Rules can change the backend port, and which port columns appear in LogPush. Port values are integers in the range 1–65535 unless a dataset notes a special case (for example 0 when protocol is unspecified).

Edge HTTP fields: server port and TCP transport

Section titled “Edge HTTP fields: server port and TCP transport”

cf.edge.server_port: which port the global network received

Section titled “cf.edge.server_port: which port the global network received”

For HTTP/WAF rules in the Ruleset Engine, cf.edge.server_port is the port number where Cloudflare’s global network received the request.

Represents the port number at which the Cloudflare global network received the request.

Use this field to filter traffic on a specific port. The value is a port number in the range 1–65535.

— Cloudflare, cf.edge.server_port

Use this when you care about the listener port on the edge (for example separating traffic to port 443 vs a non-standard published port), not the ephemeral client port.

cf.edge.client_tcp: was the client request over TCP?

Section titled “cf.edge.client_tcp: was the client request over TCP?”

cf.edge.client_tcp is a boolean: it indicates whether the request was made over TCP.

Indicates if the request was made over TCP.

— Cloudflare, cf.edge.client_tcp

Pair cf.edge.server_port with protocol or transport hints when you need rules that depend on both which edge port was hit and whether the client used TCP (as opposed to inferring transport only from port number).

Packet firewall fields: tcp.srcport, tcp.dstport, and UDP ports

Section titled “Packet firewall fields: tcp.srcport, tcp.dstport, and UDP ports”

Source and destination ports on TCP and UDP packets

Section titled “Source and destination ports on TCP and UDP packets”

At L3/L4 in Cloudflare Network Firewall fields and packet filtering fields, port numbers come from the IP packet:

Field Type When it applies
tcp.srcport Number Source port; TCP only
tcp.dstport Number Destination port; TCP only
udp.dstport Number Destination port; UDP only

Source port number of the IP packet. Only applies to TCP packets.

— Cloudflare, Cloudflare Network Firewall fields — tcp.srcport

Destination port number of the IP packet. Only applies to TCP packets.

— Cloudflare, Cloudflare Network Firewall fields — tcp.dstport

Destination port number of the IP packet. Only applies to UDP packets.

— Cloudflare, Cloudflare Network Firewall fields — udp.dstport

Always constrain with ip.proto when the rule must not match the wrong transport. For example, SIP detection requires UDP:

Determines if packets are valid L7 protocol SIP ↗︎. Requires UDP packets to operate.

Use a guard clause as shown below to ensure the packet is UDP (wirefilter):

ip.proto == "udp"

— Cloudflare, Cloudflare Network Firewall fields — sip

The transport layer for the packet, if it can be determined.

Example values: icmp, tcp

— Cloudflare, Cloudflare Network Firewall fields — ip.proto

When structured fields are not enough, tcp, udp, and ip hold the raw packet as bytes and are meant to be used with bit_slice:

The raw TCP packet as a list of bytes. It should be used in conjunction with the bit_slice function when other structured fields are lacking.

— Cloudflare, Cloudflare Network Firewall fields — tcp

From Functions — bit_slice:

This function looks for matches on a given slice of bits.

The offset starts on the given protocol header. For example, to match on the first bit of payload for a UDP packet, you must set offset_start to 64.

This is primarily intended for use with ip, udp, and tcp.

The slice (offset_end – offset_start) cannot be longer than 32 bits, but multiple calls can be joined together by using logical expressions.

The bit_slice offset cannot exceed 2,040 bits.

Prefer tcp.dstport / tcp.srcport / udp.dstport when they apply; reserve bit_slice for options or payloads not exposed as named fields.

Firewall rules can combine ports with individual TCP flags (for example tcp.flags.syn, tcp.flags.ack). The numeric tcp.flags field is the flags byte; boolean fields such as tcp.flags.reset describe each flag. See the same Network Firewall fields reference for the full list.

Zero Trust Gateway: net.dst.port and net.src.port

Section titled “Zero Trust Gateway: net.dst.port and net.src.port”

Egress policies and network policies express port matching with Gateway wirefilter examples:

UI name API example Meaning
Destination Port net.dst.port == 2222 Port number of the request’s target
Source Port net.src.port == "2222" Originating port of a device proxied by Gateway

The port number of the request’s target.

— Cloudflare, Egress policies — Destination Port

The originating port of a device proxied by Gateway.

— Cloudflare, Egress policies — Source Port

These net.*.port expressions apply to Zero Trust traffic steering, not to the same HTTP ruleset fields as cf.edge.server_port. Pick the product whose path your traffic actually follows.

Origin Rules: overriding the destination port to the origin

Section titled “Origin Rules: overriding the destination port to the origin”

Origin Rules — destination port let you change which port Cloudflare uses when connecting to your origin:

Allows you to override the destination port of a request.

When you configure a destination port override, you can redirect incoming requests to a different port. For example, you could override the destination port for requests received for mydomain.com so that they are served by the application running on port 9000 (mydomain.com:9000).

The destination port must be between 1 and 65,535.

— Cloudflare, Origin Rules settings — Destination port

The override affects origin connect port, not the port the visitor used to reach the edge (logged separately in HTTP datasets as client source port).

LogPush: where source and destination ports appear

Section titled “LogPush: where source and destination ports appear”

LogPush datasets use different column names for the same logical idea (client ephemeral port vs service destination port). Use the dataset that matches your product.

Product / dataset Source-side port fields Destination-side port fields Notes
HTTP Requests (account) ClientSrcPort — Client source port
HTTP Requests (zone) ClientSrcPort — Same field at zone scope
Gateway HTTP SourcePort DestinationPort Per HTTP request through Gateway
Gateway Network SourcePort DestinationPort, OverridePort OverridePort if session port was overridden
Gateway DNS SrcPort DstPort Edge ports vary by DNS query protocol
DNS Firewall Logs — — QueryTCP (bool): TCP vs UDP query
Zero Trust Network Session Logs SourcePort, EgressPort OriginPort EgressPort: source port toward origin
Spectrum Events ClientPort OriginPort TCP/UDP proxy sessions
Magic Network Monitoring Flow Logs SourcePort DestinationPort Flow records; Protocol (e.g. 6 = TCP)
Network Analytics Logs SourcePort DestinationPort Packet header fields including TCPFlags
Magic IDS Detections SourcePort DestinationPort Set to 0 if protocol is any
IPsec Logs LocalPort RemotePort Tunnel endpoints

For DNS at the resolver, DNS Firewall Logs — QueryTCP states:

Indicates if the query from the client was made via TCP (if false, then UDP).

Gateway DNS — DstPort adds:

The destination port used at the edge. The port changes based on the protocol used by the DNS query (for example, 0).

Spectrum UDP: Simple Proxy Protocol port encoding

Section titled “Spectrum UDP: Simple Proxy Protocol port encoding”

For Spectrum UDP proxying, the Simple Proxy Protocol Header prepends client and proxy ports to each datagram:

The client source IP and port is encoded in a fixed-length, 38-octet long header and prepended to the payload of each proxied UDP datagram.

— Cloudflare, Simple Proxy Protocol Header

16-bit source port number of the proxied UDP datagram. In other words, the UDP port number from which the client sent the datagram.

— Cloudflare, Simple Proxy Protocol Header — Client port

16-bit destination port number of the proxied UDP datagram. In other words, the UDP port number on which the proxy received the datagram.

— Cloudflare, Simple Proxy Protocol Header — Proxy port

Magic number 0x56EC identifies the 38-byte SPP header; port fields use network byte order. Backend code that parses headers often uses ntohs / htons as documented under Programmable Flow Protection.

Containers and workers: runtime TCP port (not edge logging)

Section titled “Containers and workers: runtime TCP port (not edge logging)”

The Durable Object Container API accepts a port parameter described as:

TCP port number to use for communication with the container.

That is application-level container networking, separate from cf.edge.server_port or LogPush HTTP fields.

Common mistakes when matching or reading ports

Section titled “Common mistakes when matching or reading ports”
  • Using tcp.dstport on UDP traffic (or udp.dstport on TCP)—structured port fields are transport-specific in Network Firewall fields.
  • Mixing cf.edge.server_port (edge HTTP listener) with net.dst.port (Gateway target) in one rule expression—they belong to different control planes.
  • Assuming LogPush DestinationPort always equals the origin service port; check for OverridePort on Gateway Network sessions or Origin Rules overrides.
  • Treating Magic IDS SourcePort/DestinationPort of 0 as valid listener ports when protocol was any.
  • Parsing UDP payloads without validating Simple Proxy Protocol magic 0x56EC before reading client_port / proxy_port.
  1. Identify your traffic path (public HTTP through Cloudflare, Gateway Zero Trust, Spectrum, or Magic Network) and open the matching field reference: cf.edge.server_port for edge HTTP, Network Firewall fields for packets, or egress policies for Gateway.
  2. Draft a rule or filter using the correct port field (tcp.dstport, net.dst.port, or Origin Rules destination port) and note transport guards such as ip.proto == "tcp" or DNS QueryTCP from DNS Firewall Logs.
  3. Enable or query the LogPush dataset for that product (HTTP Requests, Gateway HTTP, Spectrum Events, etc.) and confirm ClientSrcPort / SourcePort / DestinationPort align with a test connection.
  4. If you override origin ports, verify behavior against Origin Rules — destination port (valid range 1–65,535) and check session logs for OriginPort or EgressPort where applicable.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact sentence you are asking about, and we will correct or clarify it.