ROUTE_POLICY_PRIORITY: the priority for this policy,
such as1`.
ROUTE_POLICY_MATCH_EXPRESSION: ein Ausdruck, der mit dieser Routenrichtlinie abgeglichen werden soll
ROUTE_POLICY_ACTIONS_EXPRESSION: Aktionen für diese Routingrichtlinie
Mit dem folgenden Befehl wird beispielsweise eine BGP-Richtlinie erstellt, um den BGP MED-Attributwert (Multiple Exit Discriminator) auf 12345 festzulegen. Dies gilt für BGP-Routen, die nicht in 192.168.10.0/24 enthalten sind und mit den BGP-Communitys 65000:1 und 65000:2 übereinstimmen.
Ersetzen Sie ROUTE_POLICY_PRIORITY durch die gewünschte Priorität für diese Richtlinie, z. B. 1.
BGP-Routenrichtlinie hochladen
Erstellen Sie die BGP-Routenrichtlinie in Ihrem bevorzugten Texteditor. Sie können die BGP-Routenrichtlinie in JSON- oder YAML-Format erstellen. Im folgenden Beispiel wird eine YAML-Datei verwendet:
BGP_ROUTE_POLICY_NAME: ein Name für die BGP-Routenrichtlinie.
.
ROUTE_POLICY_TYPE: die Art der BGP-Routenrichtlinie, die Sie erstellen. Der Typ kann einer der folgenden sein:
ROUTE_POLICY_TYPE_IMPORT: BGP-Routenrichtlinien für eingehende Routen.
ROUTE_POLICY_TYPE_EXPORT: BGP-Routenrichtlinien für ausgehende Routen.
ROUTE_POLICY_PRIORITY: die Priorität für diese Richtlinie, z. B. 1.
ROUTE_POLICY_MATCH_EXPRESSION: ein Ausdruck, der mit dieser Routenrichtlinie abgeglichen werden soll
ROUTE_POLICY_ACTIONS_EXPRESSION: Aktionen für diese Routingrichtlinie
Mit dem folgenden Befehl für eine YAML-Datei wird beispielsweise eine BGP-Richtlinie für eingehende Routen erstellt, die den BGP MED-Attributwert (Multiple Exit Discriminator) auf 12345 für BGP-Routen festlegt, die nicht in 192.168.10.0/24 enthalten sind und mit den BGP-Communitys 65000:1 und 65000:2 übereinstimmen.
# Set the MED value for BGP routes that aren't 192.168.10.0/24 and# communities that include (65000:1, 65000:2)name:BGP_ROUTE_POLICY_NAMEtype:ROUTE_POLICY_TYPE_IMPORTterms:-priority:1match:expression:>
destination != '192.168.10.0/24' && communities.matchesEvery(['65000:1', '65000:2'])actions:-expression:med.set(12345)
PEER_NAME: der Name des BGP-Peers, auf den die BGP-Routenrichtlinie angewendet werden soll.
IMPORT_POLICIES: eine durch Kommas getrennte Liste von Importrichtlinien. Wenn Sie einen leeren String übergeben, werden alle Importrichtlinien entfernt.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-08-12 (UTC)."],[],[],null,["# Create BGP route policies\n=========================\n\nThis guide describes how to create BGP route policies in Cloud Router.\n\nYou can create BGP route policies for Cloud Router using any of the\nfollowing:\n\n- Use your preferred text editor to create a BGP route policy, and then use the gcloud CLI to [upload the BGP route\n policy](#upload-a-bpg-route-policy)\n\nBuild a BGP route policy\n------------------------\n\n1. Add a route policy to your Cloud Router:\n\n ```\n gcloud compute routers add-route-policy ROUTER_NAME \\\n --policy-name=BGP_ROUTE_POLICY_NAME \\\n --policy-type=ROUTE_POLICY_TYPE \\\n --region=REGION\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eROUTER_NAME\u003c/var\u003e: the name of the Cloud Router\n - \u003cvar translate=\"no\"\u003eBGP_ROUTE_POLICY_NAME\u003c/var\u003e: a name for the BGP route policy\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_TYPE\u003c/var\u003e: the type of policy to add, either `IMPORT` for inbound routes, or `EXPORT` for outbound routes.\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region that the Cloud Router is located in\n\n For example, the following command adds a route policy for inbound routes\n to your Cloud Router: \n\n ```\n gcloud compute routers add-route-policy ROUTER_NAME \\\n --policy-name=BGP_ROUTE_POLICY_NAME \\\n --policy-type=IMPORT \\\n --region=REGION\n ```\n2. Add a BGP route policy term by running the following command:\n\n ```\n gcloud compute routers add-route-policy-term ROUTER_NAME \\\n --policy-name=BGP_ROUTE_POLICY_NAME \\\n --region=REGION \\\n --priority=ROUTE_POLICY_PRIORITY \\\n --match=ROUTE_POLICY_MATCH_EXPRESSION \\\n --actions=ROUTE_POLICY_ACTIONS_EXPRESSION\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_PRIORITY\u003c/var\u003e`: the priority for this policy,\n such as`1\\`.\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_MATCH_EXPRESSION\u003c/var\u003e: an expression to match for this route policy\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_ACTIONS_EXPRESSION\u003c/var\u003e: actions for this route policy\n\n For example, the following command creates a BGP policy to set the BGP\n multiple exit discriminator (MED) attribute value to `12345` for BGP routes\n that aren't included in `192.168.10.0/24` and that match the set of\n BGP communities `65000:1` and `65000:2`. \n\n ```\n gcloud compute routers add-route-policy-term ROUTER_NAME \\\n --policy-name=BGP_ROUTE_POLICY_NAME \\\n --region=REGION \\\n --priority=ROUTE_POLICY_PRIORITY \\\n --match='destination != \"192.168.10.0/24\" && communities.matchesEvery([\"65000:1\", \"65000:2\"])' \\\n --actions='med.set(12345)'\n ```\n\n Replace \u003cvar translate=\"no\"\u003eROUTE_POLICY_PRIORITY\u003c/var\u003e with the priority you\n want for this policy, such as `1`.\n\nUpload a BGP route policy\n-------------------------\n\n1. Create the BGP route policy in your preferred text editor. You can use JSON\n or YAML formatting to create your BGP route policy. The following example\n uses a YAML file:\n\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eBGP_ROUTE_POLICY_NAME\u003c/span\u003e\u003c/var\u003e\n type: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eROUTE_POLICY_TYPE\u003c/span\u003e\u003cspan class=\"devsite-syntax-w\"\u003e \u003c/span\u003e\u003c/var\u003e\n terms:\n - priority: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eROUTE_POLICY_PRIORITY\u003c/span\u003e\u003c/var\u003e\n match:\n expression: \u003e\n \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eROUTE_POLICY_MATCH_EXPRESSION\u003c/span\u003e\u003c/var\u003e\n actions:\n - expression: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eROUTE_POLICY_ACTIONS_EXPRESSION\u003c/span\u003e\u003c/var\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eBGP_ROUTE_POLICY_NAME\u003c/var\u003e: a name for the BGP route policy.\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_TYPE\u003c/var\u003e: the type of BGP route policy\n you're creating. The type can be one of the following:\n\n - `ROUTE_POLICY_TYPE_IMPORT`: BGP route policies for inbound routes.\n - `ROUTE_POLICY_TYPE_EXPORT`: BGP route policies for outbound routes.\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_PRIORITY\u003c/var\u003e: the priority for this policy,\n such as `1`.\n\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_MATCH_EXPRESSION\u003c/var\u003e: an expression to match\n for this route policy\n\n - \u003cvar translate=\"no\"\u003eROUTE_POLICY_ACTIONS_EXPRESSION\u003c/var\u003e: actions for this\n route policy\n\n For example, the following YAML file command creates a BGP policy for\n inbound routes that sets the BGP multiple exit discriminator (MED) attribute\n value to `12345` for BGP routes that aren't included in `192.168.10.0/24`\n and that match the set of BGP communities `65000:1` and `65000:2`. \n\n # Set the MED value for BGP routes that aren't 192.168.10.0/24 and\n # communities that include (65000:1, 65000:2)\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eBGP_ROUTE_POLICY_NAME\u003c/span\u003e\u003c/var\u003e\n type: ROUTE_POLICY_TYPE_IMPORT\n terms:\n - priority: 1\n match:\n expression: \u003e\n destination != '192.168.10.0/24' && communities.matchesEvery(['65000:1', '65000:2'])\n actions:\n - expression: med.set(12345)\n\n2. Upload the BGP route policy:\n\n ```\n gcloud compute routers upload-route-policy ROUTER_NAME \\\n --region=REGION \\\n --policy-name=BGP_ROUTE_POLICY_NAME \\\n --file-name=FILE_NAME \\\n --file-format=yaml\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eROUTER_NAME\u003c/var\u003e: the name of the Cloud Router\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: the region the Cloud Router is in\n - \u003cvar translate=\"no\"\u003eFILENAME\u003c/var\u003e: the filename that you're uploading\n3. Apply the BGP route policies to BGP peers:\n\n ```\n gcloud compute routers update-bgp-peer ROUTER_NAME \\\n --region=REGION \\\n --peer-name=PEER_NAME \\\n --import-policies='IMPORT_POLICIES'\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePEER_NAME\u003c/var\u003e: the BGP peer's name to apply the BGP route policy to.\n - \u003cvar translate=\"no\"\u003eIMPORT_POLICIES\u003c/var\u003e: a comma-separated list of import policies. Passing an empty string removes all import policies.\n\nWhat's next\n-----------\n\n- [Update BGP route\n policies](/network-connectivity/docs/router/how-to/bgp-route-policies/update-policies)\n- [Apply BGP route policies](/network-connectivity/docs/router/how-to/bgp-route-policies/apply-policies)"]]