This article explains how to configure Border Gateway Protocol (BGP). In this tutorial you will learn BGP commands, metric and BGP configuration.
BGP is also a Routing protocol which has the below features:
- Border Gateway Protocol
- It is an Exterior Gateway Protocol ( EGP) and the only one available today
- Protocol of the Internet
- It is mainly used for Scalability, Reliability and control but NOT SPEED, thus different than other protocols
- BGP uses the concepts of Autonomous Systems ( AS)
- The IANA (Internet Assigned Numbers Authority) provides the AS numbers. The numbers 1 to 64511 are public AS numbers and 64512 to 65535 are private AS numbers
- An AS is a collection of networks under common administration
- BGP version is currently in use and the only EGP
- It uses TCP Port 179
- Interior Gateway Protocols ( RIP, IGRP, EIGRP, OSPF) operate within an Autonomous system where as BGP is used between two autonomous systems
- It is a PATH-VECTOR protocol. The autonomous system on a path to a network are listed as network in BGP
- It prevents loop using AS numbers
- Routing between AS is also known as Inter-Domain Routing
- Routers running BGP are known as BGP speakers
- BGP is open standard
- Is and Advanced distance vector protocol ( Path vector)
- It is Classless in nature and thus supports FLSM, VLSM, CIDR, auto and manual summary ( BGP v4)
- Updates are incremental and triggered
- Updates are sent as unicast to manually defined neighbors
- BGP runs on the OSI Application Layer and get reliability with the use of TCP ( port 179)
- Its Metric is Attributes
- The Administrative Distance is : 20 for External Updates and 200 for Internal Updates.
- BGP does not use load-balancing. Uses only one path per network
- As BGP uses Attributes as Metric, AS path is one of the metric which is the default. In AS Path, the path with the least number of AS hops is considered the best path
- IGP would advertise networks and cost to reach those networks, while BGP advertises pathways and the networks that are reachable at the end of a pathway.
As per the below figure, the AS 65111 would receive the advertisement for network 18.104.22.168 and see the path as having an autonomous system path of 65222 65333 65444.
It is important to know cases or scenarios where we can make use of BGP:
- If AS is working as a transmit for example ISP
- When an AS is connected to multiple AS, i.e. Multihomed
- If the data needs to be manipulated while entering or leaving the AS
When not to use BGP
It is advisable not to use BGP in these conditions:
- If you have a single home AS
- Insufficient resources like memory or CPU in routers
- If do not possess proper understanding about BGP route filtering and the path selection process
BGP Tables / Database
Like most routing protocols BGP also uses 3 tables:
- Neighbor Table: This contains the list of all configured BGP neighbors. The ‘show ip bgp summary’ command would show the neighbor table
- Forwarding Table / Routing Information Base (RIB): This contains a list of networks along their path and attributes which are known by BGP. The ‘show ip bgp’ command would display the information.
- Routing Table: This table lists the best path to the destination networks and also the next hop for each network. Like other protocols, the ‘show ip route’ will show the routing table
A site with a single ISP connection is called Singled-homed. That is making use of more than one ISPs for your network i.e. at a time you connect to more than one ISP
Multihoming is used for redundancy and backup, in case of failure of one of the ISPs the other is still active and also for better performance
BGP Peers (neighbors)
The routers used in BGP (called speakers) must form neighbor relationship (called peers) with other routers to function properly.
Two types of BGP neighbor relationships can be formed:
- iBGP (internal BGP) : The routers that form neighbor relationship with the AS. The iBGP neighbors need not be directly connected.
- eBGP (external BGP): The routers that form neighbor relationship between different AS. The eBGP neighbors need to be directly connected.
BGP Message Types
BGP uses 4 message types in its operations:
- Open: This message is sent after BGP neighbor is configured. This message is sent to establish or form peering with that neighbor. This message contains information such as the AS number, router ID and the hold-time.
- Update: Routing information between peers is transferred using this message. This message would include, new routes, withdrawn routes and the path attributes.
- Keepalive: Similar to Hellos in the other routing protocols, BGP uses keepalives which help in keeping the peering session active. The BGP peers exchange keepalive messages every 60 seconds.
- Notification: In the event of a problem which causes the router to end the BGP peering session, the BGP neighbor is send a notification message and the connection is closed.
BGP Peering State
When a BGP peer session is formed, it passes through some states. This process is called the BGP FSM (Finite State Machine).
- Idle: At this state there is no peering. The router would be searching the routing table to see if a route exists to reach a neighbor. If the state is Idle (admin) then it has been administratively shut own
- Connect: This is the state when the router finds a route to the neighbor and the TCP handshake is completed.
- Open Sent or Active: This message is sent to try to establish Peering. It is sent with the parameters for the BGP session.
- Open Confirm: When a router receives a reply to the Open message. It means that the router received an agreement on the parameters for forming a session. The router may also go into ACTIVE state if there is no response to the Open message.
- Established: When the peering has been established. At this state the routing begins. This is the desired state.
The command ‘show ip bgp neighbors’ and ‘show ip bgp summary’ can help us verify BGP peering status.
BGP Attributes Categories
The best path in BGP is chosen based on the attributes of its path. Four categories exist:
- Well-known mandatory: These attributes should be recognized by all BGP routers. It should be present in all BGP updates and should also be passed to other BGP routers. Examples: AS Path, Origin and Next Hop.
- Well-known discretionary: These attributes should be recognized by all the routers and should also be passed to other BGP routers. However, these need not be present in an update. Examples: Local preference
- Optional Transitive: These attributes may or may not be recognized by a BGP router but passing to other BGP routers is required. If this attribute is not recognized it would be marked as partial. Examples: aggregator, community.
- Optional Non-Transitive: This attribute may or may not be recognized by the BGP router and these are not passed to the other routers as well. Example: MED (Multi-Exit discriminator), originator ID.
AS Path: Is a Well-known, Mandatory attribute. It contains the list of AS though which the updates have traversed. The path that has the shortest AS Path is most preferred or desirable.
Next Hop: Is a Well-known, Mandatory attribute. As BGP is an AS to AS protocol, Next hop would NOT mean next router but instead Next Hop is equal to the IP to reach the next AS. This it is the IP address of the next AS to reach a given network.
Origin: Is a Well-known, Mandatory attribute. Tells some information about a network i.e. it tells how BGP learned about that network.
- IGP ‘i’ means it is advertised in BGP using a network command
- EGP ‘e’ means it is redistributed from some other source (EGP)
- Incomplete ‘?’ means redistributed into BGP from an IGP or static
NOTE: ‘i’ is better than ‘e’ and ‘e’ is better than ‘?’
Weight: Is a partial attribute. This is a Cisco proprietary attribute. It gives information on how to exit an AS. The path with the highest weight is more desirable. This is of local significance. The default weight is 0 for learned routes and 32768 for locally injected routes.
Local Preference: Is a Well-known discretionary attribute. It is a value that tells the iBGP peers which path needs to be used to exit or leave the AS. The path with the highest preference is considered more desirable. These are advertised only the iBGP neighbor within the AS and the default value is 100.
MED (Multi-Exit Discriminator): Is an Optional, Non-Transitive attribute. It define how the data traffic should enter an AS i.e. it shows the neighboring AS the available paths to select if some data need to arrive to your AS.
BGP Loop prevention mechanism
The use of autonomous system number in BGP acts as a loop prevention system. When any update about a network exits or leaves an AS, it’s AS number is prepended to the list of AS that have handled the update. When this information is received by an AS, the autonomous system list is examined and if the update contains its own AS number, then the update is discarded.
In the above diagram, we see the network 22.214.171.124 /16 is not accepted by the AS 65333, because it already has its own autonomous system number as prefix in its AS-PATH. Thus, it detects the loop.
Basic BGP Configuration
Consider the above scenario; we have two AS (AS 10 and AS 20). We will configure the router for communication between the different AS.
First let’s check if Router R2 (192.168.1.10) is able to ping router R3 (192.168.1.20). We see it unreachable.
Now let’s configure the Router for BGP.
We start the BGP process by issuing the command ‘router bgp 10’, here 10 is the AS number.
We specify the neighbors using the neighbor command and mention the AS to which the AS belongs.
The network is advertised using the ‘network’ command. We need to specify the subnet mask using the ‘mask’ keyword.
Now if we try to ping network 192.168.1.20 /24 from Router B, we will be able to successfully reach it.
Now if we use the command ‘show ip bgp neighbor’, we get a lot of useful information. Some important information is highlighted.
We can see the neighbor IP, the Remote AS number, BGP version and Router ID. It also displays the hold-time and keepalive interval and the BGP messages sent between the peers.
We have additional information also available, the output for is lengthy and you may need to scroll to see the complete information of the command.
The ‘show ip bgp summary’ command output looks like shown below.
The ‘show ip route’ would show the route entry for BGP using ‘B’.
The ‘show ip bgp’ shows the routing table
This article is to make you familiar with BGP and give a glimpse of the basic configurations and how the command outputs look and display valuable information. This particular protocol is vast and many more things can be done using BGP.
- Routing and Routing Protocols
- Routing, Static Routing, Dynamic Routing
- Default Route and Static Routes Configuration