Auf dieser Seite
Beispiel: Konfigurieren einer Routing-Richtlinie, die BGP-Communitys entfernt
In diesem Beispiel wird gezeigt, wie eine Richtlinie erstellt wird, die BGP-Routen akzeptiert, aber BGP-Communities aus den Routen entfernt.
Anforderungen
Über die Geräteinitialisierung hinaus ist keine spezielle Konfiguration erforderlich, bevor Sie dieses Beispiel konfigurieren.
Überblick
Dieses Beispiel zeigt zwei Routing-Geräte mit einer externen BGP-Verbindung (EBGP). Gerät R2 verwendet die BGP-Sitzung, um zwei statische Routen an Gerät R1 zu senden. Auf Gerät R1 gibt eine Importrichtlinie an, dass alle BGP-Communities aus den Routen entfernt werden müssen.
Wenn Communities auf EBGP-Peers konfiguriert sind, werden sie standardmäßig gesendet und akzeptiert. Um die Annahme von Communitys zu unterdrücken, die Sie von einem Nachbarn erhalten haben, können Sie alle Communitys oder eine bestimmte Gruppe von Communitys entfernen. Wenn das Ergebnis einer Richtlinie eine leere Gruppe von Communitys ist, wird das Community-Attribut nicht berücksichtigt. Um alle Communities zu entfernen, definieren Sie zunächst einen Platzhaltersatz von Communities (hier heißt die Community):wild
[edit policy-options] community wild members "* : *";
Geben Sie dann in der Routingrichtlinienanweisung die Aktion an:community delete
[edit policy-options] policy-statement policy-name { term term-name { then community delete wild; } }
Um eine bestimmte Community von einem autonomen System (AS) zu unterdrücken, definieren Sie die Community als .community wild members "*:community-value"
Topologie
Abbildung 1 zeigt das Beispielnetzwerk an.
Konfiguration
CLI-Schnellkonfiguration
Um dieses Beispiel schnell zu konfigurieren, kopieren Sie die folgenden Befehle, fügen Sie sie in eine Textdatei ein, entfernen Sie alle Zeilenumbrüche, ändern Sie alle Details, die für Ihre Netzwerkkonfiguration erforderlich sind, und kopieren Sie dann die Befehle und fügen Sie sie in die CLI auf Hierarchieebene ein.[edit]
Gerät R1
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 remove-communities set policy-options policy-statement remove-communities term 1 from protocol bgp set policy-options policy-statement remove-communities term 1 then community delete wild set policy-options policy-statement remove-communities term 1 then accept set policy-options policy-statement remove-communities term 2 then reject set policy-options community wild members *:* set routing-options router-id 192.168.0.1 set routing-options autonomous-system 1
Gerät R2
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
Verfahren
Schritt-für-Schritt-Anleitung
Im folgenden Beispiel müssen Sie durch verschiedene Ebenen in der Konfigurationshierarchie navigieren. Weitere Informationen zum Navigieren in der CLI finden Sie unter Verwenden des CLI-Editors im Konfigurationsmodus im Junos OS CLI-Benutzerhandbuch.Verwenden des CLI-Editors im Konfigurationsmodushttps://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
So konfigurieren Sie Gerät R1:
Konfigurieren Sie die Schnittstellen.
[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
Konfigurieren Sie BGP.
Wenden Sie die Importrichtlinie auf die BGP-Peering-Sitzung mit Gerät R2 an.
[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 remove-communities
Konfigurieren Sie die Routingrichtlinie, mit der Communitys gelöscht werden.
[edit policy-options policy-statement remove-communities] user@R1# set term 1 from protocol bgp user@R1# set term 1 then community delete wild user@R1# set term 1 then accept user@R1# set term 2 then reject
Konfigurieren Sie die AS-Nummer (Autonomous System) und die Router-ID.
[edit routing-options ] user@R1# set router-id 192.168.0.1 user@R1# set autonomous-system 1
Schritt-für-Schritt-Anleitung
Im folgenden Beispiel müssen Sie durch verschiedene Ebenen in der Konfigurationshierarchie navigieren. Weitere Informationen zum Navigieren in der CLI finden Sie unter Verwenden des CLI-Editors im Konfigurationsmodus im Junos OS CLI-Benutzerhandbuch.Verwenden des CLI-Editors im Konfigurationsmodushttps://www.juniper.net/documentation/en_US/junos/information-products/pathway-pages/junos-cli/junos-cli.html
So konfigurieren Sie Gerät R2:
Konfigurieren Sie die Schnittstellen.
[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
Konfigurieren Sie die Router-ID und die AS-Nummer (Autonomous System).
[edit routing-options] user@R2# set router-id 192.168.0.3 user@R2# set autonomous-system 2
Konfigurieren Sie BGP.
[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
Konfigurieren Sie mehrere Communitys oder eine einzelne Community mit mehreren Mitgliedern.
[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
Konfigurieren Sie die statischen Routen.
[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
Konfigurieren Sie eine Routing-Richtlinie, die statische Routen in BGP ankündigt und die BGP-Community zu den Routen hinzufügt.
[edit policy-options policy-statement statics] user@R2# set from protocol static user@R2# set then community add 1 user@R2# set then accept
Wenden Sie die Exportrichtlinie an.
[edit protocols bgp group external-peers] user@R2# set export statics
Ergebnisse
Bestätigen Sie im Konfigurationsmodus Ihre Konfiguration, indem Sie die Befehle , , und eingeben.show interfaces
show protocols
show policy-options
show routing-options
Wenn die Ausgabe nicht die gewünschte Konfiguration anzeigt, wiederholen Sie die Anweisungen in diesem Beispiel, um die Konfiguration zu korrigieren.
Gerät R1
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; } } }
user@R1# show protocols bgp { group external-peers { type external; peer-as 2; neighbor 10.0.0.2 { import remove-communities; } } }
user@R1# show policy-options policy-statement remove-communities { term 1 { from protocol bgp; then { community delete wild; accept; } } term 2 { then reject; } } community wild members *:*;
user@R1# show routing-options router-id 192.168.0.1; autonomous-system 1;
Gerät R2
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; } } }
user@R2# show protocols bgp { group external-peers { type external; export statics; peer-as 1; neighbor 10.0.0.1; } }
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 ];
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;
Wenn Sie mit der Konfiguration der Geräte fertig sind, rufen Sie den Konfigurationsmodus auf .commit
Überprüfung
Vergewissern Sie sich, dass die Konfiguration ordnungsgemäß funktioniert.
Überprüfen der BGP-Routen
Zweck
Stellen Sie sicher, dass die Routing-Tabelle auf Gerät R1 keine BGP-Communitys enthält.
Was
Führen Sie den Befehl auf Gerät R1 aus.
show route protocols bgp extensive
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 lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:39:01 Validation State: unverified Task: BGP_2.10.0.0.2+179 Announcement bits (1): 0-KRT AS path: 2 I 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 lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:39:01 Validation State: unverified Task: BGP_2.10.0.0.2+179 Announcement bits (1): 0-KRT AS path: 2 I Accepted Localpref: 100 Router ID: 192.168.0.3
Deaktivieren Sie auf Gerät R1 die Konfiguration in der Importrichtlinie.
community remove
[edit policy-options policy-statement remove-communities term 1] user@R1# deactivate then community delete wild user@R1# commit
Führen Sie auf Gerät R1 den Befehl aus, um die angekündigten Communitys anzuzeigen.
show route protocols bgp extensive
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 lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:40:53 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 lt-1/1/0.5, selected Session Id: 0x100001 State: <Active Ext> Local AS: 1 Peer AS: 2 Age: 20:40:53 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
Bedeutung
Die Ausgabe zeigt, dass in der Routing-Tabelle von Gerät R1 die Communities in den BGP-Routen unterdrückt werden, die von Gerät R2 gesendet werden. Wenn die Einstellung in der Importrichtlinie von Gerät R1 deaktiviert ist, werden die Communities nicht mehr unterdrückt.community remove