Border Gateway Protocol (BGP)
Border Gateway Protocol (BGP)
05 August 2020
BGP is a exterior gateway protocol (EGP), as opposed to RIP, OSPF, and EIGRP which are interior gateway protocols (IGP’s) as it is used to exchange routing updates like other routing protocols, but BGP typically does not exchange individual network routes (but it technically can), it exchanges summaries of network routes.. BGP is used when there are multiple paths available to send packets and to know the best path as it is considered as “Path Vector” routing protocol.
Other routing protocols like RIP, OSPF and EIGRP are all different but they have one thing in common that they look for the shortest path to reach to the destination. If we look at the internet, being able to manipulate the traffic paths is more important than to find the shortest path to the destination. Here BGP plays a vital role as it is the only routing protocol which is currently used on the internet.
The path used by BGP is Autonomous Systems – AS hop count instead of a device hop count. BGP Autonomous Systems are assigned an Autonomous System Number (ASN) where ASN is a 16-bit number (1 – 65535). ASN range 1 – 64511 are globally unique AS numbers and range 64512 – 65535 are private autonomous system numbers which have been reserved for private (or internal) use. BGP works on TCP protocol and the port no. is 179.
BGP has two flavors:
- External BGP (eBGP)
- Internal BGP (iBGP)
External BGP is used between autonomous systems to exchange routing information between the different autonomous systems. The Administrative Distance for eBGP is 20.
Internal BGP is used within the autonomous system to exchange routing information within the same autonomous systems. The Administrative Distance for iBGP is 200.
In the above figure, RouterB, RouterC and RouterD in AS 200 would form an iBGP peer relationship with each. RouterA in AS 100 and RouterB in AS 200 would form an eBGP peering similarly RouterD in AS 200 and RouterE in AS 300 would form an eBGP peering.
Once BGP neighborship is done, each router shares their full routing table and after that only changes to the routing table are forwarded to peers.
By default, all the iBGP neighbors must be fully meshed within the AS that is why iBGP neighbors do not have a hop restriction.
BGP Neighbors Configuration
In the above figure, RouterA and RouterB are members of AS 100 and RouterC is a member of AS 900.
Now the first step is to enable the BGP and specify the corresponding AS:
RouterB(config)# router bgp 100
Now RouterB is a member of AS 100. The next step is to establish the neighbor relationship. To configure a neighbor relationship with a RouterA in the same AS (iBGP Peering):
RouterB(config)# router bgp 100 RouterB(config-router)# neighbor 10.1.1.1 remote-as 100
To configure a neighbor relationship with a RouterC in the separate AS (eBGP Peering):
RouterB(config)# router bgp 100 RouterB(config-router)# neighbor 172.16.1.2 remote-as 900
Note: The syntax is the same to configure a neighbor relationship for both iBGP and eBGP.
In BGP, the basic fundamental rule is that the route must be in the routing table before BGP advertises the networks to eBGP peers. In the above example RouterB will not advertise the 10.5.0.0/16 network route to RouterC as it is not yet configured.
To advertise the RouterA network to RouterC:
RouterB(config)# router bgp 100 RouterB(config-router)# neighbor 172.16.1.2 remote-as 900 RouterB(config-router)# network 10.5.0.0 mask 255.255.0.0
Now all the Routers will advertise the routes.
BGP Routing Table
To view the BGP routing table, the command would be:
RouterB# show ip bgp
It will show the table which contains the list of routes.
To view the status of all the BGP neighbors, the command would be:
RouterB# show ip bgp neighbors
It will list out all the bgp neighbors of RouterB with their status.
BGP works on its attributes to determine the best path to reach to the destination. These are the BGP attributes in a specific order to find the best path:
- Weight: Prefer the path with the highest weight. (By default is 0)
- Local Preference: Prefer the path with highest local preference. (By default is 100)
- Origin: Prefer the originator of the route via network command. Prefer the next hop to the destination 0.0.0.0.
- AS-Path: Identifies the path to reach the preferred destination as it prefers the path with the shortest AS path.
- Origin Code: iBGP is preferred over eBGP.
- Multi-Exit-Discriminator (MED): Prefer the path with lowest MED which is by default 0.
- BGP Route Type: eBGP routes preferred over iBGP.
- Age: Oldest route is preferred.
- Router ID: Lowest BGP router id is preferred.
- Peer IP Address: Lowest IP is preferred.