ROUTE_POLICY_PRIORITY: the priority for this policy,
such as1`.
ROUTE_POLICY_MATCH_EXPRESSION: un'espressione da associare
per questo criterio di route
ROUTE_POLICY_ACTIONS_EXPRESSION: azioni per questo
criterio di routing
Ad esempio, il seguente comando crea un criterio BGP per impostare il valore dell'attributo BGP MED (Multiple Exit Discriminator) su 12345 per le route BGP che non sono incluse in 192.168.10.0/24 e corrispondono all'insieme di comunità BGP 65000:1 e 65000:2.
Sostituisci ROUTE_POLICY_PRIORITY con la priorità che preferisci per questo criterio, ad esempio 1.
Carica una policy di route BGP
Crea il criterio di route BGP nel tuo editor di testo preferito. Puoi utilizzare la formattazione JSON o YAML per creare il criterio di route BGP. Nell'esempio seguente viene utilizzato un file YAML:
BGP_ROUTE_POLICY_NAME: un nome per la policy di route BGP.
ROUTE_POLICY_TYPE: il tipo di policy di route BGP
che stai creando. Il tipo può essere uno dei seguenti:
ROUTE_POLICY_TYPE_IMPORT: policy di route BGP per le route in entrata.
ROUTE_POLICY_TYPE_EXPORT: policy di route BGP per le route in uscita.
ROUTE_POLICY_PRIORITY: la priorità per questa norma,
ad esempio 1.
ROUTE_POLICY_MATCH_EXPRESSION: un'espressione da associare
per questo criterio di route
ROUTE_POLICY_ACTIONS_EXPRESSION: azioni per questo
criterio di routing
Ad esempio, il seguente comando del file YAML crea un criterio BGP per le route in entrata che imposta il valore dell'attributo MED (Multiple Exit Discriminator) BGP su 12345 per le route BGP non incluse in 192.168.10.0/24 e che corrispondono all'insieme di community BGP 65000:1 e 65000:2.
# 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: il nome del peer BGP a cui applicare il criterio di route BGP.
IMPORT_POLICIES: un elenco separato da virgole di criteri di importazione. Se passi una stringa vuota, vengono rimossi tutti i criteri di importazione.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-08 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)"]]