Note

If you are connecting to Cloudflare via a [Direct CNI connection](https://developers.cloudflare.com/network-interconnect/express-cni/), refer to [BGP peering](https://developers.cloudflare.com/magic-wan/configuration/manually/how-to/bgp-peering/) to learn how to take advantage of this [routing](https://www.cloudflare.com/learning/network-layer/what-is-routing/) protocol. If not, continue reading.

Magic WAN uses a static configuration to route your traffic through [anycast tunnels](https://developers.cloudflare.com/magic-wan/reference/tunnels/) from Cloudflare's global network to your locations.

You must assign a route priority to each tunnel-subnet pair in your configuration, as follows:

* Lower values have greater priority.
* When the priority values for prefix entries match, Cloudflare uses equal-cost multi-path (ECMP) packet forwarding to route traffic. The maximum number of routes you can have with the same priority is 64. For more on how Cloudflare uses ECMP packet forwarding, refer to [Traffic steering](https://developers.cloudflare.com/magic-wan/reference/traffic-steering/).

You can also create and edit static routes using the [Magic Static Routes API](https://developers.cloudflare.com/api/resources/magic_transit/subresources/routes/methods/list/).

## Edge routing configuration example

| Prefix            | NextHop        | Priority |
| ----------------- | -------------- | -------- |
| `10.10.10.100/24` | `TUNNEL_1_IAD` | `100`    |
| `10.10.10.100/24` | `TUNNEL_2_IAD` | `100`    |
| `10.10.10.100/24` | `TUNNEL_3_ATL` | `100`    |
| `10.10.10.100/24` | `TUNNEL_4_ATL` | `100`    |
| `10.10.10.100/24` | `TUNNEL_1_IAD` | `200`    |
| `10.10.10.100/24` | `TUNNEL_2_IAD` | `200`    |
| `10.10.10.100/24` | `TUNNEL_3_ATL` | `100`    |
| `10.10.10.100/24` | `TUNNEL_4_ATL` | `100`    |

Optionally, you can assign weights to distribute traffic more effectively among multiple tunnels. The weight values determine the proportion of traffic directed to each tunnel, with higher weights resulting in a greater share of traffic. The maximum weight value is `256`.

In the example below, `TUNNEL_2_IAD` is likely to receive twice as much traffic as `TUNNEL_1_IAD`.

| Prefix            | NextHop        | Priority | Weight |
| ----------------- | -------------- | -------- | ------ |
| `10.10.10.100/24` | `TUNNEL_1_IAD` | `100`    | `64`   |
| `10.10.10.100/24` | `TUNNEL_2_IAD` | `100`    | `128`  |
| `10.10.10.100/24` | `TUNNEL_3_ATL` | `100`    | `192`  |
| `10.10.10.100/24` | `TUNNEL_4_ATL` | `100`    | `255`  |

## Scoped routes for anycast GRE or IPsec tunnels

To reduce latency for your anycast GRE or IPsec tunnel configurations, especially if you operate your own anycast network, Cloudflare can steer your traffic by scoping it to specific Cloudflare data center regions. Equal cost routes maintain an equal cost on a global scale so long as the routes are not scoped to specific regions. For example, if you use region-scoped routes, traffic from end users in New York will always land at their Ashburn network unless that tunnel is unhealthy.

When you scope static routes to specific regions, the routes will only exist in the specified regions, and traffic that lands outside the specified regions will not have anywhere to go.

To configure scoping for your traffic, you must provide static routes to Cloudflare with anycast GRE or IPsec tunnel data such that all Cloudflare regions have a route for your prefixes.

Note

Regions and regional objects are automatically updated. If you route traffic through specific data centers, you will need to manually update your rules when Cloudflare adds or removes data centers.

### Scoping configuration data example

| Prefix            | NextHop        | Priority | Region code |
| ----------------- | -------------- | -------- | ----------- |
| `10.10.10.100/24` | `TUNNEL_1_IAD` | `100`    | *AFR*       |
| `10.10.10.100/24` | `TUNNEL_2_IAD` | `100`    | *EEUR*      |
| `10.10.10.100/24` | `TUNNEL_3_ATL` | `100`    | *ENAM*      |
| `10.10.10.100/24` | `TUNNEL_4_ATL` | `100`    | *ME*        |

**Region codes and associated regions**

Cloudflare has nine geographic regions across the world which are listed below.

| Region code | Region                |
| ----------- | --------------------- |
| *AFR*       | Africa                |
| *APAC*      | Asia Pacific          |
| *EEUR*      | Eastern Europe        |
| *ENAM*      | Eastern North America |
| *ME*        | Middle East           |
| *OC*        | Oceania               |
| *SAM*       | South America         |
| *WEUR*      | Western Europe        |
| *WNAM*      | Western North America |

Configure scoping for your traffic in the **Region code** section when adding or editing a static route. Refer to [Create a static route](#create-a-static-route) and [Edit a static route](#edit-a-static-route) more information.

## Allowed IP ranges

By default, you can only add static routes with RFC 1918 IP prefixes like:

* `10.0.0.0/8`
* `172.16.0.0/12`
* `192.168.0.0/16`

When using Magic WAN and Cloudflare Tunnel together, remember to consider the IP ranges utilized in the static routes of Cloudflare Tunnel when selecting static routes for Magic WAN. For more information, refer to [Cloudflare Tunnel](https://developers.cloudflare.com/magic-wan/zero-trust/cloudflare-tunnel/).

For prefixes outside RFC 1918 contact your Cloudflare customer service manager.

## Create a static route

* Dashboard

  1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/login), and select your account.
  2. Go to **Magic WAN > Configuration**.
  3. From the **Routes** tab, select **Create** to add a new route.
  4. Enter a descriptive name for your route in **Description**.
  5. In **Prefix**, enter your range of IP addresses. For example, `10.10.10.100/24`.
  6. In **Tunnel/Next hop** select which tunnel you want your route to go through. Choose from the tunnels you have created in [Configure tunnel endpoints](https://developers.cloudflare.com/magic-wan/configuration/manually/how-to/configure-tunnels/).
  7. Choose the **Priority** for your route. Lower numbers have higher priorities.
  8. (Optional) Choose a **Weight** for your route. Refer to [Edge routing configuration example](#edge-routing-configuration-example) for examples.
  9. (Optional) If you need to scope your route to a specific region, you can do it in **Region code**.
  10. (Optional) We highly recommend testing your route before adding it by selecting **Test routes**.
  11. Select **Add routes** when you are done.

* API

  Note

  You will need your [account ID](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/) and [API Key](https://developers.cloudflare.com/fundamentals/api/get-started/keys/#view-your-global-api-key) to use the API.

  Create a `POST` request [using the API](https://developers.cloudflare.com/api/resources/magic_transit/subresources/routes/methods/create/) to create one or more static routes.

  Example:

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/routes \
    --request POST \
    --header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
    --header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
    --json '{
      "nexthop": "<IP_NEXT_HOP>",
      "prefix": "<YOUR_IP_PREFIX>",
      "priority": 0,
      "id": "023e105f4ecef8ad9ca31a8372d0c353",
      "description": "<ROUTE_DESCRIPTION>",
      "scope": {
          "colo_names": [
              "den01"
          ],
          "colo_regions": [
              "APAC"
          ]
      },
      "weight": 0
    }'
  ```

  ```json
  {
    "errors": [
      {
        "code": 1000,
        "message": "message"
      }
    ],
    "messages": [
      {
        "code": 1000,
        "message": "message"
      }
    ],
    "result": {
      "routes": [
        {
          "nexthop": "203.0.113.1",
          "prefix": "192.0.2.0/24",
          "priority": 0,
          "id": "023e105f4ecef8ad9ca31a8372d0c353",
          "description": "New route for new prefix 203.0.113.1",
          "scope": {
            "colo_names": [
              "den01"
            ],
            "colo_regions": [
              "APAC"
            ]
          },
          "weight": 0
        }
      ]
    },
    "success": true
  }
  ```

## Edit a static route

* Dashboard

  1. In **Routes**, select **Edit** next to the route you want to modify.
  2. Enter the updated route information.
  3. (Optional) We highly recommend testing your route before adding it by selecting **Test routes**.
  4. Select **Edit routes** to save the new information when you are done.

* API

  Note

  You will need your [account ID](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/) and [API Key](https://developers.cloudflare.com/fundamentals/api/get-started/keys/#view-your-global-api-key) to use the API.

  Create a `PUT` request [using the API](https://developers.cloudflare.com/api/resources/magic_transit/subresources/routes/methods/update/) to update one or more static routes.

  Example:

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/routes/$ROUTE_ID \
    --request PUT \
    --header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
    --header "X-Auth-Key: $CLOUDFLARE_API_KEY" \
    --json '{
      "nexthop": "<IP_NEXT_HOP>",
      "prefix": "<YOUR_IP_PREFIX>",
      "priority": 0,
      "id": "023e105f4ecef8ad9ca31a8372d0c353",
      "description": "<ROUTE_DESCRIPTION>",
      "scope": {
          "colo_names": [
              "den01"
          ],
          "colo_regions": [
              "APAC"
          ]
      },
      "weight": 0
    }'
  ```

  ```json
  {
    "errors": [
      {
        "code": 1000,
        "message": "message"
      }
    ],
    "messages": [
      {
        "code": 1000,
        "message": "message"
      }
    ],
    "result": {
      "modified": true,
      "modified_route": {
        "nexthop": "203.0.113.1",
        "prefix": "192.0.2.0/24",
        "priority": 0,
        "id": "023e105f4ecef8ad9ca31a8372d0c353",
        "description": "New route for new prefix 203.0.113.1",
        "scope": {
          "colo_names": [
            "den01"
          ],
          "colo_regions": [
            "APAC"
          ]
        },
        "weight": 0
      }
    },
    "success": true
  }
  ```

## Delete static route

* Dashboard

  1. In **Routes**, locate the static route you want to modify and select **Delete**.
  2. Confirm the action by selecting the checkbox and select **Delete**.

* API

  Note

  You will need your [account ID](https://developers.cloudflare.com/fundamentals/setup/find-account-and-zone-ids/) and [API Key](https://developers.cloudflare.com/fundamentals/api/get-started/keys/#view-your-global-api-key) to use the API.

  Create a `DELETE` request [using the API](https://developers.cloudflare.com/api/resources/magic_transit/subresources/routes/methods/delete/) to delete a static route.

  Example:

  ```bash
  curl https://api.cloudflare.com/client/v4/accounts/$ACCOUNT_ID/magic/routes/$ROUTE_ID \
    --request DELETE \
    --header "X-Auth-Email: $CLOUDFLARE_EMAIL" \
    --header "X-Auth-Key: $CLOUDFLARE_API_KEY"
  ```

  ```json
  {
    "errors": [
      {
        "code": 1000,
        "message": "message"
      }
    ],
    "messages": [
      {
        "code": 1000,
        "message": "message"
      }
    ],
    "result": {
      "deleted": true,
      "deleted_route": {
        "nexthop": "203.0.113.1",
        "prefix": "192.0.2.0/24",
        "priority": 0,
        "id": "023e105f4ecef8ad9ca31a8372d0c353",
        "description": "New route for new prefix 203.0.113.1",
        "scope": {
          "colo_names": [
            "den01"
          ],
          "colo_regions": [
            "APAC"
          ]
        },
        "weight": 0
      }
    },
    "success": true
  }
  ```

## Next steps

Now that you have configured your tunnels and static routes, the next step is to create a site.

Sites represent the local network of a data center, office, or other physical location, and combine all on-ramps available there. Sites also allow you to check, at a glance, the state of your on-ramps and set up health alert settings so that you get notified when there are issues with the site's on-ramps.

Refer to [Set up a site](https://developers.cloudflare.com/magic-wan/configuration/common-settings/sites/) for more information.
