ROUTE_POLICY_PRIORITY: the priority for this policy,
such as1`.
ROUTE_POLICY_MATCH_EXPRESSION: expression à faire correspondre pour cette règle de routage
ROUTE_POLICY_ACTIONS_EXPRESSION: actions pour cette règle de routage
Par exemple, la commande suivante crée une règle BGP pour définir la valeur de l'attribut BGP de discriminateur multisortie (MED) sur 12345 pour les routes BGP qui ne sont pas incluses dans 192.168.10.0/24 et qui correspondent à l'ensemble des communautés BGP 65000:1 et 65000:2.
Remplacez ROUTE_POLICY_PRIORITY par la priorité souhaitée pour cette stratégie, par exemple 1.
Importer une règle de routage BGP
Créez la règle de routage BGP dans l'éditeur de texte de votre choix. Vous pouvez utiliser le format JSON ou YAML pour créer votre règle de routage BGP. L'exemple suivant utilise un fichier YAML :
BGP_ROUTE_POLICY_NAME : nom de la règle de routage BGP
ROUTE_POLICY_TYPE : type de règle de routage BGP que vous créez. Le type peut être l'un des suivants :
ROUTE_POLICY_TYPE_IMPORT : règles de routage BGP pour les routes entrantes.
ROUTE_POLICY_TYPE_EXPORT : règles de routage BGP pour les routes sortantes.
ROUTE_POLICY_PRIORITY: priorité de cette règle, par exemple 1.
ROUTE_POLICY_MATCH_EXPRESSION: expression à faire correspondre pour cette règle de routage
ROUTE_POLICY_ACTIONS_EXPRESSION: actions pour cette règle de routage
Par exemple, la commande de fichier YAML suivante crée une règle BGP pour les routes entrantes qui définit la valeur de l'attribut BGP de discriminateur multisortie (MED) sur 12345 pour les routes BGP qui ne sont pas incluses dans 192.168.10.0/24 et qui correspondent à l'ensemble des communautés BGP 65000:1 et 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)
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/09/08 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 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)"]]