Use BYOIP with Magic Transit and CDN

Last updated May 6, 2026 customers using BYOIP can also benefit from the performance, reliability, and security that Cloudflare offers for HTTP-based applications. Service bindings allow BYOIP customers to selectively route traffic on a per-IP address basis to the CDN pipeline (which includes Cache, Web Application Firewall (WAF), and more).

This guide covers using the Cloudflare API to configure Magic Transit with CDN. It is also possible to define service bindings to route traffic to the Spectrum pipeline selectively. Refer to scope for the full list of possible configurations and other available guides.

It is important to note that traffic routed to the CDN pipeline is protected at Layers 3 and 4 by the inherent DDoS protection capabilities native to the CDN pipeline.

Before you begin

  • Make sure your contract includes CDN according to your needs. If you find any issues related to subscription when following the steps below, reach out to your account team.
  • Plan for what IPs will be used:

Cloudflare strongly recommends implementing service bindings through an aggregated CIDR block, as it is more efficient than adding discrete bindings for non-contiguous CIDR blocks.<details><summary>

Example</summary>

Magic Transit protected prefix: <code>203.0.113.0/24</code>

IPs to upgrade to CDN:

<code>203.0.113.16</code><br> <code>203.0.113.17</code><br> <code>203.0.113.18</code><br> <code>203.0.113.19</code><br> <code>203.0.113.20</code><br> <code>203.0.113.21</code><br> <code>203.0.113.22</code><br> <code>203.0.113.23</code>

Add one discrete CDN service binding for <code>203.0.113.16</code> with a <code>/29</code> netmask.</details>

Once a service binding is created (or deleted), it will take four to six hours to propagate across Cloudflare's global network. Services for the IP addresses in scope will likely be disrupted during this window.

Note

This guide assumes that the prefix is tied to a single Cloudflare account that has both Magic Transit and CDN properties. If you are using prefix delegations, the service bindings must be created on the parent account.

1. Get account information

  1. Log in to your Cloudflare account and get your account ID and authentication key or token. If using an API token, the permissions should include Account - IP Prefixes - Edit.
  2. Make a GET request to the List Services endpoint and take note of the id associated with the CDN service.
  3. Use the List Prefixes endpoint and take note of the id associated with the prefix ( cidr) you will configure.

At this point, continuing the example, you should have a mapping similar to the following:

Variables Description
{service_id} The ID of the CDN service within Cloudflare. <br><br> Example: 969xxxxxxxx000xxx0000000x00001bf
{prefix_id} The ID of the Magic Transit prefix (203.0.113.0/24) you want to configure. <br><br> Example: 6b25xxxxxxx000xxx0000000x0000cfc
  1. To confirm you currently have a Magic Transit service binding and that it spans across your entire prefix, make a GET request to the List Service Bindings endpoint. Replace the {prefix_id} in the URI path by the actual prefix ID you got from the previous step.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>IP Prefixes: Write</code>
  • <code>IP Prefixes: Read</code>

</details>

List Service Bindingsbash

curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/addressing/prefixes/$PREFIX_ID/bindings" \
    --request GET \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN"

2. Create service bindings

Caution

Once a service binding is created (or deleted), it will take four to six hours to propagate across Cloudflare's global network. Services for the IP addresses in scope will likely be disrupted during this window.

  1. Make a POST request to the Create service binding endpoint, indicating the IP address you want to bind to CDN. Specify the corresponding network mask as needed.

Continuing the example, 203.0.113.100/32 designates an IP address that is within the Magic Transit prefix 203.0.113.0/24.

Replace the {prefix_id} in the URI with your prefix ID from previous steps. Within the request body, the cidr value should correspond to the IP address or subnet that you are configuring for use with CDN.

<details>

<summary>

Required API token permissions

</summary>

At least one of the following <a href="https://developers.cloudflare.com/fundamentals/api/reference/permissions/">token permissions</a> is required:

  • <code>IP Prefixes: Write</code>

</details>

Create Service Bindingbash

curl "https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/addressing/prefixes/$PREFIX_ID/bindings" \
    --request POST \
    --header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
    --json '{
        "cidr": "203.0.113.100/32",
        "service_id": "<SERVICE_ID>"
    }'

In the response body, the initial provisioning state should be provisioning.

{
  "errors": [],
  "messages": [],
  "success": true,
  "result": {
    "cidr": "203.0.113.100/32",
    "id": "<SERVICE_BINDING_ID>",
    "provisioning": {
      "state": "provisioning"
      },
    "service_id": "<SERVICE_ID>",
    "service_name": "<SERVICE_NAME>"
  }
}

You can periodically check the service binding status using the List Service Bindings endpoint.

3. Create address maps

Once you have configured your IPs to have CDN service, you can use address maps to specify which IPs should be used by Cloudflare in DNS responses when a record is proxied.

You can choose between two different scopes:

  • Account-level: uses the address map for all proxied DNS records across all of the zones within an account.
  • Zone-level: uses the address map for all proxied DNS records within a zone.

Tip

If you need to map only specific subdomains (and not all proxied DNS records) to specific IP addresses, you can use a zone on Subdomain setup.

  1. In the Cloudflare dashboard, go to the Address Maps page. Go to Address maps ↗
  2. Select Create an address map.
  3. Choose the scope of the address map.
  4. Add the zones and IP addresses that you want to map.
  5. Name your address map.
  6. Review the information and select Save and Deploy.

Use the Create Address Map endpoint.

Make sure you have the correct Key/Token and permissions.

4. Create DNS records

To create a DNS record in the dashboard:

  1. In the Cloudflare dashboard, go to the DNS Records page. Go to Records ↗
  2. Select Add record.
  3. Choose an address ( A/ AAAA) record type.
  4. Complete the required fields, setting the Proxy status to proxied.
  5. Select Save.

To create records with the API, use a POST request. For field definitions, select a record type under the request body specification.

Tip

As you create the necessary DNS records, Total TLS can help making sure that you have SSL/TLS certificates in place for all your hostnames.

While the DNS record proxy status and address map will determine how Cloudflare's authoritative DNS responds to requests for your hostnames, the IP addresses specified in A/AAAA records will determine how Cloudflare reaches the configured origin.

<details>

<summary>

Example

</summary>

Type Name IP address Proxy status TTL
<code>A</code> <code>www</code> <code>203.0.113.150</code> <code>Proxied</code> <code>Auto</code>

At this point, if an address map for a zone <code>example.com</code> specifies that Cloudflare should use <code>203.0.113.100</code> for proxied records and the above record exists in the same zone, you can expect the following:

  1. Cloudflare responds to DNS requests with <code>203.0.113.100</code>.
  2. Cloudflare proxies requests through the CDN and then routes the requests via <a href="https://developers.cloudflare.com/magic-transit/reference/gre-ipsec-tunnels/">GRE</a> or <a href="https://developers.cloudflare.com/magic-transit/network-interconnect/">CNI</a> to the origin server <code>203.0.113.150</code> (which is within the Magic Transit protected prefix).
  3. Depending on whether Magic Transit is implemented with <a href="https://developers.cloudflare.com/magic-transit/how-to/configure-tunnel-endpoints/#bidirectional-vs-unidirectional-health-checks">direct server return model or with Magic Transit egress</a>, the origin server responds back to Cloudflare either:
  4. Directly over the Internet in a Magic Transit direct server return model
  5. Back through the Magic GRE tunnel(s) in a Magic Transit egress model
  6. As the HTTP response egresses the Cloudflare network back to the client side, the source IP address of the response becomes <code>203.0.113.100</code> (the IP address that the HTTP request originally landed on).

</details>

Note

Having the same IP address as ingress IP (defined in the address map) and origin IP (listed in the DNS record) will not cause any loops.

<details>

<summary>

Example

</summary>

Assuming <code>203.0.113.100</code> was also the origin IP, the DNS record would look like the following:

Type Name IP address Proxy status TTL
<code>A</code> <code>www</code> <code>203.0.113.100</code> <code>Proxied</code> <code>Auto</code>

</details>

5. (Optional) Add layer 7 functionality

Leverage other features according to your needs. For example:

Was this helpful?

YesNo

On this page

Use BYOIP with Magic Transit and CDN - 图1Docs

{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/byoip/service-bindings/magic-transit-with-cdn/#page","headline":"Use BYOIP with Magic Transit and CDN","description":"Service bindings allow BYOIP customers to selectively route traffic on a per-IP address basis to the CDN pipeline. It is important to note that traffic routed to the CDN pipeline is protected at Layers 3 and 4 by the inherent DDoS protection capabilities.","url":"https://developers.cloudflare.com/byoip/service-bindings/magic-transit-with-cdn/","inLanguage":"en","image":"https://developers.cloudflare.com/byoip/service-bindings/magic-transit-with-cdn/og.png?v=61c932dae64ac09e","dateModified":"2026-05-06","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["DNS","Integration"]}


description: Detect unauthorized advertisement of your IP prefixes. title: Route Leak Detection image: https://developers.cloudflare.com/byoip/route-leak-detection/og.png?v=8ca61d5d0525a4fa


Skip to content

Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/byoip/llms.txt
Use this file to discover all available pages before exploring further.