ROUTE_POLICY_PRIORITY: the priority for this policy,
such as1`.
ROUTE_POLICY_MATCH_EXPRESSION: uma expressão a ser correspondida com essa política de rota
ROUTE_POLICY_ACTIONS_EXPRESSION: ações para essa política de rota
Por exemplo, o comando a seguir cria uma política do BGP para definir o valor do atributo discriminador de várias saídas (MED, na sigla em inglês) do BGP como 12345 para rotas do BGP que não estão incluídas em 192.168.10.0/24 e que correspondem ao conjunto de comunidades do BGP 65000:1 e 65000:2.
Substitua ROUTE_POLICY_PRIORITY pela prioridade que você quer para essa política, como 1.
Fazer upload de uma política de rota do BGP
Crie a política de rota do BGP no editor de texto de sua preferência. Use a formatação JSON ou YAML para criar sua política de rota do BGP. O exemplo a seguir
usa um arquivo YAML:
BGP_ROUTE_POLICY_NAME: um nome para a política de rota
do BGP.
ROUTE_POLICY_TYPE: o tipo de política de rota do BGP
que você está criando. O tipo pode ser um dos seguintes:
ROUTE_POLICY_TYPE_IMPORT: políticas de rota do BGP para rotas de entrada.
ROUTE_POLICY_TYPE_EXPORT: políticas de rota do BGP para rotas de saída.
ROUTE_POLICY_PRIORITY: a prioridade dessa política, como 1.
ROUTE_POLICY_MATCH_EXPRESSION: uma expressão a ser correspondida com essa política de rota
ROUTE_POLICY_ACTIONS_EXPRESSION: ações para essa política de rota
Por exemplo, o comando de arquivo YAML a seguir cria uma política do BGP para rotas de entrada que define o valor do atributo discriminador de várias saídas (MED) do BGP como 12345 para rotas do BGP que não estão incluídas em 192.168.10.0/24 e que correspondem ao conjunto de comunidades do 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)
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-28 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)"]]