Auf dieser Seite
Beispiel: Verwenden von regulären AS-Pfadausdrücken
Ein AS-Pfad (Autonomous System) ist ein Routenattribut, das von BGP verwendet wird. Der AS-Pfad dient sowohl zur Routenauswahl als auch zur Vermeidung möglicher Routing-Schleifen. In diesem Beispiel wird gezeigt, wie reguläre Ausdrücke mit AS-Pfadnummern verwendet werden, um einen Satz von Routen zu suchen.
Anforderungen
Vor der Konfiguration dieses Beispiels ist keine spezielle Konfiguration erforderlich, die über die Geräteinitialisierung hinausgeht.
Überblick
Abbildung 1 zeigt mehrere ASs, die über externe BGP (EBGP)-Peering-Sitzungen verbunden sind. Jedes Gerät generiert Kundenrouten innerhalb des ihm zugewiesenen Adressraums.
Topologie
Abbildung 1 zeigt das Beispielnetzwerk an.
Die Administratoren von AS 64516 wollen alle Routen mit Ursprung in AS 64513 und AS 64514 ablehnen. Zwei reguläre AS-Pfadausdrücke mit dem Namen und werden in einer Richtlinie namens .orig-in-64513
orig-in-64514
reject-some-routes
Die Routing-Richtlinie wird dann als Importrichtlinie auf Gerät R6 angewendet.
CLI-Schnellkonfiguration Zeigt die Konfiguration für alle Geräte in Abbildung 1an.
In diesem Abschnitt werden die Schritte auf Gerät R2 und Gerät R6 beschrieben. Es wird gezeigt, wie die Option mit dem Befehl auf Gerät R2 verwendet wird, um Routen mithilfe regulärer Ausdrücke zu suchen. #configuration488__policy-as-path-regex-stÜberprüfungaspath-regex
show route
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/2/2 unit 0 description to-R2 set interfaces fe-1/2/2 unit 0 family inet address 10.2.0.2/30 set interfaces fe-1/2/3 unit 0 description to-R3 set interfaces fe-1/2/3 unit 0 family inet address 10.2.0.6/30 set interfaces fe-1/2/0 unit 0 description to-R5 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.1/32 set protocols bgp export send-static set protocols bgp group 64512 type external set protocols bgp group 64512 peer-as 64512 set protocols bgp group 64512 neighbor 10.2.0.1 set protocols bgp group 64513 type external set protocols bgp group 64513 peer-as 64513 set protocols bgp group 64513 neighbor 10.2.0.5 set protocols bgp group 64515 type external set protocols bgp group 64515 peer-as 64515 set protocols bgp group 64515 neighbor 10.0.0.1 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 10.10.1.0/24 reject set routing-options static route 10.10.2.0/24 reject set routing-options static route 10.10.3.0/24 reject set routing-options autonomous-system 64511
Gerät R2
set interfaces fe-1/2/2 unit 0 description to-R1 set interfaces fe-1/2/2 unit 0 family inet address 10.2.0.1/30 set interfaces lo0 unit 0 family inet address 192.168.0.2/32 set protocols bgp export send-static set protocols bgp group 64511 type external set protocols bgp group 64511 peer-as 64511 set protocols bgp group 64511 neighbor 10.2.0.2 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 10.20.1.0/24 reject set routing-options static route 10.20.2.0/24 reject set routing-options static route 10.20.3.0/24 reject set routing-options autonomous-system 64512
Gerät R3
set interfaces fe-1/2/3 unit 0 description to-R1 set interfaces fe-1/2/3 unit 0 family inet address 10.2.0.5/30 set interfaces fe-1/2/2 unit 0 description to-R4 set interfaces fe-1/2/2 unit 0 family inet address 10.3.0.42/30 set interfaces lo0 unit 0 family inet address 192.168.0.3/32 set protocols bgp export send-static set protocols bgp group 64511 type external set protocols bgp group 64511 peer-as 64511 set protocols bgp group 64511 neighbor 10.2.0.6 set protocols bgp group 64514 type external set protocols bgp group 64514 peer-as 64514 set protocols bgp group 64514 neighbor 10.3.0.41 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 10.30.1.0/24 reject set routing-options static route 10.30.2.0/24 reject set routing-options static route 10.30.3.0/24 reject set routing-options autonomous-system 64513
Gerät R4
set interfaces fe-1/2/2 unit 0 description to-R3 set interfaces fe-1/2/2 unit 0 family inet address 10.3.0.41/30 set interfaces lo0 unit 0 family inet address 192.168.0.4/32 set protocols bgp export send-static set protocols bgp group 64513 type external set protocols bgp group 64513 peer-as 64513 set protocols bgp group 64513 neighbor 10.3.0.42 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 10.40.1.0/24 reject set routing-options static route 10.40.2.0/24 reject set routing-options static route 10.40.3.0/24 reject set routing-options autonomous-system 64514
Gerät R5
set interfaces fe-1/2/0 unit 0 description to-R1 set interfaces fe-1/2/0 unit 0 family inet address 10.0.0.1/30 set interfaces fe-1/2/1 unit 0 description to-R6 set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.9/30 set interfaces lo0 unit 0 family inet address 192.168.0.5/32 set protocols bgp export send-static set protocols bgp group 64511 type external set protocols bgp group 64511 peer-as 64511 set protocols bgp group 64511 neighbor 10.0.0.2 set protocols bgp group 64516 type external set protocols bgp group 64516 peer-as 64516 set protocols bgp group 64516 neighbor 10.0.0.10 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 10.50.1.0/24 reject set routing-options static route 10.50.2.0/24 reject set routing-options static route 10.50.3.0/24 reject set routing-options autonomous-system 64515
Gerät R6
set interfaces fe-1/2/1 unit 0 description to-R5 set interfaces fe-1/2/1 unit 0 family inet address 10.0.0.10/30 set interfaces lo0 unit 0 family inet address 192.168.0.6/32 set protocols bgp export send-static set protocols bgp group 64515 type external set protocols bgp group 64515 import reject-some-routes set protocols bgp group 64515 peer-as 64515 set protocols bgp group 64515 neighbor 10.0.0.9 set policy-options policy-statement send-static term 1 from protocol static set policy-options policy-statement send-static term 1 then accept set policy-options policy-statement reject-some-routes term find-routes from as-path orig-in-64513 set policy-options policy-statement reject-some-routes term find-routes from as-path orig-in-64514 set policy-options policy-statement reject-some-routes term find-routes then reject set policy-options as-path orig-in-64513 ".* 64513" set policy-options as-path orig-in-64514 ".* 64514" set routing-options static route 10.60.1.0/24 reject set routing-options static route 10.60.2.0/24 reject set routing-options static route 10.60.3.0/24 reject set routing-options autonomous-system 64516
Verfahren
Schritt-für-Schritt-Anleitung
Im folgenden Beispiel müssen Sie durch verschiedene Ebenen in der Konfigurationshierarchie navigieren. Informationen zum Navigieren in der CLI finden Sie 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 Geräteschnittstellen.
[edit interfaces] user@R2# set fe-1/2/2 unit 0 description to-R1 user@R2# set fe-1/2/2 unit 0 family inet address 10.2.0.1/30 user@R2# set lo0 unit 0 family inet address 192.168.0.2/32
Konfigurieren Sie die EBGP-Verbindung mit Gerät R1.
[edit protocols bgp] user@R2# set export send-static user@R2# set group 64511 type external user@R2# set group 64511 peer-as 64511 user@R2# set group 64511 neighbor 10.2.0.2
Konfigurieren Sie die Routing-Richtlinie.
[edit policy-options policy-statement send-static term 1] user@R2# set from protocol static user@R2# set then accept
Konfigurieren Sie die statischen Routen.
[edit routing-options static] user@R2# set route 10.20.1.0/24 reject user@R2# set route 10.20.2.0/24 reject user@R2# set route 10.20.3.0/24 reject
Konfigurieren Sie die AS-Nummer.
[edit routing-options] user@R2# set autonomous-system 64512
Schritt-für-Schritt-Anleitung
Im folgenden Beispiel müssen Sie durch verschiedene Ebenen in der Konfigurationshierarchie navigieren. Informationen zum Navigieren in der CLI finden Sie 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 R6:
Konfigurieren Sie die Geräteschnittstellen.
[edit interfaces] user@R6# set fe-1/2/1 unit 0 description to-R5 user@R6# set fe-1/2/1 unit 0 family inet address 10.0.0.10/30 user@R6# set lo0 unit 0 family inet address 192.168.0.6/32
Konfigurieren Sie die EBGP-Verbindung mit Gerät R5.
[edit protocols bgp] user@R6# set export send-static user@R6# set group 64515 type external user@R6# set group 64515 import reject-some-routes user@R6# set group 64515 peer-as 64515 user@R6# set group 64515 neighbor 10.0.0.9
Konfigurieren Sie die Routingrichtlinie, die statische Routen sendet.
[edit policy-options policy-statement send-static term 1] user@R6# set from protocol static user@R6# set then accept
Konfigurieren Sie die Routingrichtlinie, die bestimmte Routen ablehnt.
[edit policy-options policy-statement reject-some-routes term find-routes] user@R6# set from as-path orig-in-64513 user@R6# set from as-path orig-in-64514 user@R6# set then reject [edit policy-options] user@R6# set as-path orig-in-64513 ".* 64513" user@R6# set as-path orig-in-64514 ".* 64514"
Konfigurieren Sie die statischen Routen.
[edit routing-options static] user@R6# set route 10.60.1.0/24 reject user@R6# set route 10.60.2.0/24 reject user@R6# set route 10.60.3.0/24 reject
Konfigurieren Sie die AS-Nummer.
[edit routing-options] user@R6# set autonomous-system 64516
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 R2
user@R2# show interfaces fe-1/2/0 { unit 0 { description to-R1; family inet { address 10.2.0.1/30; } } } lo0 { unit 0 { family inet { address 192.168.0.2/32; } } }
user@R2# show protocols bgp { export send-static; group 64511 { type external; peer-as 64511; neighbor 10.2.0.2; } }
user@R2# show policy-options policy-statement send-static { term 1 { from protocol static; then accept; } }
user@R2# show routing-options static { route 10.20.1.0/24 reject; route 10.20.2.0/24 reject; route 10.20.3.0/24 reject; } autonomous-system 64512;
Gerät R6
user@R6# show interfaces fe-1/2/0 { unit 0 { description to-R5; family inet { address 10.0.0.10/30; } } } lo0 { unit 0 { family inet { address 192.168.0.6/32; } } }
user@R6# show protocols bgp { export send-static; group 64515 { type external; import reject-some-routes; peer-as 64515; neighbor 10.0.0.9; } }
user@R6# show policy-options policy-statement reject-some-routes { term find-routes { from as-path [ orig-in-64513 orig-in-64514 ]; then reject; } } policy-statement send-static { term 1 { from protocol static; then accept; } } as-path orig-in-64513 ".* 64513"; as-path orig-in-64514 ".* 64514";
user@R6# show routing-options static { route 10.60.1.0/24 reject; route 10.60.2.0/24 reject; route 10.60.3.0/24 reject; } autonomous-system 64516;
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.
Routen auf Gerät R2 finden
Zweck
Verwenden Sie auf Gerät R2 den Befehl, um Routen mithilfe regulärer Ausdrücke zu suchen.show route aspath-regex
Was
Suchen Sie nach Routen, die von Gerät R6 in AS 64516 stammen.
user@R2> show route terse aspath-regex ".* 64516" inet.0: 21 destinations, 21 routes (21 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both A V Destination P Prf Metric 1 Metric 2 Next hop AS path * ? 10.60.1.0/24 B 170 100 64511 64515 64516 I unverified >10.2.0.2 * ? 10.60.2.0/24 B 170 100 64511 64515 64516 I unverified >10.2.0.2 * ? 10.60.3.0/24 B 170 100 64511 64515 64516 I unverified >10.2.0.2
Suchen Sie nach Routen, die entweder in AS 64514 oder AS 64516 beginnen.
user@R2> show route terse aspath-regex ".* (64514|64516)" inet.0: 21 destinations, 21 routes (21 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both A V Destination P Prf Metric 1 Metric 2 Next hop AS path * ? 10.40.1.0/24 B 170 100 64511 64513 64514 I unverified >10.2.0.2 * ? 10.40.2.0/24 B 170 100 64511 64513 64514 I unverified >10.2.0.2 * ? 10.40.3.0/24 B 170 100 64511 64513 64514 I unverified >10.2.0.2 * ? 10.60.1.0/24 B 170 100 64511 64515 64516 I unverified >10.2.0.2 * ? 10.60.2.0/24 B 170 100 64511 64515 64516 I unverified >10.2.0.2 * ? 10.60.3.0/24 B 170 100 64511 64515 64516 I unverified >10.2.0.2
Suchen Sie nach Routen, die AS 64513 als ÖPNV-Netzwerk verwenden.
user@R2> show route terse aspath-regex ".* 64513 .+" inet.0: 21 destinations, 21 routes (21 active, 0 holddown, 0 hidden) + = Active Route, - = Last Active, * = Both A V Destination P Prf Metric 1 Metric 2 Next hop AS path * ? 10.40.1.0/24 B 170 100 64511 64513 64514 I unverified >10.2.0.2 * ? 10.40.2.0/24 B 170 100 64511 64513 64514 I unverified >10.2.0.2 * ? 10.40.3.0/24 B 170 100 64511 64513 64514 I unverified
Bedeutung
Die Ausgabe zeigt die Routing-Tabelleneinträge an, die mit den angegebenen regulären AS-Pfadausdrücken übereinstimmen.
Sicherstellen, dass Routen auf Gerät R6 ausgeschlossen sind
Zweck
Verwenden Sie auf Gerät R6 die Befehle, um sicherzustellen, dass Routen, die von AS 64513 und AS 64514 ausgehen, aus der Routing-Tabelle von Gerät R6 ausgeschlossen werden.show route and show route hidden
Was
user@R6> show route 10.30.0/22 inet.0: 21 destinations, 21 routes (15 active, 0 holddown, 6 hidden)
user@R6> show route 10.40.0/22 inet.0: 21 destinations, 21 routes (15 active, 0 holddown, 6 hidden)
user@R6> show route hidden inet.0: 21 destinations, 21 routes (15 active, 0 holddown, 6 hidden) + = Active Route, - = Last Active, * = Both 10.30.1.0/24 [BGP ] 02:24:47, localpref 100 AS path: 64515 64511 64513 I, validation-state: unverified > to 10.0.0.9 via fe-1/2/1.0 10.30.2.0/24 [BGP ] 02:24:47, localpref 100 AS path: 64515 64511 64513 I, validation-state: unverified > to 10.0.0.9 via fe-1/2/1.0 10.30.3.0/24 [BGP ] 02:24:47, localpref 100 AS path: 64515 64511 64513 I, validation-state: unverified > to 10.0.0.9 via fe-1/2/1.0 10.40.1.0/24 [BGP ] 02:24:47, localpref 100 AS path: 64515 64511 64513 64514 I, validation-state: unverified > to 10.0.0.9 via fe-1/2/1.0 10.40.2.0/24 [BGP ] 02:24:47, localpref 100 AS path: 64515 64511 64513 64514 I, validation-state: unverified > to 10.0.0.9 via fe-1/2/1.0 10.40.3.0/24 [BGP ] 02:24:47, localpref 100 AS path: 64515 64511 64513 64514 I, validation-state: unverified > to 10.0.0.9 via fe-1/2/1.0
Bedeutung
Die Ausgabe zeigt, dass die Routen 10.30.0/22 und 10.40.0/22 auf Gerät R6 abgelehnt werden.