BGP – wyrażenia regularne
Wyrażenia regularne bardzo często przydają się w manipulacji trasami BGP, oraz przeszukiwaniu tablicy BGP po atrybucie AS-Path. Do sprawadzenia w praktyce wykorzystania wyrażeń regularnych skorzystamy z jednego z dostępnych serwerów Looking Glass. Ja wybrałem serwer Looking Glass: https://www.as13030.net/looking-glass.php
Po wejściu na powyższy serwer możemy wybrać Router (domyślnie Router: RR Zurich (AS13030)), typ zapytania Request: show ip bgp regexp, oraz ustawić argumenty, w naszym przypadku będą to wyrażenia regularne.
1. Wyświetlenie wszystkich podsieci pochodzących tylko z AS4788
show ip bgp regexp ^4788$
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i1.32.0.0/19 213.144.128.173 2 150 0 4788 i
*>i1.32.32.0/19 213.144.128.173 2 150 0 4788 i
*>i23.6.120.0/24 213.144.128.173 2 150 0 4788 i
*>i23.212.55.0/24 213.144.128.173 2 150 0 4788 i
*>i103.4.140.0/22 213.144.128.221 2 150 0 4788 i
*>i137.195.224.0/20 213.144.128.173 2 150 0 4788 i
*>i210.195.0.0/19 213.144.128.173 2 150 0 4788 ?
*>i210.195.32.0/19 213.144.128.173 2 150 0 4788 ?
*>i210.195.64.0/19 213.144.128.173 2 150 0 4788 ?
*>i210.195.96.0/19 213.144.128.173 2 150 0 4788 ?
*>i210.195.128.0/19 213.144.128.173 2 150 0 4788 ?
*>i210.195.160.0/19 213.144.128.173 2 150 0 4788 ?
*>i210.195.192.0/19 213.144.128.173 2 150 0 4788 ?
*>i210.195.224.0/19 213.144.128.173 2 150 0 4788 ?
*>i218.208.160.0/19 213.144.128.173 2 150 0 4788 i
*>i219.93.2.0 213.144.128.173 2 150 0 4788 i
*>i219.95.64.0/20 213.144.128.173 2 150 0 4788 i
*>i219.95.104.0/21 213.144.128.173 2 150 0 4788 i
*>i219.95.136.0/21 213.144.128.173 2 150 0 4788 i
Total number of prefixes 19
2. Wyświetlenie wszystkich podsieci pochodzących z AS4788, ale mogących przechodzić przez inne ASy
show ip bgp regexp _4788$
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i1.9.0.0/16 213.144.128.169 1 160 0 1273 4788 i
*>i1.32.0.0/17 213.144.128.169 1 160 0 1273 4788 i
*>i1.32.0.0/19 213.144.128.173 2 150 0 4788 i
*>i1.32.32.0/19 213.144.128.173 2 150 0 4788 i
*>i1.32.64.0/18 213.144.128.169 1 160 0 1273 4788 i
*>i23.6.120.0/24 213.144.128.173 2 150 0 4788 i
*>i23.13.192.0/20 213.144.128.169 1 160 0 1273 4788 i
*>i23.15.16.0/20 213.144.128.169 1 160 0 1273 4788 i
*>i23.51.32.0/20 213.144.128.169 1 160 0 1273 4788 i
*>i23.51.48.0/20 213.144.128.169 1 160 0 1273 4788 i
*>i23.197.60.0/23 213.144.128.169 1 160 0 1273 4788 i
*>i23.200.82.0/23 213.144.128.169 1 160 0 1273 4788 i
*>i23.201.156.0/22 213.144.128.169 1 160 0 1273 4788 i
...
Total number of prefixes 402
3. Wyświetlenie wszystkich podsieci przechodzących przez AS46887
show ip bgp regexp _46887_
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i5.11.28.0/24 213.144.128.216 1 150 0 6939 46887 36614 42705 i
*>i5.61.116.0/23 213.144.128.216 1 150 0 6939 46887 199373 199373 199373 199373 199373 199373 199373 199373 199373 199373 i
*>i8.2.68.0/24 213.144.128.216 1 150 0 6939 46887 396835 i
*>i8.2.104.0/24 213.144.128.216 1 150 0 6939 46887 396487 396487 396487 396487 396487 i
*>i8.11.166.0/24 213.144.128.216 1 150 0 6939 46887 i
*>i8.14.103.0/24 213.144.128.216 1 150 0 6939 46887 13817 i
*>i8.14.121.0/24 213.144.128.216 1 150 0 6939 46887 12169 i
*>i8.22.101.0/24 213.144.128.216 1 150 0 6939 46887 12220 i
*>i8.28.55.0/24 213.144.128.216 1 150 0 6939 46887 394830 i
*>i8.33.72.0/24 213.144.128.216 1 150 0 6939 46887 17158 17158 17158 17158 i
*>i8.37.99.0/24 213.144.128.216 1 150 0 6939 46887 16491 i
*>i8.44.200.0/24 213.144.128.216 1 150 0 6939 46887 25611 25611 25611 25611 25611 25611 i
...
Total number of prefixes 1537
4. Wyświetlenie wszystkich podsieci, które są lokalnymi podsieciami routera
show ip bgp regexp ^$
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i14.0.0.0 213.144.128.214 1 10 0 i
*>i27.0.0.0 213.144.128.214 1 10 0 i
*>i37.17.232.0/22 213.144.128.208 1 100 0 i
*>i37.17.236.0/23 213.144.128.208 1 100 0 i
*>i37.17.238.0/23 213.144.128.208 1 100 0 i
*>i46.28.203.155/32 213.144.128.177 1 100 0 i
*>i46.28.204.142/32 213.144.128.177 1 100 0 i
*>i77.109.128.0/18 213.144.128.208 1 100 0 i
*>i77.109.128.0/19 213.144.128.208 1 100 0 i
*>i77.109.128.2/32 77.109.129.61 3 100 0 i
...
Total number of prefixes 127
5. wyświetlenie wszystkich podsieci tylko z bezpośrednio połączonych ASów
show ip bgp ^[0-9]+$
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i1.0.0.0/24 213.144.128.173 1 150 0 13335 i
*>i1.1.1.0/24 213.144.128.173 1 150 0 13335 i
*>i1.6.4.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.6.0/24 213.144.128.179 2 150 0 9583 i
*>i1.6.8.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.12.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.16.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.20.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.24.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.28.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.32.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.36.0/22 213.144.128.179 2 150 0 9583 i
*>i1.6.40.0/22 213.144.128.179 2 150 0 9583 i
...
Total number of prefixes 41787
6. Wyświetlenie wszystkich podsieci osiągalnych przez AS6939
show ip bgp regexp ^6939_
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i1.0.4.0/22 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.4.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.5.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.6.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.7.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.255.30.0/24 213.144.128.216 1 150 0 6939 63199 i
*>i2.16.36.0/24 213.144.128.216 1 150 0 6939 7545 7545 7545 7545 2764 12222 12222 i
*>i2.17.218.0/24 213.144.128.216 1 150 0 6939 7545 7545 7545 7545 2764 32787 i
*>i2.18.52.0/24 213.144.128.216 1 150 0 6939 4826 20940 33905 i
...
Total number of prefixes 36028
7. Wyświetlenie wszystkich podsieci
show ip bgp regexp .*
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i1.0.0.0/24 213.144.128.173 1 150 0 13335 i
*>i1.0.4.0/22 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.4.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.5.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.6.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.7.0/24 213.144.128.216 1 150 0 6939 4826 38803 56203 i
*>i1.0.16.0/24 213.144.128.221 2 150 0 2497 2519 i
*>i1.0.64.0/18 213.144.128.221 2 150 0 2497 7670 18144 i
*>i1.0.128.0/17 213.144.128.203 1 60 0 1299 38040 23969 i
*>i1.0.128.0/18 213.144.128.203 1 60 0 1299 38040 23969 i
*>i1.0.128.0/19 213.144.128.203 1 60 0 1299 38040 23969 i
*>i1.0.128.0/24 213.144.128.203 1 60 0 1299 4809 38040 23969 ?
...
Total number of prefixes 695338
8. Wyświetlenie wszystkich podsieci które pochodzą z AS56201 i przechodzą przez AS18101
show ip bgp regexp 18101_56201$
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i220.225.183.0 213.144.128.173 2 150 0 15412 18101 56201 i
Total number of prefixes 1
9. Wyświetlenie wszystkich podsieci które pochodzą z AS46164 lub z AS46163
show ip bgp regexp _46164$|_46163$
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i4.23.88.0/24 213.144.128.184 1 60 0 1299 7018 46164 i
*>i4.23.89.0/24 213.144.128.184 1 60 0 1299 7018 46164 i
*>i4.23.92.0/23 213.144.128.184 1 60 0 1299 7018 46164 i
*>i107.117.80.0/20 213.144.128.184 1 60 0 1299 7018 46164 i
*>i107.239.64.0/20 213.144.128.184 1 60 0 1299 7018 46164 i
*>i107.250.192.0/19 213.144.128.184 1 60 0 1299 7018 46164 i
*>i107.250.224.0/19 213.144.128.184 1 60 0 1299 7018 46164 i
*>i141.160.4.0/22 213.144.128.203 1 60 0 1299 174 46163 i
*>i141.160.12.0/22 213.144.128.173 2 150 0 6461 1294 46163 i
*>i141.160.20.0/22 213.144.128.173 2 150 0 6461 1294 4616346163 46163 46163 46163 i
*>i141.160.25.0/24 213.144.128.203 1 60 0 1299 174 46163 i
*>i141.160.26.0/24 213.144.128.184 1 60 0 1299 7018 2687 46163 i
*>i141.160.27.0/24 213.144.128.203 1 60 0 1299 174 46163 i
*>i141.160.28.0/24 213.144.128.214 2 150 0 7473 3758 46163 i
*>i141.160.29.0/24 213.144.128.203 1 60 0 1299 174 46163 I
...
Total number of prefixes 47
10. Wyświetlenie wszystkich podsieci, których atrybut AS_Path posiada więcej niż raz AS396835, czyli gdzie została zastosowana technika AS Prepending
show ip bgp regexp (396835_){2,}
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i140.102.0.0 213.144.128.216 1 150 0 6939 46887 396835 396835 396835 396835 i
*>i140.102.2.0/23 213.144.128.216 1 150 0 6939 46887 396835 396835 396835 396835 i
*>i192.80.85.0 213.144.128.216 1 150 0 6939 46887 396835 396835 396835 396835 i
*>i192.80.95.0 213.144.128.216 1 150 0 6939 46887 396835 396835 396835 396835 i
*>i192.138.225.0 213.144.128.216 1 150 0 6939 46887 396835 396835 396835 396835 i
Total number of prefixes 5
11. Wyświetlenie wszystkich podsieci, które pochodzą z ASów trzy cyfrowych zaczynających się od 1,2 lub 3.
np. 312 , 123, 223 itp
show ip bgp regexp _[123].{2}$
BGP table version is 0, local router ID is 213.144.129.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale, R Removed
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*>i5.157.72.0/21 213.144.128.203 1 60 0 1299 174 i
*>i5.158.83.0/24 213.144.128.203 1 60 0 1299 174 i
*>i5.178.16.0/21 213.144.128.203 1 60 0 1299 3257 260 i
*>i6.64.164.0/23 213.144.128.184 1 60 0 1299 209 721 27064 367 i
*>i8.25.217.0/24 213.144.128.173 2 150 0 6461 54756 100 i
*>i8.27.160.0/24 213.144.128.184 1 60 0 1299 209 i
*>i8.27.167.0/24 213.144.128.184 1 60 0 1299 209 i
*>i8.28.178.0/23 213.144.128.216 1 150 0 6939 2381 2381 103 i
*>i8.30.248.0/22 213.144.128.216 1 150 0 6939 2381 2381 103 i
...
Total number of prefixes 6168