帮助我们改善您的体验。

让我们了解您的想法。

您是否能抽出两分钟的时间完成一份问卷调查?

Announcement: Try the Ask AI chatbot for answers to your technical questions about Juniper products and solutions.

close
header-navigation
keyboard_arrow_up
close
keyboard_arrow_left
list Table of Contents
keyboard_arrow_right

机器翻译对您有帮助吗?

starstarstarstarstar
Go to English page
免责声明:

我们将使用第三方机器翻译软件翻译本页面。瞻博网络虽已做出相当大的努力提供高质量译文,但无法保证其准确性。如果对译文信息的准确性有任何疑问,请参阅英文版本. 可下载的 PDF 仅提供英文版.

示例:在路由策略中配置扩展社区

date_range 18-Jan-25

扩展社区在大多数方面与常规社区相似。某些网络实现(如虚拟专用网络 (VPN))使用扩展社区,因为 4 个八位字节的常规社区值无法提供足够的扩展和灵活性。扩展社区是一个八位字节值,分为两个主要部分。

要求

配置此示例之前,不需要除设备初始化之外的特殊配置。

概述

在此示例中,设备 R1 和设备 R2 是自治系统 (AS) 64510 中的 OSPF 邻接方。设备 R3 具有到设备 R1 的外部 BGP (EBGP) 连接。设备 R2 在 172.16/16 地址空间中具有客户网络,使用其环路接口 (lo0) 上的地址进行模拟。设备 R1 具有到多个 172.16 的静态路由。x/24网络,并为这些路线赋予常规的社区价值。然后,设备 R1 使用导出策略将路由通告到设备 R3。设备 R3 接收这些路由,并使用导入策略将扩展社区值添加到路由。

注:

有关受支持的扩展社区的列表,

请参阅 了解 BGP 社区、扩展社区和大型社区作为路由策略匹配条件

拓扑学

图 1 显示了示例网络。

图 1: 扩展 BGP 社区的拓扑扩展 BGP 社区的拓扑

CLI 快速配置 显示了 中 图 1所有设备的配置。

#configuration587__policy-extended-community-st本节介绍设备 R3 上的步骤。

配置

CLI 快速配置

要快速配置此示例,请复制以下命令,将其粘贴到文本文件中,删除所有换行符,更改与您的网络配置匹配所需的任何详细信息,然后将命令复制并粘贴到层次结构级别的 CLI [edit] 中。

设备 R1

content_copy zoom_out_map
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30
set interfaces fe-1/2/3 unit 0 family inet address 10.0.0.14/30
set interfaces lo0 unit 0 family inet address 192.168.0.1/32 primary
set protocols bgp group ext type external
set protocols bgp group ext export send-static
set protocols bgp group ext peer-as 64511
set protocols bgp group ext neighbor 10.0.0.13
set protocols ospf area 0.0.0.0 interface fe-1/2/0.0
set protocols ospf area 0.0.0.0 interface lo0.0 passive
set policy-options policy-statement send-static term 1 from protocol static
set policy-options policy-statement send-static term 1 then accept
set routing-options static route 172.16.1.0/24 next-hop 10.0.0.2
set routing-options static route 172.16.1.0/24 community 64510:1
set routing-options static route 172.16.2.0/24 next-hop 10.0.0.2
set routing-options static route 172.16.2.0/24 community 64510:2
set routing-options static route 172.16.3.0/24 next-hop 10.0.0.2
set routing-options static route 172.16.3.0/24 community 64510:3
set routing-options static route 172.16.4.0/24 next-hop 10.0.0.2
set routing-options static route 172.16.4.0/24 community 64510:4
set routing-options router-id 192.168.0.1
set routing-options autonomous-system 64510

设备 R2

content_copy zoom_out_map
set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.2/30
set interfaces lo0 unit 0 family inet address 192.168.0.2/32
set interfaces lo0 unit 0 family inet address 172.16.1.1/32
set interfaces lo0 unit 0 family inet address 172.16.2.2/32
set interfaces lo0 unit 0 family inet address 172.16.3.3/32
set interfaces lo0 unit 0 family inet address 172.16.4.4/32
set protocols ospf area 0.0.0.0 interface fe-1/2/0.0
set protocols ospf area 0.0.0.0 interface lo0.0 passive
set routing-options router-id 192.168.0.2
set routing-options autonomous-system 64510

设备 R3

content_copy zoom_out_map
set interfaces fe-1/2/3 unit 0 family inet address 10.0.0.13/30
set interfaces lo0 unit 0 family inet address 192.168.0.3/32
set protocols bgp group to-R1 type external
set protocols bgp group to-R1 import set-ext-comms
set protocols bgp group to-R1 peer-as 64510
set protocols bgp group to-R1 neighbor 10.0.0.14
set policy-options policy-statement set-ext-comms term route-1 from route-filter 172.16.1.0/24 exact
set policy-options policy-statement set-ext-comms term route-1 then community add target-as
set policy-options policy-statement set-ext-comms term route-1 then accept
set policy-options policy-statement set-ext-comms term route-2 from route-filter 172.16.2.0/24 exact
set policy-options policy-statement set-ext-comms term route-2 then community add target-ip
set policy-options policy-statement set-ext-comms term route-2 then accept
set policy-options policy-statement set-ext-comms term route-3 from route-filter 172.16.3.0/24 exact
set policy-options policy-statement set-ext-comms term route-3 then community add origin-as
set policy-options policy-statement set-ext-comms term route-3 then accept
set policy-options policy-statement set-ext-comms term route-4 from route-filter 172.16.4.0/24 exact
set policy-options policy-statement set-ext-comms term route-4 then community add origin-ip
set policy-options policy-statement set-ext-comms term route-4 then accept
set policy-options community origin-as members origin:64511:3
set policy-options community origin-ip members origin:172.16.7.7:4
set policy-options community target-as members target:64511:1
set policy-options community target-ip members target:172.16.7.7:2
set routing-options router-id 192.168.0.3
set routing-options autonomous-system 64511

程序

分步过程

以下示例要求您在配置层次结构中导航各个级别。有关导航 CLI 的信息,请参阅 在配置模式下使用 CLI 编辑器Junos OS CLI 用户指南

要配置设备 R3:

  1. 配置接口。

    content_copy zoom_out_map
    [edit interfaces]
    user@R3# set fe-1/2/3 unit 0 family inet address 10.0.0.13/30
    user@R3# set lo0 unit 0 family inet address 192.168.0.3/32
    
  2. 配置与设备 R1 的 EBGP 连接。

    content_copy zoom_out_map
    [edit protocols bgp group to-R1]
    user@R3# set type external
    user@R3# set import set-ext-comms
    user@R3# set peer-as 64510
    user@R3# set neighbor 10.0.0.14
    
  3. 配置将扩展社区值添加到从设备 R1 接收的路由的策略。

    扩展社区使用 的 type:administrator:assigned-number表示法。

    特定社区值可以是在特定参数范围内实现管理目标的任何值,如中所述 community (Policy Options)

    content_copy zoom_out_map
    [edit policy-options policy-statement set-ext-comms]
    user@R3# set term route-1 from route-filter 172.16.1.0/24 exact
    user@R3# set term route-1 then community add target-as
    user@R3# set term route-1 then accept
    user@R3# set term route-2 from route-filter 172.16.2.0/24 exact
    user@R3# set term route-2 then community add target-ip
    user@R3# set term route-2 then accept
    user@R3# set term route-3 from route-filter 172.16.3.0/24 exact
    user@R3# set term route-3 then community add origin-as
    user@R3# set term route-3 then accept
    user@R3# set term route-4 from route-filter 172.16.4.0/24 exact
    user@R3# set term route-4 then community add origin-ip
    user@R3# set term route-4 then accept
    [edit policy-options]
    user@R3# set community origin-as members origin:64511:3
    user@R3# set community origin-ip members origin:172.16.7.7:4
    user@R3# set community target-as members target:64511:1
    user@R3# set community target-ip members target:172.16.7.7:2
    
  4. 配置自治系统 (AS) 编号和路由器 ID。

    content_copy zoom_out_map
    [edit routing-options]
    user@R3# set router-id 192.168.0.3
    user@R3# set autonomous-system 64511
    

结果

在配置模式下,输入 show interfacesshow protocolsshow policy-optionsshow routing-options 命令,以确认您的配置。如果输出未显示预期的配置,请重复此示例中的说明,以便进行更正。

content_copy zoom_out_map
user@R3# show interfaces
fe-1/2/3 {
    unit 0 {
        family inet {
            address 10.0.0.13/30;
        }
    }
}
lo0 {
    unit 0 {
        family inet {
            address 192.168.0.3/32;
        }
    }
}
content_copy zoom_out_map
user@R3# show protocols
bgp {
    group to-R1 {
        type external;
        import set-ext-comms;
        peer-as 64510;
        neighbor 10.0.0.14;
    }
}
content_copy zoom_out_map
user@R3# show policy-options
policy-statement set-ext-comms {
    term route-1 {
        from {
            route-filter 172.16.1.0/24 exact;
        }
        then {
            community add target-as;
            accept;
        }
    }
    term route-2 {
        from {
            route-filter 172.16.2.0/24 exact;
        }
        then {
            community add target-ip;
            accept;
        }
    }
    term route-3 {
        from {
            route-filter 172.16.3.0/24 exact;
        }
        then {
            community add origin-as;
            accept;
        }
    }
    term route-4 {
        from {
            route-filter 172.16.4.0/24 exact;
        }
        then {
            community add origin-ip;
            accept;
        }
    }
}
community origin-as members origin:64511:3;
community origin-ip members origin:172.16.7.7:4;
community target-as members target:64511:1;
community target-ip members target:172.16.7.7:2;
content_copy zoom_out_map
user@R3# show routing-options
router-id 192.168.0.3;
autonomous-system 64511;

如果完成设备配置,请从配置模式输入 commit

验证

确认配置工作正常。

验证设备 R1 上的路由

目的

在设备 R1 上,检查 172.16。路由表中的路由。

操作

content_copy zoom_out_map
user@R1> show route protocol static match-prefix 172.16.* detail

inet.0: 15 destinations, 15 routes (15 active, 0 holddown, 0 hidden)
172.16.1.0/24 (1 entry, 1 announced)
        *Static Preference: 5
                Next hop type: Router, Next hop index: 835
                Address: 0x9260250
                Next-hop reference count: 19
                Next hop: 10.0.0.2 via fe-1/2/0.0, selected
                State: <Active Int Ext>
                Local AS: 64510 
                Age: 2:06:08 
                Task: RT
                Announcement bits (2): 2-KRT 3-BGP_RT_Background 
                AS path: I
                Communities: 64510:1

172.16.2.0/24 (1 entry, 1 announced)
        *Static Preference: 5
                Next hop type: Router, Next hop index: 835
                Address: 0x9260250
                Next-hop reference count: 19
                Next hop: 10.0.0.2 via fe-1/2/0.0, selected
                State: <Active Int Ext>
                Local AS: 64510 
                Age: 2:06:08 
                Task: RT
                Announcement bits (2): 2-KRT 3-BGP_RT_Background 
                AS path: I
                Communities: 64510:2

172.16.3.0/24 (1 entry, 1 announced)
        *Static Preference: 5
                Next hop type: Router, Next hop index: 835
                Address: 0x9260250
                Next-hop reference count: 19
                Next hop: 10.0.0.2 via fe-1/2/0.0, selected
                State: <Active Int Ext>
                Local AS: 64510 
                Age: 2:06:08 
                Task: RT
                Announcement bits (2): 2-KRT 3-BGP_RT_Background 
                AS path: I
                Communities: 64510:3

172.16.4.0/24 (1 entry, 1 announced)
        *Static Preference: 5
                Next hop type: Router, Next hop index: 835
                Address: 0x9260250
                Next-hop reference count: 19
                Next hop: 10.0.0.2 via fe-1/2/0.0, selected
                State: <Active Int Ext>
                Local AS: 64510 
                Age: 2:06:08 
                Task: RT
                Announcement bits (2): 2-KRT 3-BGP_RT_Background 
                AS path: I
                Communities: 64510:4

意义

输出显示常规社区值附加到路由。

注:

社区附加到静态路由,从而证明社区可以附加到非 BGP 路由。

验证设备 R3 上的路由

目的

在设备 R3 上,检查 172.16。路由表中的路由。

操作

content_copy zoom_out_map
user@R3> show route protocol bgp match-prefix 172.16.* detail
betsy@tp5# run show route protocol bgp match-prefix 172.16.* detail logical-system R3       

inet.0: 7 destinations, 7 routes (7 active, 0 holddown, 0 hidden)
172.16.1.0/24 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 611
                Address: 0x9260130
                Next-hop reference count: 8
                Source: 10.0.0.14
                Next hop: 10.0.0.14 via fe-1/2/3.0, selected
                State: <Active Ext>
                Local AS: 64511 Peer AS: 64510
                Age: 1:57:27 
                Task: BGP_64510.10.0.0.14+54618
                Announcement bits (1): 0-KRT 
                AS path: 64510 I
                Communities: 64510:1 target:64511:1
                Accepted
                Localpref: 100
                Router ID: 192.168.0.1

172.16.2.0/24 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 611
                Address: 0x9260130
                Next-hop reference count: 8
                Source: 10.0.0.14
                Next hop: 10.0.0.14 via fe-1/2/3.0, selected
                State: <Active Ext>
                Local AS: 64511 Peer AS: 64510
                Age: 1:57:27 
                Task: BGP_64510.10.0.0.14+54618
                Announcement bits (1): 0-KRT 
                AS path: 64510 I
                Communities: 64510:2 target:172.16.7.7:2
                Accepted
                Localpref: 100
                Router ID: 192.168.0.1

172.16.3.0/24 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 611
                Address: 0x9260130
                Next-hop reference count: 8
                Source: 10.0.0.14
                Next hop: 10.0.0.14 via fe-1/2/3.0, selected
                State: <Active Ext>
                Local AS: 64511 Peer AS: 64510
                Age: 1:57:27 
                Task: BGP_64510.10.0.0.14+54618
                Announcement bits (1): 0-KRT 
                AS path: 64510 I
                Communities: 64510:3 origin:64511:3
                Accepted
                Localpref: 100
                Router ID: 192.168.0.1

172.16.4.0/24 (1 entry, 1 announced)
        *BGP    Preference: 170/-101
                Next hop type: Router, Next hop index: 611
                Address: 0x9260130      
                Next-hop reference count: 8
                Source: 10.0.0.14
                Next hop: 10.0.0.14 via fe-1/2/3.0, selected
                State: <Active Ext>
                Local AS: 64511 Peer AS: 64510
                Age: 1:57:27 
                Task: BGP_64510.10.0.0.14+54618
                Announcement bits (1): 0-KRT 
                AS path: 64510 I
                Communities: 64510:4 origin:172.16.7.7:4
                Accepted
                Localpref: 100
                Router ID: 192.168.0.1

意义

输出显示常规社区值仍然附加到路由,并且添加了扩展社区值。

footer-navigation