Introduction To BGP
Introduction To BGP
Autonomous Systems
An AS is a collection of networks under a single administrative domain.
How do we get an autonomous system number? Just like public IP address space you’ll
need to register one.
Autonomous system numbers are 16-bit which means we have 65535 numbers to choose
from. Just like private and public IP addresses, we have a range of public and private AS
numbers.
Range 1 – 64511 are globally unique AS numbers and range 64512 – 65535 are private
autonomous system numbers.
You now have an idea of why we require BGP and what autonomous systems are. The
Internet is a big place, as I am writing this there are more than 500.000 prefixes in a
complete Internet routing table. If you are curious, you can find the size of the Internet
routing table here:
Above in our picture our customer network has an autonomous system number (AS 1) and
some IP address space (10.0.0.0 /8), let’s pretend that these are public IP addresses. We
are connected to two different ISPs and you can see their AS number (AS2 and AS3) and
IP address space (20.0.0.0/8 and 30.0.0.0/8). We can reach the rest of the internet through
both ISPs.
We can use BGP to advertise our address space to the ISPs but what are the ISPS going to
advertise to our customer through BGP? There are a number of options:
Receiving a default route requires the fewest resources on your routers since you only
have a single entry to reach any external network. The customer router will advertise its
10.0.0.0 /8 network to both ISPs which will advertise it to any other AS they are connected
to and we will use a default route to reach anything on the Internet. The downside of this
configuration is that our customer network doesn’t know what is behind ISP1 and ISP2. We
have connectivity because of the default routes but this can lead to sub-optimal routing. If
we only have the default routes then we will send all traffic to one of the ISPs.
Partial Routing Updates
We can also receive a partial routing table plus a default route. This partial update might
include all the IP address space that the ISPs have assigned to their customers.
Just like in real life…the more you know the better off you are (unless you believe ignorance
is bliss). In the world of routing having more routing information means you can make better
routing decisions. We’ll have less sub-optimal routing problems than when we only have the
default route.
Path Vector
BGP is called a path vector routing protocol. What does this mean?
We have 4 autonomous systems and we are running BGP to exchange routing information.
In AS 1 we have network 1.1.1.0 /24 and this is advertised to AS 2, AS 3 and AS 4.
If we would look at the BGP table of the router in AS4 then we will see network 1.1.1.0 /24
but it also stores the path we have to get through in order to get there. It will store the prefix
but also the paths it has to cross in order to get to 1.1.1.0 /24. Here’s an example of a real
BGP router:
A path vector protocol is a network routing protocol which maintains the path information that gets
updated dynamically.
BGP Route Selection
What all IGPs have in common is that all of them want to find the shortest path to the
destination. BGP works differently, since autonomous systems belong to different ISPs or
organizations we want to be able to selectively influence our routing. Take a look at this
example:
BGP allows us to use routing policies at the autonomous system level. In the picture above I
have 9 autonomous systems and in AS 9 we have network 192.168.9.0 /24. If we look at AS
1 then we have a lot of different paths we can take to reach network 192.168.9.0 /24 in AS
9.
Does this mean the network administrator at AS 1 can choose the path we are going to
use? Not really because of the following reasons:
You can choose the exit path…AS1 can send traffic to AS 2 or AS4 but you don’t make
routing decisions for other autonomous systems.
Each autonomous system will only advertise the best path to your autonomous system.
AS 1 will only learn about the best path from AS 2 and AS 4 unless their best path
fails…only then you will learn about the second best path.
Let’s start with a simple topology. Just two routers and two autonomous systems. Each
router has a network on a loopback interface which we are going to advertise in BGP.
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R2(config)#router bgp 2
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R1(config)#router bgp 1
R1(config-router)#network 1.1.1.0 mask 255.255.255.0
R2(config)#router bgp 2
R2(config-router)#network 2.2.2.0 mask 255.255.255.0
EBGP Multihop
eBGP (external BGP) by default requires two Cisco IOS routers to be directly connected to
each other in order to establish a neighbor adjacency. This is because eBGP routers use
a TTL of one for their BGP packets. When the BGP neighbor is more than one hop away,
the TTL will decrement to 0 and it will be discarded.
When these two routers are not directly connected then we can still make it work but we’ll
have to use multihop. This requirement does not apply to internal BGP.
Here’s an example:
Above we will try to configure eBGP between R1 and R3. Since R2 is in the middle, these
routers are more than one hop away from each other. Let’s take a look at the configuration:
First I will create some static routes so that R1 and R3 are able to reach each other. Now
we can configure eBGP:
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.23.3 remote-as 3
R3(config)#router bgp 3
R3(config-router)#neighbor 192.168.12.1 remote-as 1
Even though this configuration is correct, BGP will not even try to establish a eBGP
neighbor adjacency. BGP knows that since these routers are on different subnets, they are
not directly connected.
R2(config)#router ospf 1
R2(config-router)#network 192.168.23.0 0.0.0.255 area 0
R2(config-router)#network 2.2.2.0 0.0.0.255 area 0
R2(config)#router bgp 2
R2(config-router)#neighbor 4.4.4.4 remote-as 2
R2(config-router)#neighbor 4.4.4.4 update-source loopback 0
R2(config)#router bgp 2
R2(config-router)#neighbor 4.4.4.4 next-hop-self
R2(config)#router bgp 2
R2(config-router)#neighbor 3.3.3.3 remote-as 2
R2(config-router)#neighbor 3.3.3.3 update-source loopback 0
R2(config-router)#neighbor 3.3.3.3 next-hop-self
R4(config)#interface loopback 0
R4(config-if)#ip address 4.4.4.4 255.255.255.0
R4(config)#router ospf 1
R4(config-router)#network 192.168.34.0 0.0.0.255 area 0
R4(config-router)#network 4.4.4.0 0.0.0.255 area 0
R4(config)#router bgp 2
R4(config-router)#neighbor 2.2.2.2 remote-as 2
R4(config-router)#neighbor 2.2.2.2 update-source loopback 0
R4(config)#router bgp 2
R4(config-router)#neighbor 192.168.45.5 remote-as 3
R4(config)#router bgp 2
R4(config-router)#neighbor 2.2.2.2 next-hop-self
R4(config)#router bgp 2
R4(config-router)#neighbor 3.3.3.3 remote-as 2
R4(config-router)#neighbor 3.3.3.3 update-source loopback 0
R4(config-router)#neighbor 3.3.3.3 next-hop-self
R3(config)#router ospf 1
R3(config-router)#network 192.168.23.0 0.0.0.255 area 0
R3(config-router)#network 192.168.34.0 0.0.0.255 area 0
R3(config)#interface loopback 0
R3(config-if)#ip address 3.3.3.3 255.255.255.0
R3(config)#router ospf 1
R3(config-router)#network 3.3.3.0 0.0.0.255 area 0
R3(config)#router bgp 2
R3(config-router)#neighbor 2.2.2.2 remote-as 2
R3(config-router)#neighbor 2.2.2.2 update-source loopback 0
R3(config-router)#neighbor 4.4.4.4 remote-as 2
R3(config-router)#neighbor 4.4.4.4 update-source loopback 0
R5(config)#router bgp 3
R5(config-router)#neighbor 192.168.45.4 remote-as 2
R5(config)#router bgp 3
R5(config-router)#network 192.168.45.0 mask 255.255.255.0
Ok so what do we see here? Let’s start with the items I highlighted in red first. This router
has network 4.4.4.4/32 in its BGP table and in front of the network there’s the *> symbol:
The * means that this is a valid route and that BGP is able to use it.
The > means that this entry has been selected as the best path.
The next hop is 0.0.0.0. The next hop of 0.0.0.0 means that this network originated on this
router, that makes sense since I used the network command on R4 to advertise this
network into BGP.
The ‘i’ is the origin code and indicates that this network was advertised into BGP using the
network command, the table says it refers to IGP but it doesn’t have anything to do with
“interior gateway protocols”. When you redistribute something into BGP it will show up with
the ? symbol. You will never see the ‘e’ symbol, this refers to EGP (Exterior Gateway
Protocol) which is the predecessor of BGP.
Network command
Redistribution
Note:
Alright so far so good. What if we want to advertise a network that we don’t have? Let’s say
that I want to advertise network 1.0.0.0 /8 in BGP. We won’t be able to advertise this
network in BGP if it’s not in the routing table. To achieve this, we’ll put this network in our
routing table:
This can be done with a static route that points to the null interface, everything you send to
the null interface will be discarded. Using a static route like this is also called a discard
route.
Network 1.0.0.0 /8 is now in the routing table:
R1#show ip route 1.0.0.0
Routing entry for 1.0.0.0/8, 3 known subnets
Attached (3 connections)
Variably subnetted with 3 masks
S 1.0.0.0/8 is directly connected, Null0
C 1.1.1.0/24 is directly connected, Loopback1
L 1.1.1.1/32 is directly connected, Loopback1
Redistribution
Instead of using the network command we can also redistribute something into BGP. To
demonstrate this I will create a new loopback interface, advertise it in OSPF and then
redistribute it into BGP:
R1(config)#interface loopback 3
R1(config-if)#ip address 111.111.111.111 255.255.255.0
R1(config-if)#exit
R1(config)#router ospf 1
R1(config-router)#network 111.111.111.0 0.0.0.255 area 0
R1(config)#router bgp 1
R1(config-router)#redistribute ospf 1
Once R1 learns about prefix 3.3.3.0 /24 then the next hop IP address will remain
192.168.23.3. When R1 doesn’t know how to reach this IP address then it will fail to install
3.3.3.0 /24 in its routing table.
Let’s take a look at the configuration, I’ll show you two methods how we can deal with this
issue.
Configuration
Here’s the BGP configuraton that we will use:
R1(config)#router bgp 12
R1(config-router)#neighbor 192.168.12.2 remote-as 12
R2(config)#router bgp 12
R2(config-router)#neighbor 192.168.12.1 remote-as 12
R2(config-router)#neighbor 192.168.23.3 remote-as 3
R3(config)#router bgp 3
R3(config-router)#neighbor 192.168.23.2 remote-as 12
R3(config-router)#network 3.3.3.0 mask 255.255.255.0
The configuration is pretty straight forward. We use iBGP between R1/R2 and eBGP
between R2/R3. On R3 we advertised 3.3.3.0 /24 in BGP. Let’s take a look at the BGP
tables:
R2#show ip bgp
BGP table version is 2, local router ID is 192.168.23.2
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
R2 has installed 3.3.3.0 /24 in its BGP table and it is a valid route, the next hop is
192.168.23.3. Let’s check R1:
R1#show ip bgp
BGP table version is 1, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
R1 doesn’t know so it’s impossible to install 3.3.3.0 /24 in the routing table. How can we fix
this? I’ll show you two different methods.
Advertise Network
The first solution is simple, we can advertise the network in iBGP (or an IGP if you use one)
so that R1 is able to reach the next hop. Let’s advertise 192.168.23.0 /24 in BGP:
R2(config)#router bgp 12
R2(config-router)#network 192.168.23.0 mask 255.255.255.0
R1#show ip bgp
BGP table version is 3, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
R1 learns about 192.168.23.0 /24 so now it knows how to reach the next hop for 3.3.3.0 /24.
It can now install this network in the routing table:
This will work but there is another solution that is easier. Let’s clean up before we continue:
R2(config)#router bgp 12
R2(config-router)#no network 192.168.23.0 mask 255.255.255.0
R2(config)#router bgp 12
R2(config-router)#neighbor 192.168.12.1 next-hop-self
R1#show ip bgp
BGP table version is 6, local router ID is 192.168.12.1
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
BGP Auto-Summary
With auto-summary enabled, you can advertise a classful network and you don’t have to
add the mask parameter. BGP will automatically advertise the classful network if you have
the classful network or a subnet of this network in your routing table.
R1(config)#router bgp 1
R1(config-router)#network 1.0.0.0
Note that I didn’t specify a subnet mask with the mask parameter. Take a look at the BGP
table now:
As expected there is nothing in the BGP table since we require the exact network and
subnet mask. Let’s enable auto-summary now so you can see the difference:
R1(config)#router bgp 1
R1(config-router)#auto-summary
After enabling auto-summary things will change. Take a look at the BGP table of R1:
Chapter 2
BGP Neighbor Adjacency States
Just like OSPF or EIGRP, BGP establishes a neighbor adjacency with other BGP routers
before they exchange any routing information. Unlike other routing protocols however, BGP
does not use broadcast or multicast to “discover” other BGP neighbors.
1. Idle:This is the first state where BGP waits for a “start event”. The start event occurs
when someone configures a new BGP neighbor or when we reset an established BGP
peering. After the start event, BGP will initialize some resources, resets a ConnectRetry
timer and initiates a TCP connection to the remote BGP neighbor. It will also start
listening for a connection in case the remote BGP neighbor tries to establish a
connection. When successful, BGP moves to the Connect state. When it fails, it will
remain in the Idle state.
2. Connect: BGP is waiting for the TCP three-way handshake to complete. When it is
successful, it will continue to the OpenSent state. In case it fails, we continue to the
Active state. If the ConnectRetry timer expires then we will remain in this state. The
ConnectRetry timer will be reset and BGP will try a new TCP three-way handshake. If
anything else happens (for example resetting BGP) then we move back to the Idle state.
3. Active: BGP will try another TCP three-way handshake to establish a connection with
the remote BGP neighbor. If it is successful, it will move to the OpenSent state. If the
ConnectRetry timer expires then we move back to the Connect state. BGP will also
keep listening for incoming connections in case the remote BGP neighbor tries to
establish a connection. Other events can cause the router to go back to the Idle state
(resetting BGP for example).
4. OpenSent: In this state BGP will be waiting for an Open message from the remote BGP
neighbor. The Open message will be checked for errors, if something is wrong (incorrect
version numbers, wrong AS number, etc.) then BGP will respond with a Notification
message and jumps back to the Idle state. This is also the moment where BGP decides
whether we use EBGP or IBGP (since we check the AS number). If everything is OK
then BGP starts sending keepalive messages and resets its keepalive timer. At this
moment, the hold time is negotiated (lowest value is picked) between the two BGP
routers. In case the TCP session fails, BGP will jump back to the Active state. When any
other errors occur (expiration of hold timer), BGP will send a notification message with
the error code and jumps back to the Idle state. In case someone resets the BGP
process, we also jump back to the Idle state.
5. OpenConfirm: BGP waits for a keepalive message from the remote BGP neighbor.
When we receive the keepalive, we can move to the established state and the neighbor
adjacency will be completed. When this occurs, it will reset the hold timer. If we receive
a notification message from the remote BGP neighbor then we fall back to the Idle state.
BGP will keep sending keepalive messages.
6. Established: The BGP neighbor adjacency is complete and the BGP routers will send
update packets to exchange routing information. Every time we receive a keepalive or
update message, the hold timer will be resetted. In case we receive a notification
message we will jump back to the Idle state.
BGP Messages
BGP uses a variety of messages for establishing the connection, exchanging routing
information, checking if the remote BGP neighbor is still there and/or notifying the remote
side if any errors occur.
Open Message
Update Message
Keepalive Message
Notification Message
Open Message
Once two BGP routers have completed a TCP 3-way handshake they will attempt
to establish a BGP session, this is done using open messages. In the open message you
will find some information about the BGP router, these have to be negotiated and accepted
by both routers before we can exchange any routing information.
Update Message
Once two routers have become BGP neighbors, they can start exchanging routing
information. This is done with the update message. In the update message you will find
information about the prefixes that are advertised.In “BGP language” a prefix is referred to
as NLRI (Network Layer Reachability Information).
Keepalive Message
When there are no routes to be advertised or withdrawn, there’s not much our BGP
neighbors have to share with each other. To make sure the other side is “still there” we use
these periodic keepalive messages. By default, BGP sends 19 byte long keepalive
messages every 60 seconds. When a remote BGP neighbor misses three keepalives (3 x
60 = 180 seconds, the value of the hold time) it will flush the routes from the BGP neighbor.
Notification Message
The notification message is used when an error occurs which will result in termination of the
BGP neighbor adjacency. When something goes wrong, the notification message will be
sent and the session will be terminated.
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 weight 500
R2(config)#router bgp 2
R2(config-router)#bgp default local-preference 800
R3(config)#router bgp 2
R3(config-router)#neighbor 192.168.13.1 route-map LOCALPREF in
In my example AS 1 wants to make sure traffic enters the autonomous system through R2.
We can add our own autonomous system number multiple times so the as path becomes
longer. Since BGP prefers a shorter AS path we can influence our routing. This is called AS
path prepending. Let’s see what this looks like on Cisco routers, this is the topology that I
will use:
You will see IGP when you use the network command for BGP. It means you advertised
the network yourself in BGP. EGP is historical and you won’t see it in the BGP table
anymore. EGP is an old routing protocol we don’t use it anymore. Incomplete means you
have redistributed something into BGP.
MED (also called metric) is exchanged between autonomous systems and you can use it to
let the other AS know which path they should use to enter your AS. R2 is sending a MED of
200 towards AS 3. R3 is sending a MED of 300 to AS 3. AS 3 will prefer the lower metric
and send all traffic for AS 1 through R2.
R2(config)#router bgp 1
R2(config-router)#neighbor 192.168.12.2 route-map MED out
R3(config)#route-map MED permit 10
R3(config-route-map)#set metric 300
R3(config-route-map)#exit
R3(config)#router bgp 1
R3(config-router)#neighbor 192.168.23.2 route-map MED out
Chapter 4
BGP Communities
The BGP community attribute is a numerical value that can be assigned to a specific prefix and
advertised to other neighbors. When the neighbor receives the prefix it will examine
the community value and take proper action whether it is filtering or modifying other attributes.
There are 4 well known BGP communities that you can use or you can pick a numeric
value that you can use for your own policies.
Here are the 4 well known BGP communities:
When you add the no-advertise community to a prefix then the receiving BGP router will use
and store the prefix in its BGP table but it won’t advertise the prefix to any other
neighbors.
Let’s look at an example, this is the topology I will use:
Above you can see R1 with a loopback interface that has network 1.1.1.1 /32. We will
advertise this network in BGP towards R2 with the no advertise community set. As a result,
R2 will not advertise it to R3 (iBGP) or R4 (eBGP).
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 send-community
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 route-map NO_ADVERTISE out
R2(config)#router bgp 23
R2(config-router)#neighbor 192.168.12.1 route-map LOCAL_AS in
R2(config-router)#neighbor 3.3.3.3 send-community
[] is a range.
_ matches the space between AS numbers or the end of the AS PATH list.
Examples
^$ matches an empty AS PATH so it will match all prefixes from the local AS.
^51_ matches prefixes from AS 51 that is directly connected to our AS.
matches prefixes that originated in AS 51, the $ ensures that it’s the
_51$
beginning of the AS PATH.
^(51_)+([0- matches prefixes from the clients of directly connected AS 51, where AS 51
9]+) might be doing AS PATH prepending.
^51_([0-9]+_) matches prefixes from the clients of directly connected AS 51, where the
+ clients might be doing AS PATH prepending.
As far as I know there are 4 methods how you can prevent becoming a transit AS:
The ^$ regular expression ensures that we will only advertise locally originated prefixes.
We’ll have to apply this filter to both ISPs.
No-Export Community
R1(config)#route-map NO-EXPORT
R1(config-route-map)#set community no-export
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 route-map NO-EXPORT in
R1(config-router)#neighbor 192.168.13.3 route-map NO-EXPORT in
I’m only using one router in AS 1, if you have other routers and are running IBGP (Internal
BGP) then don’t forget to send communities to those routers with the neighbor <ip> send-
community command.
ISP1#show ip bgp
BGP table version is 11, local router ID is 11.11.11.11
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Prefix-List Filtering
Using a prefix-list we can determine what prefixes are advertised to our BGP neighbors.
This works fine but it’s not a good solution to prevent becoming a transit AS. Each time you
add new prefixes you’ll have to reconfigure the prefix-list. Anyway let me show you how it
works:
The prefix-list above will only advertise 1.1.1.0 /24 to the ISP routers. Let’s verify the
configuration:
ISP1#show ip bgp
BGP table version is 17, local router ID is 11.11.11.11
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Distribute-list Filtering
This method is similar to using the prefix-list but this time we’ll use an access-list.
ISP1#show ip bgp
BGP table version is 23, local router ID is 11.11.11.11
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
R1 and R2 are using IPv6 addresses and will use MP-BGP so that R1 can advertise
some prefixes on its loopback interfaces. All prefixes on the loopback interfaces
are /64 subnets while loopback3 has a /96 subnet.
Configuration
Let’s start with a basic MP-BGP configuration so that R1 and R2 become eBGP neighbors:
R1 & R2#
(config)ipv6 unicast-routing
R1(config)#router bgp 1
R1(config-router)#bgp router-id 1.1.1.1
R1(config-router)#neighbor 2001:db8:0:12::2 remote-as 2
R1(config-router)#address-family ipv6
R1(config-router-af)#neighbor 2001:db8:0:12::2 activate
R1(config-router-af)#network 2001:db8:0:1::/64
R1(config-router-af)#network 2001:db8:0:11::/64
R1(config-router-af)#network 2001:db8:0:111::/64
R1(config-router-af)#network 2001:db8:0:1111::/96
R2(config)#router bgp 2
R2(config-router)#bgp router-id 2.2.2.2
R2(config-router)#neighbor 2001:db8:0:12::1 remote-as 1
R2(config-router)#address-family ipv6
R2(config-router-af)#neighbor 2001:db8:0:12::1 activate
Prefix-List Filtering
Let’s start with the prefix-list. R1 is advertising one /96 subnet. Let’s see if we can configure
R2 to filter this network:
This prefix-list checks the entire 2001::/16 range and permits subnets with a /64 or larger.
Anything smaller will be denied. Let’s activate it:
R2(config)#router bgp 2
R2(config-router)#address-family ipv6
R2(config-router-af)#neighbor 2001:db8:0:12::1 prefix-list
SMALL_NETWORKS in
Filter-List Filtering
Let’s try the filter-list. We can use this to filter prefixes from certain autonomous systems.
Everything that R1 is advertising only has AS 1 in the AS path, I’ll configure AS prepending
so we have something to play with:
Let me explain the regular expression that I used here. The ^ symbol means that this is the
beginning of the string and the $ matches the end of the string. We put 3257 in between so
only “3257” matches. If you want to configure this filter on a Cisco IOS router you can do
this with the as-path access-list command:
ip as-path access-list 1 permit ^3257$
router bgp 1
neighbor 213.200.64.93 remote-as 3257
neighbor 213.200.64.93 route-map AS_PATH_FILTER in
Only allow networks that passed through AS 3257
We only want to see prefixes that passed through AS 3257, here’s how:
The regular expression starts and ends with a _ . This matches the space between the AS
path numbers. I’m not using a ^or $ to indicate the start and end of the string so there can
be as many autonomous systems as we want, as long as it passed through AS 3257 it will
match. Here’s what it looks like on a router:
router bgp 1
neighbor 213.200.64.93 remote-as 3257
neighbor 213.200.64.93 route-map AS_PATH_FILTER in
Deny prefixes that originated from AS 56203 and permit everything else
This one might be useful if you want to block prefixes that originated in a particular AS:
route-server.as3257.net>show ip bgp regexp _56203$
BGP table version is 4493689, local router ID is 213.200.87.253
Status codes: s suppressed, d damped, h history, * valid, > best, i
- internal
Origin codes: i - IGP, e - EGP, ? - incomplete
The first AS is always on the right side, so in order to match this we end the string with a $
and put the AS number just in front of it. The _ will match the space in front of the AS
number. On a router it will look like this:
router bgp 1
neighbor 213.200.64.93 remote-as 3257
neighbor 213.200.64.93 route-map AS_PATH_FILTER in
First we use a deny statement to block the AS number and then we use a permit .* to allow
everything else. The . (dot) matches anything and the * (wildcard) means “repeat the
previous character zero or many times”. This will permit everything.
We start with the ^3257 so that we only accept prefixes from AS 3257. The _ will match on
the space and the [0-9] will match on any character between 0 and 9. The * means that we
repeat the last character (0-9). This means that AS1 would match, but also AS123 or
AS12345, etc. The $ at the end will make sure that only 1 autonomous system behind AS
3257 is allowed.
router bgp 1
neighbor 213.200.64.93 remote-as 3257
neighbor 213.200.64.93 route-map AS_PATH_FILTER in
That’s it for now! I hope these examples are helpful to understand regular expressions a bit
more and how to configure the as-path access-list on a Cisco IOS router. If you have any
questions, feel free to ask.
To simplify the configuration of BGP and to reduce the number of updates BGP has to
create, we can use peer groups. We can add neighbors to a peer group and then apply all
our configurations to the peer group. BGP will prepare the updates for the peer group which
requires less CPU resources than preparing them for each neighbor separately.
R1(config)#router bgp 1
R1(config-router)#neighbor 2.2.2.2 remote-as 2
R1(config-router)#neighbor 3.3.3.3 remote-as 3
R1(config-router)#neighbor 4.4.4.4 remote-as 4
R1(config-router)#neighbor 2.2.2.2 update-source loopback 0
R1(config-router)#neighbor 3.3.3.3 update-source loopback 0
R1(config-router)#neighbor 4.4.4.4 update-source loopback 0
R1(config-router)#neighbor 2.2.2.2 ebgp-multihop 2
R1(config-router)#neighbor 3.3.3.3 ebgp-multihop 2
R1(config-router)#neighbor 4.4.4.4 ebgp-multihop 2
N(N-1)/2
So that will be:
When we use a route reflector our network could look like this:
We still have 6 routers but each router only has an IBGP peering with the route reflector on
top. When one of those IBGP routes advertises a route to the route reflector, it will be
“reflected” to all other IBGP routers:
RR:
router bgp 1
network 1.1.1.1 mask 255.255.255.255
neighbor 192.168.12.2 remote-as 1
neighbor 192.168.12.2 route-reflector-client
neighbor 192.168.13.3 remote-as 1
neighbor 192.168.13.3 route-reflector-client
neighbor 192.168.14.4 remote-as 1
neighbor 192.168.14.4 route-reflector-client
neighbor 192.168.15.5 remote-as 1
neighbor 192.168.15.5 route-reflector-client
R5:
router bgp 65000
bgp cluster-id 3.3.3.3
network 5.5.5.5 mask 255.255.255.255
neighbor 1.1.1.1 remote-as 65000
neighbor 3.3.3.7 remote-as 65000
neighbor 192.168.14.6 remote-as 65000
neighbor 192.168.15.4 remote-as 65000
R6:
network 6.6.6.6 mask 255.255.255.255
neighbor 192.168.14.5 remote-as 65000
Confederations
Route Reflector
A BGP confederation divides our AS into sub-ASes to reduce the number of required IBGP
peerings. Within a sub-AS we still require full-mesh IBGP but between these sub-ASes we
use something that looks like EBGP but behaves like IBGP (called confederation BGP) .
Here’s an example of what a BGP confederation could look like:
By dividing our main AS into two sub-ASes we reduced the number of IBGP peerings from
15 to 8.
Within the sub-AS we still have the full-mesh IBGP requirement. Between sub-ASes it’s just
like EBGP, it’s up to you how many peerings you want. The outside world will never see
your sub-AS numbers, they will only see the main AS number.
Since the sub-AS numbers are not seen outside of your network you will often see private
AS numbers used for the sub-ASes (64512 – 65535) but you can pick any number you like.
Above we have AS 2 which is divided into two sub-ASes, AS 24 and AS 35. There’s also
AS 1 on top that we can use to see how the outside world sees our confederation.
R2(config)#router ospf 1
R2(config-router)#network 192.168.23.0 0.0.0.255 area 0
R2(config-router)#network 192.168.24.0 0.0.0.255 area 0
R2(config-router)#network 2.2.2.2 0.0.0.0 area 0
R3(config)#router ospf 1
R3(config-router)#network 192.168.23.0 0.0.0.255 area 0
R3(config-router)#network 192.168.35.0 0.0.0.255 area 0
R3(config-router)#network 3.3.3.3 0.0.0.0 area 0
R4(config)#router ospf 1
R4(config-router)#network 192.168.24.0 0.0.0.255 area 0
R4(config-router)#network 192.168.45.0 0.0.0.255 area 0
R4(config-router)#network 4.4.4.4 0.0.0.0 area 0
R5(config)#router ospf 1
R5(config-router)#network 192.168.35.0 0.0.0.255 area 0
R5(config-router)#network 192.168.45.0 0.0.0.255 area 0
R5(config-router)#network 5.5.5.5 0.0.0.0 area 0
R2(config)#router bgp 24
R2(config-router)#bgp confederation identifier 2
R2(config-router)#bgp confederation peers 35
R2(config-router)#neighbor 4.4.4.4 remote-as 24
R2(config-router)#neighbor 4.4.4.4 update-source loopback 0
R2(config-router)#neighbor 3.3.3.3 remote-as 35
R2(config-router)#neighbor 3.3.3.3 update-source loopback 0
R2(config-router)#neighbor 3.3.3.3 ebgp-multihop 2
R3(config)#router bgp 35
R3(config-router)#bgp confederation identifier 2
R3(config-router)#bgp confederation peers 24
R3(config-router)#neighbor 2.2.2.2 remote-as 24
R3(config-router)#neighbor 2.2.2.2 update-source loopback 0
R3(config-router)#neighbor 2.2.2.2 ebgp-multihop 2
R3(config-router)#neighbor 5.5.5.5 remote-as 35
R3(config-router)#neighbor 5.5.5.5 update-source loopback 0
R4(config)#router bgp 24
R4(config-router)#bgp confederation identifier 2
R4(config-router)#bgp confederation peers 35
R4(config-router)#neighbor 2.2.2.2 remote-as 24
R4(config-router)#neighbor 2.2.2.2 update-source loopback 0
R4(config-router)#neighbor 5.5.5.5 remote-as 35
R4(config-router)#neighbor 5.5.5.5 update-source loopback 0
R4(config-router)#neighbor 5.5.5.5 ebgp-multihop 2
R5(config)#router bgp 35
R5(config-router)#bgp confederation identifier 2
R5(config-router)#bgp confederation peers 24
R5(config-router)#neighbor 4.4.4.4 remote-as 24
R5(config-router)#neighbor 4.4.4.4 update-source loopback 0
R5(config-router)#neighbor 4.4.4.4 ebgp-multihop 2
R5(config-router)#neighbor 3.3.3.3 remote-as 35
R5(config-router)#neighbor 3.3.3.3 update-source loopback 0
R1(config)#router bgp 1
R1(config-router)#neighbor 192.168.12.2 remote-as 2
R2(config)#router bgp 24
R2(config-router)#neighbor 192.168.12.1 remote-as 1
R1 and R2 have a fast “backdoor” link and OSPF is configured to exchange some prefixes
between the two sites. To illustrate this I have added a loopback interface on these two
routers.
R1 and R2 are also configured to use EBGP with R3, they advertise the same prefixes as
they do in OSPF. This introduces a problem:
Above you see that R1 learns about the 2.2.2.2 /32 prefix through BGP (R3) and OSPF
(R2). Since EBGP has a lower (thus better) AD it will install this path in its routing table. The
same thing applies to R2 for the 1.1.1.1 /32 prefix.
Let’s take a look at this scenario on our routers, I’ll configure OSPF and BGP and you will
learn how to fix this problem.
R1(config)#router ospf 1
R1(config-router)#network 192.168.12.0 0.0.0.255 area 0
R1(config-router)#network 1.1.1.1 0.0.0.0 area 0
R2(config)#router ospf 1
R2(config-router)#network 192.168.12.0 0.0.0.255 area 0
R2(config-router)#network 2.2.2.2 0.0.0.0 area 0
R1 and R2 will now use R3 to reach each others loopback interfaces. This happens
because the AD of EBGP is 20 while OSPF has an AD of 110. As a result, OSPF is
removed from the routing table. So how do we fix this? You could change the administrative
distance manually but this tutorial is about the “backdoor” feature so let’s see how it works.