USD ($)
$
United States Dollar
India Rupee

What is BGP and How Does it Work?

Created by Thrilok Thallapelly in Articles 23 Nov 2023
Share

The full form of BGP is Border Gateway Protocol in networking.

It is one of the most important components for the working of Internet that is widely used protocol for routing over the Internet.

In this blog, I'll discuss some of the core components revolve around BGP that will help you to understand the basic concepts of Border Gateway Protocol. 


Table Of Content


1.0 What is BGP?

1.1 What is Autonomous System (AS)?

1.2 What is BGP Routing?

1.3 What is BGP Port Number?

2.0 What are the BGP Rules?

2.1 What is BGP Neighbor or What is BGP Peering?

2.2 What are BGP States?

2.3 eBGP vs iBGP

2.4 What is BGP Split Horizon?

3.0 How Does BGP Work?

3.1 What are BGP Path Attributes?

3.2 What is BGP Best Path Selection Criteria?

3.3 What is BGP Prefix List?

3.4 What is BGP route map?

3.5 What is BGP Community?

4.0 Where is BGP Used?

5.0 How to Learn BGP?


What is BGP?


The BGP stands for Border Gateway Protocol, as its name suggest BGP is the protocol (Language all internet routers understand) that internet routers use to communicate with each other to exchange routing information.

In other words, the internet routers utilize BGP in various autonomous systems (AS) on the Internet to exchange routing information. You may be wondering about autonomous system and routing, so they are defined as:


What is Autonomous System (AS)?


A group of interconnected networks connected to internet routers that are managed by a single administrative domain, such as a business or organization or enterprises, is known as an Autonomous System (AS).

It is assigned by a 2-byte number called ASN or Autonomous Number. These ASN are exhausted now, so Internet Engineering Task Force (IETF) come up with a 4-byte ASN. Let me also give you a little brief on types of AS.

1. Multi Home AS - AS connected to two or more Autonomous Systems

2. Stub AS - AS connected to only one Autonomous System

3. Transit AS - AS acts like a link between two or more Autonomous Systems



What is BGP Routing?


BGP is a path vector protocol, which means it chooses the best route to a destination based on the qualities and path information of a route.

Internet BGP routers exchange these routes which they are aware of with each other across several autonomous systems.

Based on these routes, internet BGP routers build a routing table that displays the most direct route to each destination.




What is BGP Port Number?


BGP is an application layer protocol which uses TCP at transport layer. Its TCP port number is 179.



What are the BGP Rules?


BGP is the internet protocol that means some sort of rules must be defined all internet routers should follow them. 

Internet routers use these rules to make decisions about routing data between different networks.

Here are some key aspects of BGP rules: 



What is BGP neighbor or peering?


Internet routers should know each other before sharing any information to each other.

So first these routers become BGP neighbor or peer with each other and then start sharing routing information effectively.

Later they also exchange routing updates if there are some changes in the connected networks.



What are BGP States?


Let's talk about BGP states in brief, these are the different phases in the process of routers becoming BGP neighbors. 

1. Idle State: In this initial state, the two routers who wants to become neighbors wait for the BGP process to start.

2. Connect State: In this state, TCP connection requests initiates but 3-way handshake is not completed yet.

3. Active State: Enter into this state when BGP is unable to establish TCP connection with the neighbor.

4. OpenConfirm State: When a BGP router receives an Open message from its neighbor and also sends Keepalive. 

5. Established State: When both BGP routers receive Keepalive messages from each other. Here they start exchanging routing information.


eBGP vs iBGP


There are two main types of Border Gateway Protocol (BGP) that are used in the internet networks:


1. External BGP (EBGP):

EBGP is used to exchange routing information between different autonomous systems on the Internet.

In EBGP, routers in different AS establish BGP sessions with each other to exchange routing information and establish the best path to a destination. 

Administrative Distance (AD) value of eBGP is 20.


2. Internal BGP (IBGP):

IBGP is used to exchange routing information within the same autonomous system (AS).

IBGP routers are typically used to propagate routing information between different parts of the same AS, or to provide redundancy within an AS.

IBGP router do not need to be directly connected to each other, they can be connected via other BGP routers.

Administrative Distance (AD) value of iBGP is 200.


How AS PATH Attribute Handled by eBGP and iBGP


It’s important to remember that although if the two types of BGP are utilized in various ways, they share a common protocol and perform similarly.

The way EBGP and IBGP handle the AS PATH parameter is the major distinction between the two protocols. I cover BGP attributes in the later part of this blog article.

When a route is learned in EBGP, the AS PATH attribute is updated to include the router’s AS number. It helps in loop avoidance in eBGP.

While AS number is not assigned to the AS PATH element in iBGP.



What is Split Horizon in BGP?


Split horizon is a mechanism used in iBGP to avoid routing loops. If an iBGP router receives a route from its iBGP peer, then iBGP router does not propagate that route to its another iBGP peer. Routes are not passed on to the other peer creates a routing issue. There are some solutions to this problem:

1. Full Mesh: All routers in a AS form iBGP peering with each other.

2. Route Reflector: All routers form iBGP peering with a Route Reflector (RR).

3. Confederation: Large AS is divided into sub-as



How Does BGP Work?


As described previously that Border Gateway Protocol is a routing protocol used to exchange routing information between routers in different or same autonomous systems on the Internet.

BGP routers establish a session, called a BGP neighbor or peer relationship. When two BGP routers establish a neighbor relationship, they exchange their full routing tables with each other.

Each router then uses the information it receives to construct a routing table that shows the best path to each destination. BGP routers use a combination of metrics called BGP attribute to determine the best path to a destination.



What are BGP Path Attributes?


The optimum route to a destination is chosen by BGP routers via a technique known as BGP Best Path Selection.

Route attributes like the Weight, AS PATH, the origin code, and the MED etc. are used to determine which route to choose. The optimum path is determined by the router to be the one with the lowest metric.



What is BGP Best Path Selection Criteria?


BGP routers select the best path among multiple paths available to reach to the destination networks. The best path is selected based on the attributes associated with each route. The criteria, in order of preference are as follows:

1. Weight: It's a Cisco specific attribute, a route with higher weight is more preferred. It is local to a router. 

2. Local Preference: It determines preference of a route within AS. A BGP route with higher preference value is preferred. The default local preference value is 500.

3. AS Path Length: An AS is prepended when a route is traversed through various BGP autonomous systems. A BGP route with shorter AS Path length is more preferred.

4. Origin Code: IGP routes are preferred over EGP, and EGP routes are preferred over incomplete routes.

● IGP routes are advertised using interior gateway routing protocols and determine by "i".

● EGP routes are the routes advertised by exterior gateway protocol (Older BGP - never used).

● Incomplete routes are the routes advertised using redistribution and determine by "?".

5. Multi-Exit Discriminator (MED): It determines the preferred exit point for traffic leaving the AS. Lower MED value is preferred.

6. eBGP vs iBGP: eBGP routes are more preferred over iBGP routes.

7. IGP metric to Next Hop: A route with lower IGP metric to the next hop is more preferred. 

8. Next Hop: A route with reachable next hop IP address is more preferred.

9. Router ID: BGP uses the Router ID of the router advertising the route. The router with the lowest Router ID is preferred.

10. Cluster ID and Originator ID: They are considered only in case of route reflector. A route with the lowest Originator ID is preferred and Originator ID is used to avoid loops.



What is BGP Prefix List?


Prefix list is a route filtering mechanism used in BGP and with other protocols based on IP address prefixes. A prefix list is created by a name and with a sequence number for example

!

ip prefix-list TEST-LIST seq 10 permit 10.0.0.0/8

ip prefix-list TEST-LIST seq 20 permit 20.0.0.0/8

!

In this prefix list, there is a default implicit deny statement at the end of the prefix list. These prefix list can directly be used in BGP neighbor statement inbound or outbound to filter IP address prefixes. As an example, below is the BGP configuration.

!

router bgp 100

  neighbor 192.168.1.1 remote-as 101

  neighbor 192.168.1.1 prefix-list TEST-LIST out

!

In above configuration, prefix-list TEST-LIST is applied outbound to allow only the IP address prefixes present in the TEST-LIST prefix list to its BGP neighbor 192.168.1.1


What is BGP Route Map?


The prefix list can also be called from a route map for example below, there may be many other parameters such as local preference, weight, access-list, med etc. can be called from a route map. The route map statements are also permit and deny with a sequence number. 

!

route-map MY-ROUTE-MAP permit 10

 ip address prefix-list TEST-LIST

!

Now this route map then can be applied to the neighbor statement under BGP process. 

!

router bgp 100

  neighbor 192.168.1.1 remote-as 101

  neighbor 192.168.1.1 route-map MY-ROUTE-MAP out

!

In this configuration, route map also has an implicit deny statement in the end. The route-map is applied on neighbor 192.168.1.1 outbound, this route-map has prefix list which is permitting 10.0.0.0/8 and 20.0.0.0/8 only to its neighbor. 

Note: In above case, the result achieved by both i.e. directly applying prefix list and using route-map are same. 



BGP routers also exchange information about the reachability of a destination. This is done through the use of routing updates, which are sent to inform other routers about changes to the routing table.

These updates can include information about new routes that have become available, or routes that have become unavailable.


What is BGP Community?


BGP community is a 32-bit attribute, represented as 16-bit pair value for example 65000:101, first 16-bit value is AS number and other 16-bit value is assigned by administrator. There are the following types of communities.

1. Transitive vs. Non-transitive:

Transitive communities are propagated to BGP neighbors, while non-transitive communities are not. The default behavior is transitive.

2. Well-Known Communities:

There are a few well-known BGP communities with predefined meanings. For example:

No-Export : Prevents the route from being advertised to external BGP peers.

No-Advertise: Prevents the route from being advertised to any BGP peer.

3. Custom Communities:

Network administrators can define and use custom communities based on their specific needs. These communities can be used to implement various policies or convey information about the route.



Where is BGP Used?


Border Gateway Protocol (BGP) is used in several types of networks, including:


1. Internet Service Providers (ISPs): ISPs use BGP to communicate routing data among several Internet autonomous systems. This enables effective traffic routing between various networks and geographies.


2. Enterprise networks: In industrial networks, BGP is also used to exchange routing data across several sites or regions. This enables effective traffic routing within the same organization’s various departments.


3. Data center networks: BGP is used in data center networks to exchange routing information between different parts of the same data center or between different data centers. This allows for efficient routing of traffic and enables features such as load balancing and failover.


4. Service Provider networks: BGP is used by Service providers for efficient traffic routing between different networks and to provide redundancy.


5. Inter-domain routing: BGP is the routing protocol used between different domains of the internet, it’s the only protocol that can be used to exchange routing information between different autonomous systems (AS).


In summary, BGP is widely used in different types of networks such as Internet Service Providers (ISPs), Enterprise networks, Data center networks, Service Provider networks, and mainly used in inter-domain routing on the internet.


How to Learn BGP?


Now you have the basic concepts on what is BGP and How does BGP work, you can go ahead and study more in-depth on the topics covered here and beyond. There are several ways to learn Border Gateway Protocol (BGP), including:


1. Online Courses:

There are many online courses available that cover BGP, several institutes such as Cisco and renowned platforms like Uninets.

These courses typically include live training, video lectures, quizzes, and hands-on lab exercises to help you learn the concepts and gain practical experience.


2. Books:

There are also several books available on BGP, But I recommend the following books which I have personally read, and I consider them the best books on BGP Routing Protocol.

● Internet Routing Architectures by Sam Halabi

● Routing TCP/IP Volume II by Jeff Doyle

These books provide in-depth explanations of the BGP protocol and its configuration and can be used as a reference guide.


3. Training centers:

Some training centers also offer BGP training courses. These courses are usually taught by certified instructors and provide hands-on experience with BGP.


4. Self-study:

You can also learn BGP by studying on your own using the Cisco documentation and other resources available online.

This method requires self-discipline, time management, and a willingness to experiment with BGP in a lab environment.


5. Labs:

Practical experience is crucial to master BGP, you can use software-based routers emulators like Uninets Virtual labs, GNS3, VIRL, or Eve-NG to set up your own lab and practice different BGP scenarios.

You can use the documentation and the knowledge you gained from the previous methods to understand how to configure and troubleshoot BGP on these routers.

It’s important to remember that using a variety of techniques you can learn BGP more effectively. For instance, you may read a book, do practices in lab, can take an online course to enhance your knowledge.

You may join live training where you can Implement your learnings and knowledge in labs.


Comments (0)

Share

Share this post with others