全部產品
Search
文件中心

VPN Gateway:CreateVpnPbrRouteEntry

更新時間:Oct 08, 2026

呼叫CreateVpnPbrRouteEntry介面建立VPN策略路由。

介面說明

前提條件

  • 建立策略路由前,請確保您已經建立了 IPsec 連線。具體操作,請參見 CreateVpnConnection 。

  • 建立策略路由前,建議您先了解策略路由的使用限制、比對規則等資訊。更多資訊,請參見使用策略路由。

使用限制

  • 針對單隧道 VPN 閘道器:
    • 不支援 0.0.0.0/0 作為策略路由的目標網段。

    • 不支援與 100.64.0.0/10 存在位址重疊的網段(包括其本身、子網段及包含它的父網段)作為策略路由的目標網段。

  • CreateVpnPbrRouteEntry 介面屬於非同步介面,即系統先返回策略路由的資訊,但該策略路由尚未建立成功,系統後台的建立任務仍在進行。您可以呼叫 DescribeVpnGateway 介面查詢 VPN 閘道器執行個體狀態,來確定策略路由的建立狀態:
    • 當 VPN 閘道器執行個體處於 updating 狀態時,表示策略路由正在建立中。

    • 當 VPN 閘道器執行個體處於 active 狀態時,表示策略路由建立成功。

  • CreateVpnPbrRouteEntry 介面不支援在同一個 VPN 閘道器執行個體下並行建立策略路由。

調試

您可以在OpenAPI Explorer中直接運行該介面,免去您計算簽名的困擾。運行成功後,OpenAPI Explorer可以自動產生SDK程式碼範例。

調試

授權資訊

當前API暫無授權資訊透出。

請求參數

名稱

類型

必填

描述

樣本值

RegionId

string

是

VPN 閘道器執行個體所在的地域 ID。您可以透過呼叫 DescribeRegions 介面取得地域 ID。

cn-hangzhou

ClientToken

string

否

用戶端 Token,用於保證請求的冪等性。

從您的用戶端產生一個參數值,確保不同請求間該參數值唯一。ClientToken 只支援 ASCII 字元。

說明

若您未指定,則系統自動使用 API 請求的 RequestId 作為 ClientToken 標識。每次 API 請求的 RequestId 不一樣。

d7d24a21-f4ba-4454-9173-b3****

VpnGatewayId

string

是

VPN 閘道器執行個體的 ID。

vpn-bp1a3kqjiiq9legfx****

RouteSource

string

是

策略路由的來源網段。

192.168.1.0/24

RouteDest

string

是

策略路由的目標網段。

10.0.0.0/24

NextHop

string

是

策略路由的下一跳。

vco-bp15oes1py4i66rmd****

Weight

integer

是

策略路由的權重值。

在您使用同一個 VPN 閘道器執行個體搭建主備 IPsec-VPN 連線的場景中,您可以透過設定策略路由的權重值來指定主鏈路和備鏈路,權重值為 100 的策略路由預設為主鏈路,權重值為 0 的策略路由預設為備鏈路。

您可以透過為 IPsec 連線設定健康檢查來自動偵測鏈路的連通性,在主鏈路不通的情況下,系統自動將流量切換至備鏈路進行傳輸,實現上雲端鏈路的高可用性。具體操作,請參見 CreateVpnConnection 。

  • 100:表示目前策略路由關聯的 IPsec 連線為主鏈路。

  • 0:表示目前策略路由關聯的 IPsec 連線為備鏈路。

說明
  • 在您指定主備鏈路時,主策略路由和備策略路由的來源網段和目標網段需相同。

  • 對於支援雙隧道模式 IPsec-VPN 連線的 VPN 閘道器執行個體,無需設定該參數。一個雙隧道模式 IPsec-VPN 連線包含兩條隧道,兩條隧道自動形成主備鏈路,無需再透過設定該參數指定主備鏈路。如果您設定了該參數,則該參數設定後不生效。

0

PublishVpc

boolean

是

是否發佈策略路由到 VPC 中。取值:

  • true:發佈策略路由到 VPC 中,系統僅會將路由發佈至 VPC 系統路由表中,而不會發佈至 VPC 自訂路由表中。

    如果 VPC 自訂路由表中需要包含該路由,請您手動新增。具體操作,請參見 CreateRouteEntry 。

  • false:不發佈策略路由到 VPC 的路由表。

    您需要在 VPC 系統路由表和自訂路由表中手動新增下一跳指向 VPN 閘道器執行個體的策略路由,否則 VPC 將無法透過 IPsec-VPN 連線存取該網段下的資源。

true

Description

string

否

策略路由的描述資訊。

描述資訊長度為 1~100 個字元。

desctest

OverlayMode

string

否

隧道協定。僅取值:Ipsec(IPsec 隧道協定)。

Ipsec

Priority

integer

否

策略路由的策略優先順序。取值範圍:1~100。預設值:10。

策略優先順序數字越小,策略路由的優先順序越高。

10

DryRun

boolean

否

是否只預檢此次請求。取值:

  • true:傳送檢查請求,不會建立路由。檢查項目包括是否填寫了必需參數、請求格式、業務限制。如果檢查不通過,則返回對應錯誤。如果檢查通過,則返回錯誤碼DryRunOperation。

  • false(預設值):傳送正常請求,通過檢查後返回 HTTP 2xx 狀態碼並直接進行操作。

false

返回參數

名稱

類型

描述

樣本值

object

返回結果。

NextHop

string

策略路由的下一跳。

vco-bp15oes1py4i66rmd****

Weight

integer

策略路由的權重值。

  • 100:表示目前策略路由關聯的 IPsec 連線為主鏈路。

  • 0:表示目前策略路由關聯的 IPsec 連線為備鏈路。

0

RouteDest

string

策略路由的目標網段。

10.0.0.0/24

RequestId

string

請求 ID。

5BE01CD7-5A50-472D-AC14-CA181C5C03BE

Description

string

策略路由的描述資訊。

desctest

State

string

策略路由的發佈狀態。

  • published:已發佈策略路由到 VPC 的路由表。

  • normal:未發佈策略路由到 VPC 的路由表。

normal

CreateTime

integer

建立策略路由的時間戳記。單位:毫秒。

時間戳記的格式採用 Unix 時間戳記,表示從格林威治時間 1970 年 01 月 01 日 00 時 00 分 00 秒至建立策略路由時的總時長。

1492747187000

OverlayMode

string

隧道協定。僅取值:Ipsec(IPsec 隧道協定)。

Ipsec

RouteSource

string

策略路由的來源網段。

192.168.1.0/24

VpnInstanceId

string

VPN 閘道器執行個體 ID。

vpn-bp1cmw7jh1nfe43m9****

Priority

integer

策略路由的策略優先順序。

10

樣本

正常返回樣本

JSON格式

{
  "NextHop": "vco-bp15oes1py4i66rmd****",
  "Weight": 0,
  "RouteDest": "10.0.0.0/24",
  "RequestId": "5BE01CD7-5A50-472D-AC14-CA181C5C03BE",
  "Description": "desctest",
  "State": "normal",
  "CreateTime": 1492747187000,
  "OverlayMode": "Ipsec",
  "RouteSource": "192.168.1.0/24",
  "VpnInstanceId": "vpn-bp1cmw7jh1nfe43m9****",
  "Priority": 10
}

錯誤碼

HTTP status code

錯誤碼

錯誤資訊

描述

400 Resource.QuotaFull The quota of resource is full
400 VpnGateway.FinancialLocked The specified service is financial locked.
400 VpnRouteEntry.AlreadyExists The specified route entry is already exist. 該路由已存在。
400 VpnRouteEntry.Conflict The specified route entry has conflict. 路由項目存在衝突。
400 VpnRouteEntry.ConflictSSL The specified route entry has conflict with SSL client. 路由項目與SSL用戶端衝突。
400 VpnRouteEntry.BackupRoute Validate backup route entry failed. 主備路由條目校驗失敗。
400 VpnRouteEntry.InvalidWeight Invalid route entry weight value. 路由權重值不合法。
400 InvalidNextHop.NotFound The specified NextHop does not exist. 該下一跳位址不存在。
400 IllegalParam.RouteDest The specified RouteDest is invalid 目的位址不合法。
400 OperationFailed.RouteConflict Operation failed because there is already a route in VPC route table to another VPN on the same network block. 指定的首碼清單中的網段與IPsec連線中已有的路由項目衝突,請消除衝突後重試。
400 OperationFailed.InvalidCidrBlock Operation failed because the specified network block is invalid. 網段不合法。
400 QuotaExceeded.VpnRouteEntry The number of route entries to the VPN gateway in the VPC routing table has reached the quota limit. VPC路由表中指向VPN閘道器的路由條目已經達到配額限制。
400 VpnPbrRouteEntryPriority.NotSupport Current version of the VPN does not support setting custom pbr route entry priority. 當前版本VPN閘道不支援策略路由優先順序功能。
400 TaskConflict The operation is too frequent, please wait a moment and try again. EIP操作太頻繁。
400 VpnTask.CONFLICT Vpn task has conflict. VPN 操作存在衝突,請稍後重試。
400 VpnGateway.Configuring The specified service is configuring.
400 InternalError The request processing has failed due to some unknown error, exception or failure.
400 VpnRouteEntry.SrcDestWeightConflict The VPN gateway does not support Policy-based routing with the same source CIDR, destination CIDR and weight. VPN閘道器不支援設定來源網段、目標網段與權重同時相同的原則路由。
400 VpnRouteEntry.SamePriorityPbrRoutePrefixOverlap The source CIDR and destination CIDR of Policy-based routes with the same priority cannot overlap. VPN閘道器不支援相同優先順序下的多個原則路由來源和目標網段同時重合。
400 VpnRouteEntry.SrcDestConflict The VPN gateway does not support Policy-based routing with the same source CIDR and destination CIDR. 雙隧道類型的VPN閘道器不支援設定來源網段與目標網段同時相同的原則路由。
400 CreatePbrRoutesQuotaFull.QuotaFull The number of policy routes exceeds the quota limit. 策略路由數量超過配額限制。
400 InvalidCidrBlock.Malformed Specified CIDR block is not valid.
400 DryRunOperation Request validation has been passed with DryRun flag set. DryRun 驗證通過。
400 VpnPbrRouteEntry.NotSupport Current version of the VPN does not support pbr route entry. 目前 VPN 執行個體不支援原則路由。
403 Forbbiden.SubUser User not authorized to operate on the specified resource as your account is created by another user.
403 Forbidden User not authorized to operate on the specified resource. 您沒有權限操作指定資源,請申請權限後再操作。
404 InvalidVpnGatewayInstanceId.NotFound The specified vpn gateway instance id does not exist.

訪問錯誤中心查看更多錯誤碼。

變更歷史

更多資訊,參考變更詳情。