# BGP - Border Gateway Protocol
## What is BGP
BGP stands for Border Gateway Protocol. It is the routing protocol used to exchange routing information between different autonomous systems on the internet. An autonomous system is a collection of networks under a single administrative domain, such as the network of an internet service provider or a large organization. BGP is the protocol that makes the internet function as a global interconnected network. Every large organization and internet service provider that connects to the internet uses BGP. BGP is defined in RFC 4271.
## Why BGP Exists
Interior gateway protocols like OSPF and EIGRP are designed to route within a single autonomous system. They are efficient for this purpose but cannot scale to the size of the internet and do not support the policy-based routing decisions that organizations need when connecting to the internet. BGP was designed to handle routing between autonomous systems at internet scale while allowing organizations to implement routing policies based on business agreements and other considerations.
## Autonomous System Numbers
Every autonomous system is identified by an autonomous system number or ASN. ASNs are assigned by regional internet registries. Originally ASNs were 16-bit numbers allowing values from 1 to 65535. Today 32-bit ASNs are used allowing about 4 billion autonomous system numbers. Private ASNs in the range 64512 to 65535 for 16-bit and 4200000000 to 4294967294 for 32-bit can be used within organizations similarly to private IP addresses.
## eBGP and iBGP
External BGP or eBGP is used between routers in different autonomous systems. When two organizations peer with each other they use eBGP. Internal BGP or iBGP is used between routers within the same autonomous system. iBGP ensures that all routers within an AS have consistent routing information. The default behavior of BGP is that routes learned from an iBGP peer are not advertised to other iBGP peers, requiring either a full mesh of iBGP sessions between all routers or the use of route reflectors.
## BGP Path Selection
BGP uses a set of attributes associated with each route to select the best path when multiple paths to the same destination exist. The path selection process evaluates attributes in a specific order. Weight is a Cisco proprietary attribute applied locally. Local preference indicates the preferred exit point from the autonomous system. AS path length represents the number of autonomous systems the route has passed through. Origin indicates how the route was originated. MED or Multi Exit Discriminator suggests to neighboring ASes the preferred entry point into the AS.
## BGP Peering and Sessions
BGP routers establish TCP sessions with their peers on port 179. The BGP session goes through several states before becoming established. After the TCP connection is established, routers exchange Open messages to negotiate session parameters. Then they exchange Update messages containing routing information. Keepalive messages are sent periodically to maintain the session.
## BGP Routing Policies
BGP allows organizations to implement detailed routing policies. An organization can prefer routes from one provider over another. It can advertise only certain routes to certain peers. It can set attributes on routes to influence how other ASes route traffic toward it. These policies are implemented using route maps, prefix lists, and community attributes.Back to Course