ROUTE_POLICY_PRIORITY: the priority for this policy,
such as1`.
ROUTE_POLICY_MATCH_EXPRESSION: ekspresi yang akan dicocokkan
untuk kebijakan rute ini
ROUTE_POLICY_ACTIONS_EXPRESSION: tindakan untuk kebijakan rute ini
Misalnya, perintah berikut membuat kebijakan BGP untuk menetapkan nilai atribut BGP multiple exit discriminator (MED) ke 12345 untuk rute BGP yang tidak disertakan dalam 192.168.10.0/24 dan yang cocok dengan kumpulan komunitas BGP 65000:1 dan 65000:2.
Ganti ROUTE_POLICY_PRIORITY dengan prioritas yang Anda inginkan untuk kebijakan ini, seperti 1.
Mengupload kebijakan rute BGP
Buat kebijakan rute BGP di editor teks pilihan Anda. Anda dapat menggunakan format JSON
atau YAML untuk membuat kebijakan rute BGP. Contoh berikut menggunakan file YAML:
BGP_ROUTE_POLICY_NAME: nama untuk kebijakan rute BGP.
ROUTE_POLICY_TYPE: jenis kebijakan rute BGP
yang Anda buat. Jenisnya dapat berupa salah satu dari berikut:
ROUTE_POLICY_TYPE_IMPORT: Kebijakan rute BGP untuk rute masuk.
ROUTE_POLICY_TYPE_EXPORT: Kebijakan rute BGP untuk rute keluar.
ROUTE_POLICY_PRIORITY: prioritas untuk kebijakan ini,
seperti 1.
ROUTE_POLICY_MATCH_EXPRESSION: ekspresi yang akan dicocokkan
untuk kebijakan rute ini
ROUTE_POLICY_ACTIONS_EXPRESSION: tindakan untuk kebijakan rute ini
Misalnya, perintah file YAML berikut membuat kebijakan BGP untuk
rute masuk yang menetapkan nilai atribut BGP multiple exit discriminator (MED)
ke 12345 untuk rute BGP yang tidak disertakan dalam 192.168.10.0/24
dan yang cocok dengan kumpulan komunitas BGP 65000:1 dan 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)
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)"]]