Sie sind auf Seite 1von 6

5/15/2019 BGP Regular Expressions Examples | NetworkLessons.

com

Search...

Table of Contents
BGP

 Unit 1: Introduction to BGP

 Unit 2: BGP Neighbor Adjacency

 Unit 3: BGP Attributes

 Unit 4: BGP Communities

 Unit 5: BGP Filtering

BGP Regular Expressions

BGP Transit AS

BGP IPv6 route ltering

BGP AS Path Filter

BGP Extended Access-List Filtering

 Unit 6: Advanced BGP Features

 Unit 7: BGP Convergence

You are here: Home » BGP

BGP Regular Expressions Examples


Regular Expressions are used often for BGP route manipulation or ltering. In this lesson we’ll
take a look at some useful regular expressions. First let’s take a look at the di erent characters
that we can use:

Characters

https://networklessons.com/bgp/bgp-regular-expressions-examples 1/6
5/15/2019 BGP Regular Expressions Examples | NetworkLessons.com

? repeats the previous character one or zero times.

* repeats the previous character zero or many times.

+ repeats the previous character one or more times.

^ matches the beginning of a string.

$ matches the end of a string.

[] is a range.

_ matches the space between AS numbers or the end of the AS PATH list.

\\ is an escape character. You’ll need this for BGP confederations.

Examples

^$ matches an empty AS PATH so it will match all pre xes from the local AS.

^51_ matches pre xes from AS 51 that is directly connected to our AS.

 _51_ matches pre xes that transit AS 51.

matches pre xes that originated in AS 51, the $ ensures that it’s the
 _51$
beginning of the AS PATH.

 ^([0- matches pre xes from AS 51 where AS 51 is behind one of our directly
9]+)_51 connected AS’es.

 ^51_([0-
matches pre xes from the clients of directly connected AS 51.
9]+)

 ^(51_)+ matches pre xes from the clients of directly connected AS 51, where AS
([0-9]+) 51 might be doing AS PATH prepending.

 ^51_([0- matches pre xes from the clients of directly connected AS 51, where the
9]+_)+ clients might be doing AS PATH prepending.

^\65200\) matches pre xed from confederation peer 65200.


https://networklessons.com/bgp/bgp-regular-expressions-examples 2/6
5/15/2019 BGP Regular Expressions Examples | NetworkLessons.com

If you need some practice for these, I would suggest to use a BGP looking glass server.

Got some more useful BGP regular expressions? Please let me know!

« Previous Lesson
BGP Community Local AS
Next Lesson
BGP Transit AS »
 Tags: Filtering

Forum Replies

seafarmer11

Hey Rene,

I have found one of Swisscom BGP router from that expressions:

AS path access list 1


permit ^$
permit 650[0-9][0-9][)]$

permit ^$ : I think this one is written for locally originating routes

I can’t get a meaning the last one’s " [)] "section ? You have an idea?
By the way ; these ip as-path access lists , bgp ltering commands just ltering the AS’s that advertising
from another BGP routers right?

Deniz

ReneMolenaar

Hi Deniz,

https://networklessons.com/bgp/bgp-regular-expressions-examples 3/6
5/15/2019 BGP Regular Expressions Examples | NetworkLessons.com

The rst entry will match on pre xes that originated in this AS. The second one will match on everything
that ends with 650XX). Anything in the 64512 – 65535 range are private AS numbers. The [)] is a bit
strange, normally you use the [] for a range (like 0-9). I’m guessing that they use it to match on sub-AS
numbers in a confederation? That’s the only time you will see a ) in the AS path:

https://networklessons.com/bgp/bgp-confederation-explained/

Rene

ReneMolenaar

Hi A,

Most of the looking glass servers support regular expressions so that would be the best option to get
some practice. If you want to practice this “locally” then I would con gure some BGP routers and use
route-maps for things like AS path prepending, this can be used as a nice simulation of the Internet.

Rene

wilder7bc

Is it abnormal not really to be real uent with these?

Don’t get me wrong I see the examples and as I went through lessons later on I see some of the examples
come up that can be useful.

I am good with ones like:

^$ which can be useful for applying to everything (you use this one when dealing with Transit issues when
multi-homing and need to lter) or ^63100$ apply to an AS speci cally.

I also get and like the ones like

//cdn-
forum.networklessons.com/uploads/default/original/1X/ba8410b24c63f01693bd194e49f4b85b377d378c.PNG

which would give every AS that

... Continue reading in our forum

ReneMolenaar

https://networklessons.com/bgp/bgp-regular-expressions-examples 4/6
5/15/2019 BGP Regular Expressions Examples | NetworkLessons.com

Hi Brian,

It’s normal I think…as network engineers, we don’t use regular expressions much. If you are into
programming, you’ll use them quite a lot to match strings/numbers/etc… If you want to practice these, try
a site like:

https://regexr.com/

Paste in the output of a BGP table there and test it…it’s easier and quicker than testing regex on your
router.

I wouldn’t worry about this too much though…when you need to use them for BGP, you can always look
them up…test it, then apply it to your router. No need to memorize all the di erent options. When you
need it

... Continue reading in our forum

 1 more reply! Ask a question or join the discussion by visiting our Community Forum

Hello There!
I am René Molenaar (CCIE #41726), Your main Instructor. My goal is to teach
you everything about Cisco, Wireless and Security. I am here to Help You
Master Networking!

Read my story

New Lessons
Device Programmability
Data Models and Structures
Network Automation and Orchestration
Cloud Connectivity
Virtualization Functions (NFVI, VNF)

https://networklessons.com/bgp/bgp-regular-expressions-examples 5/6
5/15/2019 BGP Regular Expressions Examples | NetworkLessons.com

Disclaimer
Privacy Policy
Support

© 2013 - 2019 NetworkLessons.com 22344

https://networklessons.com/bgp/bgp-regular-expressions-examples 6/6

Das könnte Ihnen auch gefallen