帮助我们改善您的体验。

让我们了解您的想法。

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

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 仅提供英文版.

示例:根据 BGP 社区数量配置路由策略

date_range 18-Jan-25

此示例说明如何根据 BGP 社区的数量创建接受 BGP 路由的策略。

要求

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

概述

此示例显示了两台路由设备之间具有外部 BGP (EBGP) 连接。设备 R2 使用 BGP 会话向设备 R1 发送两个静态路由。在设备 R1 上,导入策略指定 BGP 接收的路由最多可以包含五个社区,以被视为匹配。例如,如果路径包含三个社区,则会将其视为匹配并被接受。如果路径包含六个或更多社区,则会将其视为不匹配并被拒绝。

请务必记住,EBGP 的默认策略是接受所有路由。若要确保拒绝不匹配的路由,必须在策略定义的末尾包含一个 then reject 操作。

拓扑学

图 1 显示了示例网络。

图 1: 对接受的社区数量有限制的 BGP 策略对接受的社区数量有限制的 BGP 策略

配置

CLI 快速配置

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

设备 R1

content_copy zoom_out_map
set interfaces fe-1/1/0 unit 0 description to-R2
set interfaces fe-1/1/0 unit 0 family inet address 10.0.0.1/30
set interfaces lo0 unit 0 family inet address 192.168.0.1/32
set protocols bgp group external-peers type external
set protocols bgp group external-peers peer-as 2
set protocols bgp group external-peers neighbor 10.0.0.2 import import-communities
set policy-options policy-statement import-communities term 1 from protocol bgp
set policy-options policy-statement import-communities term 1 from community-count 5 orlower
set policy-options policy-statement import-communities term 1 then accept
set policy-options policy-statement import-communities term 2 then reject
set routing-options router-id 192.168.0.1
set routing-options autonomous-system 1

设备 R2

content_copy zoom_out_map
set interfaces fe-1/1/0 unit 0 description to-R1
set interfaces fe-1/1/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 protocols bgp group external-peers type external
set protocols bgp group external-peers export statics
set protocols bgp group external-peers peer-as 1
set protocols bgp group external-peers neighbor 10.0.0.1
set policy-options policy-statement statics from protocol static
set policy-options policy-statement statics then community add 1
set policy-options policy-statement statics then accept
set policy-options community 1 members 2:1
set policy-options community 1 members 2:2
set policy-options community 1 members 2:3
set policy-options community 1 members 2:4
set policy-options community 1 members 2:5
set policy-options community 1 members 2:6
set policy-options community 1 members 2:7
set policy-options community 1 members 2:8
set policy-options community 1 members 2:9
set policy-options community 1 members 2:10
set routing-options static route 10.2.0.0/16 reject
set routing-options static route 10.2.0.0/16 install
set routing-options static route 10.3.0.0/16 reject
set routing-options static route 10.3.0.0/16 install
set routing-options router-id 192.168.0.3
set routing-options autonomous-system 2

程序

分步过程

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

要配置设备 R1:

  1. 配置接口。

    content_copy zoom_out_map
    [edit interfaces]
    user@R1# set fe-1/1/0 unit 0 description to-R2
    user@R1# set fe-1/1/0 unit 0 family inet address 10.0.0.1/30
    user@R1# set lo0 unit 0 family inet address 192.168.0.1/32
    
  2. 配置 BGP。

    将导入策略应用于与设备 R2 的 BGP 对等会话。

    content_copy zoom_out_map
    [edit protocols bgp group external-peers]
    user@R1# set type external
    user@R1# set peer-as 2
    user@R1# set neighbor 10.0.0.2 import import-communities
    
  3. 配置发送直接路由的路由策略。

    content_copy zoom_out_map
    [edit policy-options policy-statement import-communities]
    user@R1# set term 1 from protocol bgp
    user@R1# set term 1 from community-count 5 orlower
    user@R1# set term 1 then accept
    user@R1# set term 2 then reject
    
  4. 配置自治系统 (AS) 编号和路由器 ID。

    content_copy zoom_out_map
    [edit routing-options ]
    user@R1# set router-id 192.168.0.1
    user@R1# set autonomous-system 1
    

分步过程

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

要配置设备 R2:

  1. 配置接口。

    content_copy zoom_out_map
    [edit interfaces]
    user@R2# set fe-1/1/0 unit 0 description to-R1
    user@R2# set fe-1/1/0 unit 0 family inet address 10.0.0.2/30
    user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
    
  2. 配置路由器 ID 和自治系统 (AS) 编号。

    content_copy zoom_out_map
    [edit routing-options]
    user@R2# set router-id 192.168.0.3
    user@R2# set autonomous-system 2
    
  3. 配置 BGP。

    content_copy zoom_out_map
    [edit  protocols bgp group external-peers]
    user@R2# set type external
    user@R2# set peer-as 1
    user@R2# set neighbor 10.0.0.1
    
  4. 配置多个社区,或配置具有多个成员的单个社区。

    content_copy zoom_out_map
    [edit policy-options community 1]
    user@R2# set members 2:1
    user@R2# set members 2:2
    user@R2# set members 2:3
    user@R2# set members 2:4
    user@R2# set members 2:5
    user@R2# set members 2:6
    user@R2# set members 2:7
    user@R2# set members 2:8
    user@R2# set members 2:9
    user@R2# set members 2:10
    
  5. 配置静态路由。

    content_copy zoom_out_map
    [edit routing-options static]
    user@R2# set route 10.2.0.0/16 reject
    user@R2# set route 10.2.0.0/16 install
    user@R2# set route 10.3.0.0/16 reject
    user@R2# set route 10.3.0.0/16 install
    
  6. 配置路由策略,用于将静态路由播发到 BGP 中,并将 BGP 社区添加到路由。

    content_copy zoom_out_map
    [edit policy-options policy-statement statics]
    user@R2# set from protocol static
    user@R2# set then community add 1
    user@R2# set then accept
    
  7. 应用导出策略。

    content_copy zoom_out_map
    [edit protocols bgp group external-peers]
    user@R2# set export statics
    

结果

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

设备 R1

content_copy zoom_out_map
user@R1# show interfaces
fe-1/1/0 {
    unit 0{
        description to-R2;
        family inet {
            address 10.0.0.1/30;
        }
    }
}
lo0 {
    unit 0 {
        family inet {
            address 192.168.0.1/32;
        }
    }
}
}
content_copy zoom_out_map
user@R1# show protocols
bgp {
    group external-peers {
        type external;
        peer-as 2;
        neighbor 10.0.0.2 {
            import import-communities;
        }
    }
}
content_copy zoom_out_map
user@R1# show policy-options
policy-statement import-communities {
    term 1 {
        from {
            protocol bgp;
            community-count 5 orlower;
        }
        then accept;
    }
    term 2 {
        then reject;
    }
}
content_copy zoom_out_map
user@R1# show routing-options
router-id 192.168.0.1;
autonomous-system 1;

设备 R2

content_copy zoom_out_map
user@R2# show interfaces
fe-1/1/0 {
    unit 0 {
        description to-R1;
        family inet {
            address 10.0.0.2/30;
        }
    }
}
lo0 {
    unit 0 {
        family inet {
            address 192.168.0.2/32;
        }
    }
}
content_copy zoom_out_map
user@R2# show protocols
bgp {
    group external-peers {
        type external;
        export statics;
        peer-as 1;
        neighbor 10.0.0.1;
    }
}
content_copy zoom_out_map
user@R2# show policy-options
policy-statement statics {
    from protocol static;
    then {
        community add 1;
        accept;
    }
}
community 1 members [ 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10 ];
content_copy zoom_out_map
user@R2# show routing-options
static {
    route 10.2.0.0/16 {
        reject;
        install;
    }
    route 10.3.0.0/16 {
        reject;
        install;
    }
}
router-id 192.168.0.3;
autonomous-system 2;

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

验证

确认配置工作正常。

验证 BGP 路由

目的

确保设备 R1 上的路由表包含预期的 BGP 路由。

操作

  1. 在设备 R1 上,运行 show route protocols bgp 命令。

    content_copy zoom_out_map
    user@R1> show route protocols bgp
    
    inet.0: 5 destinations, 5 routes (3 active, 0 holddown, 2 hidden)
    
  2. 在设备 R1 上,更改 community-count 导入策略中的配置。

    content_copy zoom_out_map
    [edit policy-options policy-statement import-communities term 1]
    user@R1# set from community-count 5 orhigher
    user@R1# commit
    
  3. 在设备 R1 上,运行 show route protocols bgp 命令。

    content_copy zoom_out_map
    user@R1> show route protocols bgp
    
    inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden)
    + = Active Route, - = Last Active, * = Both
    
    10.2.0.0/16        *[BGP/170] 18:29:53, localpref 100
                          AS path: 2 I, validation-state: unverified
                        > to 10.0.0.2 via fe-1/1/0.0
    10.3.0.0/16        *[BGP/170] 18:29:53, localpref 100
                          AS path: 2 I, validation-state: unverified
                        > to 10.0.0.2 via fe-1/1/0.0
  4. 在设备 R1 上,运行 show route protocols bgp extensive 命令以查看播发的社区。

    content_copy zoom_out_map
    user@R1> show route protocols bgp extensive
    inet.0: 5 destinations, 5 routes (5 active, 0 holddown, 0 hidden)
    10.2.0.0/16 (1 entry, 1 announced)
    TSI:
    KRT in-kernel 10.2.0.0/16 -> {10.0.0.2}
            *BGP    Preference: 170/-101
                    Next hop type: Router, Next hop index: 671
                    Address: 0x9458270
                    Next-hop reference count: 4
                    Source: 10.0.0.2
                    Next hop: 10.0.0.2 via fe-1/1/0.0, selected
                    Session Id: 0x100001
                    State: <Active Ext>
                    Local AS:     1 Peer AS:     2
                    Age: 18:56:10 
                    Validation State: unverified 
                    Task: BGP_2.10.0.0.2+179
                    Announcement bits (1): 0-KRT 
                    AS path: 2 I
                    Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10
                    Accepted
                    Localpref: 100
                    Router ID: 192.168.0.3
    
    10.3.0.0/16 (1 entry, 1 announced)
    TSI:
    KRT in-kernel 10.3.0.0/16 -> {10.0.0.2}
            *BGP    Preference: 170/-101
                    Next hop type: Router, Next hop index: 671
                    Address: 0x9458270
                    Next-hop reference count: 4
                    Source: 10.0.0.2
                    Next hop: 10.0.0.2 via fe-1/1/0.0, selected
                    Session Id: 0x100001
                    State: <Active Ext>
                    Local AS:     1 Peer AS:     2
                    Age: 18:56:10 
                    Validation State: unverified 
                    Task: BGP_2.10.0.0.2+179
                    Announcement bits (1): 0-KRT 
                    AS path: 2 I
                    Communities: 2:1 2:2 2:3 2:4 2:5 2:6 2:7 2:8 2:9 2:10
                    Accepted
                    Localpref: 100
                    Router ID: 192.168.0.3
    
    

意义

输出显示,在设备 R1 的路由表中,从设备 R2 发送的 BGP 路由是隐藏的。community-count修改设备 R1 导入策略中的设置后,BGP 路由将不再隐藏。

footer-navigation