1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be

2025/07/1104:32:49 hotcomm 1076

1. The concept of BGP

BGP (Border Gateway Protocol, Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is a protocol based on AS ( autonomous system ). BGP belongs to the external gateway routing protocol, which solves the problem of routing between AS. This is true, it is more suitable for use on the Internet. The key to BGP is to understand BGP messages, neighbor establishment, BGP routing attributes, routing principles, etc. What is the autonomous system of

01?

autonomous system (autonomous system, referred to as "AS"), is a collection of routers managed by the same technical management organization and using a unified routing strategy (running the same dynamic routing protocol). The number value range of the autonomous system is 1~65535. Among them, 1~64511 is a public AS number registered on the Internet, similar to a public IP address, and is the only and cannot be reused in the world; 64512~65535 is a private AS number, similar to a private IP address, which can be reused but is not visible on the Internet.

02Dynamic routing Category

Dynamic routing protocol has many classification methods, and the two most commonly used classifications are classified by autonomous system and protocol type.

1. Classification by autonomous system:

IGP: Internal gateway routing protocol, mainly including RIP, OSPF, ISIS, and EIGRP ( Cisco private protocol). The IGP routing protocol runs within the AS, solving the problem of routing within the AS. The main function is to discover and calculate routes.

EGP: External gateway routing protocol, usually refers to BGP, which runs between AS and AS, solving the problem of routing between AS. The main function of BGP is to control the propagation of routing entries and select the optimal route.

will generally first use the IGP protocol to calculate and discover routing entries within the autonomous system, and then pass the routes generated by the IGP protocol to other ASs (autonomous system) through the BGP protocol.

03BGP features

BGP solves the problem of routing learning between AS. Today's Internet is globally connected. In China, Internet operators include mobile, telecommunications and China Unicom. Each company has its own autonomous system and runs IGP protocols internally. However, the Internet requires interconnection, so through BGP, you can learn the other party's internal AS routing between Telecom and China Unicom, so that the users of Telecom and China Unicom can communicate with each other.

BGP has the following characteristics:

Transmission protocol: TCP, port number 179

BGP is an external routing protocol used to pass routing information between AS

is an enhanced path vector routing protocol

has a reliable routing update mechanism

has rich Metric (a metric standard) measurement methods

Loopless protocol design

is a routing entry with multiple attribute information

supports CIDR (that is, it supports subnet partition

rich routing filtering and routing strategies

No periodic update

Only incremental routes are sent

Periodically send KeepAlive (keep-alive) packets to maintain TCP connectivity

2. Working principle of BGP

BGP is a routing protocol across public networks and across AS (autonomous system), which can learn routing between AS. BGP's dynamic learning routing is also based on neighbors. BGP can work normally only if the neighbor relationship is normal.

01BGP neighbor relationship

The router running BGP is usually called a BGPSpeaker (speaker), and the speakers passing messages to each other are called peers (peers). The establishment, update and deletion of BGP neighbor relationships are completed through information such as 5 messages, 6 state machines and 5 tables between peers, and finally forming BGP neighbors.

(1) BGP message type and function: The type in the

BGP message header defines the BGP message type.BGP peers interact with routing information through five types of packets, including Open, Update, Notification, KeepAlive and Route-Refresh.

Open message: It is the first message sent after the TCP connection is established. It is used to establish the connection relationship between BGP peers, mainly including BGP version, local AS number, Holdtime (maintenance time) and other information.

update message: The update message is used to update routing information between BGP peers. The update message can advertise multiple accessible routing information with the same attributes, or revoke multiple unreachable routing information.

Notification message: When BGP detects an error state, the Notification message is immediately sent to the peer, and the BGP connection will be immediately interrupted. Regardless of the current state of BGP, the idle state will be returned as long as the Notification message is received.

Route-Refresh message: used to inform the peer of the refresh capability of the routes supported locally. When all BGP routers have Route-Refresh capabilities, if the BGP inlet routing policy changes, the local BGP router will send a Route-Refresh message to the peer. The peer receiving this message will resend its routing information to the local BGP router.

KeepAlive message: This message is sent periodically between peers to maintain the validity of the connection, similar to the hello packet in the OSPF protocol.

(2) BGP status:

BGP status describes the establishment process of BGP neighbors. There are six BGP statuses, namely Idle (idle), Connect (connect), Active (active), OpenSent (open send), OpenConfirm (open confirmation) and Established (established successfully).

Idle status: BGP rejects any incoming connection request, the Idle status is the initial state of BGP.

Connect status: In this state, BGP waits for the establishment of the TCP connection to be completed before deciding on subsequent operations.

Active status: In this state, BGP will try to establish a TCP connection, which is the intermediate state of BGP.

OpenSent status: In this state, BGP waits for the peer's Open message and checks the AS number, version number, Holdtime, etc. in the received Open message.

OpenConfirm status: In this state, BGP waits for KeepAlive or Notification packets.

Established state: In this state, BGP can exchange all messages between peers, which is also the normal working state of BGP.

During the process of establishing a BGP peer, the three usually visible states are Idle, Active, and Established. The status of both parties of the BGP peer must be established, so that the BGP neighbor relationship can be established, and both parties exchange routing information through Update messages.

(3) BGP database:

BGP database is the storage space required for BGP to work normally. According to the content saved, it can be divided into the following types:

IP routing table (IP-RIB): a global routing information database, including all the optimal IP routing information.

BGP routing table (Loc-RIB): BGP routing information library, including routing information advertised by local BGP Speaker, adds the optimal route to the IP routing table. Note: First, you should pay attention to the BGP routing table. If the BGP routing table is not the optimal route, it cannot be visible in the IP routing table.

neighbor table: a peer neighbor list list, including neighbor information at both ends of the peer, that is, a neighbor list.

Adi-RIB-In: The unprocessed routing information library declared by the peer to the local Speaker.

Adj-RIB-Out: The local Speaker declares to the routing information base of the specified peer.

(4) BGP neighbor relationship type:

can be roughly divided into two neighbor relationships in BGP: IBGP neighbor and EBGP neighbor.

IBGP: BGP neighbor relationship within the same AS. IBGP neighbor usually refers to the two ends of the peer running the BGP protocol are in the same AS domain and belonging to the same BGP AS.

EBGP: BGP neighbor relationship between AS. EBGP neighbor usually refers to the two ends of the peer running the BGP protocol in different ASs.The AS number of the

BGP neighbor is the same as the AS number of the local end, and the difference is the EBGP neighbor.

IGP (internal gateway protocol, such as OSPF) establishing neighbors generally requires direct connection between layer three devices and establishing neighbor relationships through broadcast or multicast. The neighbor relationship of BGP (external gateway protocol) is based on TCP, which means that as long as TCP/IP is accessible, BGP peers can establish neighbor relationships with each other regardless of whether they are directly connected. Therefore, the first thing BGP should consider before establishing a neighbor is that the path between peers is reachable (whether there is a route, it can be pinged). It is necessary to communicate between the two ends of the peer through IGP or static routing.

02 Method of advertised BGP routing

BGP routing is advertised through BGP commands, and there are two methods of advertised BGP routing: network and Import.

(1) network method:

Use the network command to publish the route (non-BGP) in the current device routing table to the BGP routing table and announce it to the neighbors. It is similar to the method of using the network command in OSPF, except that when BGP is announced, you only need to declare the network segment + mask number, such as: network 12.12.0.0 16.

(2) Import method:

Use the Import command to redistribute the routing information learned by the router to the BGP routing table. It is a way for BGP to declare routing. The routes that can be introduced include: direct connection routing, static routing and routes learned by dynamic routing protocols. Its command format is similar to redistribution of OSPF in RIP.

03BGP peer interaction principle

BGP device will add the optimal route to the BGP routing table to form a BGP route. After the BGP device establishes a neighbor relationship with the peer, the following interaction principle is adopted:

BGP route obtained from the IBGP peer, and the BGP device only passes it to its EBGP peer.

BGP route obtained from the EBGP peer, the BGP device passes it to all EBGP and IBGP peers (peer is IBGP only passes one hop, and peer is EBGP is not limited)

When there are multiple valid routes reaching the same destination address, the BGP device only publishes the optimal route to the peer

When there are multiple valid routes to the same destination address, the BGP device only publishes the optimal route to the peer

when the route is updated. The BGP device only sends the updated BGP route

all peers sent by all peers. The BGP device will receive the next hop during the delivery process. The next hop will be changed during the delivery process.

. All IBGP peers will not change during the delivery process (special attention is required)

. TTL value is 1 (special attention is required)

When passing the default IBGP The TTL value is 255

04 update source to establish neighbor relationship

To put it bluntly, when specifying a peer, use the other party's loopback port, because this interface is more stable than any physical interface. As long as the device is running, the loopback port will not be closed. As long as there is a link that can communicate with the other party's loopback address, it will not cause a change in the BGP state. If you use a physical interface, once this physical interface is down, then BGP is finished. Therefore, this method of using the loopback port to establish BGP neighbor is called the update source to establish neighbors. Usually, redundant link is used in the same AS to ensure the stability of BGP.(If you use the loopback address of the peer router in different ASs to establish a neighbor relationship, you need to change the TTL value on the two routers. For details, please refer to the configuration summary at the end of the blog post)

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

As in the figure above, the three routers are in the AS 100 area. If R1 and R3 want to use the update source to establish a neighbor relationship, then the configuration is as follows:

R1 router:

[R1]bgp 100

[R1-bgp]router-id 1.1.1.1

[R1-bgp]peer 3.3.3.3 as-number 100

[R1-bgp]peer 3.3.3.3 connect-interface LoopBack0

R3 router (refer to the configuration of R1 router for relevant command explanation):

[R3]bgp 100

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 1.1.1.1 as-number 100

[R3-bgp]peer 1.1.1.1 connect-interface LoopBack0

Note: local loopback interface must first make the peer reachable (that is, it can ping the other party's loopback address). You need to manually add the route entry of the peer loopback interface or use OSPF, RIP, etc. to automatically learn the route of the other party's loopback interface.

05 ensures that the next hop of IBGP can reach

BGP devices on the edge of the AS will receive the BGP routing information transmitted by its EBGP peer neighbor. As mentioned above: All EBGP peers change the next hop during the delivery process, while all IBGP peers remain unchanged during the delivery process. The previous figure will be intuitively explained: In the figure

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

, A-J is used instead of the router's interface IP address, and combined with the next hop of all EBGP peers during the transmission process, the next hop of all IBGP peers will not change during the transmission process. You can see what problems are in the figure (you can understand it yourself, it is in the late stage of lazy cancer, and I don't want to explain it). In the figure, the next hop in the router after the R3 router in the figure is wrong. The solution is to declare the next hop of R4 and R6 on the R3 and R5 routers as it is itself, and then you will find that the next hop address learned by R4 is E. The next jump that R6 learns is I. This only solves the problem that occurs when R1 declares routing. If R6 now announces another route, it is also necessary to declare the next hop for R3 and R1 on the R4 and R2 routers as it itself. This ensures that the next hop of IBGP is reachable.

configuration is as follows (take a router as an example. The explanation of the first three configuration commands can be referred to the comment above, mainly the last command to change the next hop of the route):

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 34.1.1.4 as-number 200

[R3-bgp]peer 34.1.1.4 as-number 200

[R3-bgp]peer 34.1.1.4 next-hop-local

06EBGP multi-hop

is easy to understand, because the TTL value between EBGP neighbors in the default BGP is 1, (TTL, the life cycle value of the packet, the value will be -1 every time a router passes through, and when the value is 0, the packet will be discarded). If the EBGP peer is not direct-connected (more than one router is required to communicate, and the TTL value is not enough), the TTL value limit will make the non-direct-connected peer unable to establish a neighbor relationship normally, so the EBGP multi-hop command needs to be used to solve the non-direct-connected neighbor relationship.As shown in the figure below, if EBGP multi-hop is not configured, then R1 and R3 will not be able to establish a neighbor relationship normally:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

Configure the R3 router multi-hop in the figure above (the R1 router also needs to perform a similar configuration, and then change the TTL value. Here we only take R3 as an example):

R3 Configuration is as follows:

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 12.0.0.1 as-number 100

[R3-bgp]peer 12.0.0.1 ebgp-max-hop 2 !-- indicates that the number of hops is 2, that is, TTL value is 2--

07 controls BGP routing

BGP protocol contains many routing attributes, these attributes can control BGP routing very flexibly. The attributes of

BGP are divided into four categories: arbitrary, optional transitions, and non-transitions. The following table is the attributes of BGP and the corresponding classification:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

(1) Public must-bearing: All BGP routers can recognize and must exist in the update message.


(2) Public arbitrary: All BGP routers can recognize it, but it does not require it to exist in the update message. You can decide whether to add it to the Update message according to the specific situation.


(3) Optional transition: The BGP router can choose whether to carry this attribute in the Update message. If the received router does not recognize this attribute, it can be forwarded to the neighbor router (this is what the transition means), which the neighbor router may recognize and use.


(4) Optional non-transition: The BGP router can choose whether to carry this attribute in the Update message. On the entire route published path, if some routers cannot recognize this property, it may cause the property to fail to work. Because if the received router does not recognize this attribute, it will discard this attribute and will no longer forward it to the neighbor router. Introduction to

BGP attributes:

BGP commonly used attributes include: Origin, AS-PATH, Next-Hop, Local-Perf and MED, etc.

(1) Origin attribute: It is a must-followed by public, used to define the source of path information, and its function is to mark how a route becomes a BGP route. It has the following three types:


IGP(I): The highest priority is, the route injected into the BGP routing table through the Network command, and its Origin property is IGP.


EGP(e): priority. The routing information obtained through EGP has the Origin attribute of EGP.


Incomplete(?): The lowest priority. Routing information learned through other ways. If BGP redistributes the routes introduced through the Import-route command, its Origin property is Incomplete. You can use the
display bgp routing-table command to view it and it will be displayed in the last column. The column name is Path/Ogn

(2) AS-PATH (AS path) attribute: This attribute records all AS numbers to pass through for a route from the local to the destination address in vector order. When accepting the route, if the device finds that there is this AS number in the AS-PATH list, it will not receive the route, thus avoiding the routing loop between AS.


If you see the AS number when viewing the BGP routing table, such as (100,200,300), it means that the routing entry has been propagated to the device through AS300, AS200 and AS100, where AS100 is the AS closest to this device.

(3) Next-Hop (next hop) attribute: It's back to the issue of ensuring that the next hop of IBGP can reach. Let's put it this way, the aforementioned guarantee that the next hop of IBGP can reach is to use the Next-Hop attribute, and it will not be explained.

(4) Local-Perf attribute: used to identify the priority of BGP routing, and is used to determine the optimal route when traffic leaves AS.When the BGP device obtains multiple routes with the same destination address but different next hops through different IBGP peers, a route with a higher priority Local-Perf attribute value will be selected. The Local-Perf attribute is only valid between IBGP peers and will not be advertised to other ASs. Local priority is passed inside the AS, and the higher the value, the more priority it is. The default priority is 100 and can be changed manually. Below is a configuration diagram I found online (you can use ACL to define some traffic, or you can directly modify the local priority. The following figure is based on ACL to set different priority levels for different network segments).

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

(5) MED attribute: used to judge the optimal route when traffic enters the neighbor AS. When a device running BGP obtains multiple routes with the same destination address but the next hop is different, under the same other conditions, the one with a smaller MED value will be selected as the best route to change the downstream route selection. The


MED attribute is only passed between two adjacent ASs, and the AS party receiving this attribute will no longer advertise it to any other third-party AS. The MED attribute can be configured manually, the default is 0. See the picture for the specific configuration:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

. The configuration on RT3 is as follows. You can control the routing of the two routers in AS200:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

08BGP's path selection principle

BGP The route selection principle
(1) If the next hop of the route to the destination network is unreachable, this route can be ignored
(2) Preferred-Value priority is the route with a high value
(3) Local-Preference priority is the route with a high value
(4) Aggregation route priority is higher than non-aggregated route
(5) Local manual aggregation route priority is higher than local automatic aggregation route
(6) Local route introduced through the Network command is higher than local route introduced through the Import-route command
(7) AS path with the shortest (minimum number) high priority is higher

(8) Comparison Origi n attribute, IGP priority is higher than EGP, EGP priority is higher than Incomplete
(9) Select the route with a smaller MED priority
(10) EBGP routing priority is higher than IBGP routing
(11) BGP priority is to select the path with low IGP metric
to BGP next hop
When all the above are the same, it is equivalent route and can be load-sharing (Note: AS-PATH must be consistent). When load-sharing, the following three principles are invalid

(12) Compare Cluster-List length, and shorter ones are preferred
(13) Compare Originator_ID (If there is no Originator_ID, use Router ID comparison), select the path with a smaller value
(14) and compare the IP address of the peer, select the path with the smallest IP address

3. BGP configuration example

The BGP theory above is so long-winded, but the real configuration is actually very simple (this also conforms to the characteristics of the network). Let’s configure it in an experimental diagram! network topology is as follows:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

01 requirements are as follows

1, AS 200 uses the OSPF protocol internally to make AS 200 interoperable, and runs the BGP protocol on each router within AS 200 (R1 and R2 and R3 establish neighbor relationships, R4 and R2, R3 and R5 establish neighbor relationships,), and runs the BGP protocol between each AS.

2, using the BGP protocols in R1 and R5, respectively, declare 21.0.0.0/24 and 20.0.0.0/24, so that all routers can learn these two routing information.

3. Control the routing through the attributes of BGP to realize routing communication of PC 1→R1→R2→R4→R5→PC 2→R5→R4→R3→R2→R1→PC 1. By the way, test multiple control path selection methods.

4. Inject local OSPF routing information into the BGP protocol on R2, R3 and R4 routers respectively to enable the entire network to communicate (although the third requirement is to control routing, it does not mean that PC1 can ping any router, such as R2).

5. In order to introduce the EBGP multi-hop configuration, try R1 and R4 to directly establish a peer relationship.

1. The concept of BGP

BGP (Border Gateway Protocol, Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is a protocol based on AS ( autonomous system ). BGP belongs to the external gateway routing protocol, which solves the problem of routing between AS. This is true, it is more suitable for use on the Internet. The key to BGP is to understand BGP messages, neighbor establishment, BGP routing attributes, routing principles, etc. What is the autonomous system of

01?

autonomous system (autonomous system, referred to as "AS"), is a collection of routers managed by the same technical management organization and using a unified routing strategy (running the same dynamic routing protocol). The number value range of the autonomous system is 1~65535. Among them, 1~64511 is a public AS number registered on the Internet, similar to a public IP address, and is the only and cannot be reused in the world; 64512~65535 is a private AS number, similar to a private IP address, which can be reused but is not visible on the Internet.

02Dynamic routing Category

Dynamic routing protocol has many classification methods, and the two most commonly used classifications are classified by autonomous system and protocol type.

1. Classification by autonomous system:

IGP: Internal gateway routing protocol, mainly including RIP, OSPF, ISIS, and EIGRP ( Cisco private protocol). The IGP routing protocol runs within the AS, solving the problem of routing within the AS. The main function is to discover and calculate routes.

EGP: External gateway routing protocol, usually refers to BGP, which runs between AS and AS, solving the problem of routing between AS. The main function of BGP is to control the propagation of routing entries and select the optimal route.

will generally first use the IGP protocol to calculate and discover routing entries within the autonomous system, and then pass the routes generated by the IGP protocol to other ASs (autonomous system) through the BGP protocol.

03BGP features

BGP solves the problem of routing learning between AS. Today's Internet is globally connected. In China, Internet operators include mobile, telecommunications and China Unicom. Each company has its own autonomous system and runs IGP protocols internally. However, the Internet requires interconnection, so through BGP, you can learn the other party's internal AS routing between Telecom and China Unicom, so that the users of Telecom and China Unicom can communicate with each other.

BGP has the following characteristics:

Transmission protocol: TCP, port number 179

BGP is an external routing protocol used to pass routing information between AS

is an enhanced path vector routing protocol

has a reliable routing update mechanism

has rich Metric (a metric standard) measurement methods

Loopless protocol design

is a routing entry with multiple attribute information

supports CIDR (that is, it supports subnet partition

rich routing filtering and routing strategies

No periodic update

Only incremental routes are sent

Periodically send KeepAlive (keep-alive) packets to maintain TCP connectivity

2. Working principle of BGP

BGP is a routing protocol across public networks and across AS (autonomous system), which can learn routing between AS. BGP's dynamic learning routing is also based on neighbors. BGP can work normally only if the neighbor relationship is normal.

01BGP neighbor relationship

The router running BGP is usually called a BGPSpeaker (speaker), and the speakers passing messages to each other are called peers (peers). The establishment, update and deletion of BGP neighbor relationships are completed through information such as 5 messages, 6 state machines and 5 tables between peers, and finally forming BGP neighbors.

(1) BGP message type and function: The type in the

BGP message header defines the BGP message type.BGP peers interact with routing information through five types of packets, including Open, Update, Notification, KeepAlive and Route-Refresh.

Open message: It is the first message sent after the TCP connection is established. It is used to establish the connection relationship between BGP peers, mainly including BGP version, local AS number, Holdtime (maintenance time) and other information.

update message: The update message is used to update routing information between BGP peers. The update message can advertise multiple accessible routing information with the same attributes, or revoke multiple unreachable routing information.

Notification message: When BGP detects an error state, the Notification message is immediately sent to the peer, and the BGP connection will be immediately interrupted. Regardless of the current state of BGP, the idle state will be returned as long as the Notification message is received.

Route-Refresh message: used to inform the peer of the refresh capability of the routes supported locally. When all BGP routers have Route-Refresh capabilities, if the BGP inlet routing policy changes, the local BGP router will send a Route-Refresh message to the peer. The peer receiving this message will resend its routing information to the local BGP router.

KeepAlive message: This message is sent periodically between peers to maintain the validity of the connection, similar to the hello packet in the OSPF protocol.

(2) BGP status:

BGP status describes the establishment process of BGP neighbors. There are six BGP statuses, namely Idle (idle), Connect (connect), Active (active), OpenSent (open send), OpenConfirm (open confirmation) and Established (established successfully).

Idle status: BGP rejects any incoming connection request, the Idle status is the initial state of BGP.

Connect status: In this state, BGP waits for the establishment of the TCP connection to be completed before deciding on subsequent operations.

Active status: In this state, BGP will try to establish a TCP connection, which is the intermediate state of BGP.

OpenSent status: In this state, BGP waits for the peer's Open message and checks the AS number, version number, Holdtime, etc. in the received Open message.

OpenConfirm status: In this state, BGP waits for KeepAlive or Notification packets.

Established state: In this state, BGP can exchange all messages between peers, which is also the normal working state of BGP.

During the process of establishing a BGP peer, the three usually visible states are Idle, Active, and Established. The status of both parties of the BGP peer must be established, so that the BGP neighbor relationship can be established, and both parties exchange routing information through Update messages.

(3) BGP database:

BGP database is the storage space required for BGP to work normally. According to the content saved, it can be divided into the following types:

IP routing table (IP-RIB): a global routing information database, including all the optimal IP routing information.

BGP routing table (Loc-RIB): BGP routing information library, including routing information advertised by local BGP Speaker, adds the optimal route to the IP routing table. Note: First, you should pay attention to the BGP routing table. If the BGP routing table is not the optimal route, it cannot be visible in the IP routing table.

neighbor table: a peer neighbor list list, including neighbor information at both ends of the peer, that is, a neighbor list.

Adi-RIB-In: The unprocessed routing information library declared by the peer to the local Speaker.

Adj-RIB-Out: The local Speaker declares to the routing information base of the specified peer.

(4) BGP neighbor relationship type:

can be roughly divided into two neighbor relationships in BGP: IBGP neighbor and EBGP neighbor.

IBGP: BGP neighbor relationship within the same AS. IBGP neighbor usually refers to the two ends of the peer running the BGP protocol are in the same AS domain and belonging to the same BGP AS.

EBGP: BGP neighbor relationship between AS. EBGP neighbor usually refers to the two ends of the peer running the BGP protocol in different ASs.The AS number of the

BGP neighbor is the same as the AS number of the local end, and the difference is the EBGP neighbor.

IGP (internal gateway protocol, such as OSPF) establishing neighbors generally requires direct connection between layer three devices and establishing neighbor relationships through broadcast or multicast. The neighbor relationship of BGP (external gateway protocol) is based on TCP, which means that as long as TCP/IP is accessible, BGP peers can establish neighbor relationships with each other regardless of whether they are directly connected. Therefore, the first thing BGP should consider before establishing a neighbor is that the path between peers is reachable (whether there is a route, it can be pinged). It is necessary to communicate between the two ends of the peer through IGP or static routing.

02 Method of advertised BGP routing

BGP routing is advertised through BGP commands, and there are two methods of advertised BGP routing: network and Import.

(1) network method:

Use the network command to publish the route (non-BGP) in the current device routing table to the BGP routing table and announce it to the neighbors. It is similar to the method of using the network command in OSPF, except that when BGP is announced, you only need to declare the network segment + mask number, such as: network 12.12.0.0 16.

(2) Import method:

Use the Import command to redistribute the routing information learned by the router to the BGP routing table. It is a way for BGP to declare routing. The routes that can be introduced include: direct connection routing, static routing and routes learned by dynamic routing protocols. Its command format is similar to redistribution of OSPF in RIP.

03BGP peer interaction principle

BGP device will add the optimal route to the BGP routing table to form a BGP route. After the BGP device establishes a neighbor relationship with the peer, the following interaction principle is adopted:

BGP route obtained from the IBGP peer, and the BGP device only passes it to its EBGP peer.

BGP route obtained from the EBGP peer, the BGP device passes it to all EBGP and IBGP peers (peer is IBGP only passes one hop, and peer is EBGP is not limited)

When there are multiple valid routes reaching the same destination address, the BGP device only publishes the optimal route to the peer

When there are multiple valid routes to the same destination address, the BGP device only publishes the optimal route to the peer

when the route is updated. The BGP device only sends the updated BGP route

all peers sent by all peers. The BGP device will receive the next hop during the delivery process. The next hop will be changed during the delivery process.

. All IBGP peers will not change during the delivery process (special attention is required)

. TTL value is 1 (special attention is required)

When passing the default IBGP The TTL value is 255

04 update source to establish neighbor relationship

To put it bluntly, when specifying a peer, use the other party's loopback port, because this interface is more stable than any physical interface. As long as the device is running, the loopback port will not be closed. As long as there is a link that can communicate with the other party's loopback address, it will not cause a change in the BGP state. If you use a physical interface, once this physical interface is down, then BGP is finished. Therefore, this method of using the loopback port to establish BGP neighbor is called the update source to establish neighbors. Usually, redundant link is used in the same AS to ensure the stability of BGP.(If you use the loopback address of the peer router in different ASs to establish a neighbor relationship, you need to change the TTL value on the two routers. For details, please refer to the configuration summary at the end of the blog post)

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

As in the figure above, the three routers are in the AS 100 area. If R1 and R3 want to use the update source to establish a neighbor relationship, then the configuration is as follows:

R1 router:

[R1]bgp 100

[R1-bgp]router-id 1.1.1.1

[R1-bgp]peer 3.3.3.3 as-number 100

[R1-bgp]peer 3.3.3.3 connect-interface LoopBack0

R3 router (refer to the configuration of R1 router for relevant command explanation):

[R3]bgp 100

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 1.1.1.1 as-number 100

[R3-bgp]peer 1.1.1.1 connect-interface LoopBack0

Note: local loopback interface must first make the peer reachable (that is, it can ping the other party's loopback address). You need to manually add the route entry of the peer loopback interface or use OSPF, RIP, etc. to automatically learn the route of the other party's loopback interface.

05 ensures that the next hop of IBGP can reach

BGP devices on the edge of the AS will receive the BGP routing information transmitted by its EBGP peer neighbor. As mentioned above: All EBGP peers change the next hop during the delivery process, while all IBGP peers remain unchanged during the delivery process. The previous figure will be intuitively explained: In the figure

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

, A-J is used instead of the router's interface IP address, and combined with the next hop of all EBGP peers during the transmission process, the next hop of all IBGP peers will not change during the transmission process. You can see what problems are in the figure (you can understand it yourself, it is in the late stage of lazy cancer, and I don't want to explain it). In the figure, the next hop in the router after the R3 router in the figure is wrong. The solution is to declare the next hop of R4 and R6 on the R3 and R5 routers as it is itself, and then you will find that the next hop address learned by R4 is E. The next jump that R6 learns is I. This only solves the problem that occurs when R1 declares routing. If R6 now announces another route, it is also necessary to declare the next hop for R3 and R1 on the R4 and R2 routers as it itself. This ensures that the next hop of IBGP is reachable.

configuration is as follows (take a router as an example. The explanation of the first three configuration commands can be referred to the comment above, mainly the last command to change the next hop of the route):

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 34.1.1.4 as-number 200

[R3-bgp]peer 34.1.1.4 as-number 200

[R3-bgp]peer 34.1.1.4 next-hop-local

06EBGP multi-hop

is easy to understand, because the TTL value between EBGP neighbors in the default BGP is 1, (TTL, the life cycle value of the packet, the value will be -1 every time a router passes through, and when the value is 0, the packet will be discarded). If the EBGP peer is not direct-connected (more than one router is required to communicate, and the TTL value is not enough), the TTL value limit will make the non-direct-connected peer unable to establish a neighbor relationship normally, so the EBGP multi-hop command needs to be used to solve the non-direct-connected neighbor relationship.As shown in the figure below, if EBGP multi-hop is not configured, then R1 and R3 will not be able to establish a neighbor relationship normally:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

Configure the R3 router multi-hop in the figure above (the R1 router also needs to perform a similar configuration, and then change the TTL value. Here we only take R3 as an example):

R3 Configuration is as follows:

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 12.0.0.1 as-number 100

[R3-bgp]peer 12.0.0.1 ebgp-max-hop 2 !-- indicates that the number of hops is 2, that is, TTL value is 2--

07 controls BGP routing

BGP protocol contains many routing attributes, these attributes can control BGP routing very flexibly. The attributes of

BGP are divided into four categories: arbitrary, optional transitions, and non-transitions. The following table is the attributes of BGP and the corresponding classification:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

(1) Public must-bearing: All BGP routers can recognize and must exist in the update message.


(2) Public arbitrary: All BGP routers can recognize it, but it does not require it to exist in the update message. You can decide whether to add it to the Update message according to the specific situation.


(3) Optional transition: The BGP router can choose whether to carry this attribute in the Update message. If the received router does not recognize this attribute, it can be forwarded to the neighbor router (this is what the transition means), which the neighbor router may recognize and use.


(4) Optional non-transition: The BGP router can choose whether to carry this attribute in the Update message. On the entire route published path, if some routers cannot recognize this property, it may cause the property to fail to work. Because if the received router does not recognize this attribute, it will discard this attribute and will no longer forward it to the neighbor router. Introduction to

BGP attributes:

BGP commonly used attributes include: Origin, AS-PATH, Next-Hop, Local-Perf and MED, etc.

(1) Origin attribute: It is a must-followed by public, used to define the source of path information, and its function is to mark how a route becomes a BGP route. It has the following three types:


IGP(I): The highest priority is, the route injected into the BGP routing table through the Network command, and its Origin property is IGP.


EGP(e): priority. The routing information obtained through EGP has the Origin attribute of EGP.


Incomplete(?): The lowest priority. Routing information learned through other ways. If BGP redistributes the routes introduced through the Import-route command, its Origin property is Incomplete. You can use the
display bgp routing-table command to view it and it will be displayed in the last column. The column name is Path/Ogn

(2) AS-PATH (AS path) attribute: This attribute records all AS numbers to pass through for a route from the local to the destination address in vector order. When accepting the route, if the device finds that there is this AS number in the AS-PATH list, it will not receive the route, thus avoiding the routing loop between AS.


If you see the AS number when viewing the BGP routing table, such as (100,200,300), it means that the routing entry has been propagated to the device through AS300, AS200 and AS100, where AS100 is the AS closest to this device.

(3) Next-Hop (next hop) attribute: It's back to the issue of ensuring that the next hop of IBGP can reach. Let's put it this way, the aforementioned guarantee that the next hop of IBGP can reach is to use the Next-Hop attribute, and it will not be explained.

(4) Local-Perf attribute: used to identify the priority of BGP routing, and is used to determine the optimal route when traffic leaves AS.When the BGP device obtains multiple routes with the same destination address but different next hops through different IBGP peers, a route with a higher priority Local-Perf attribute value will be selected. The Local-Perf attribute is only valid between IBGP peers and will not be advertised to other ASs. Local priority is passed inside the AS, and the higher the value, the more priority it is. The default priority is 100 and can be changed manually. Below is a configuration diagram I found online (you can use ACL to define some traffic, or you can directly modify the local priority. The following figure is based on ACL to set different priority levels for different network segments).

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

(5) MED attribute: used to judge the optimal route when traffic enters the neighbor AS. When a device running BGP obtains multiple routes with the same destination address but the next hop is different, under the same other conditions, the one with a smaller MED value will be selected as the best route to change the downstream route selection. The


MED attribute is only passed between two adjacent ASs, and the AS party receiving this attribute will no longer advertise it to any other third-party AS. The MED attribute can be configured manually, the default is 0. See the picture for the specific configuration:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

. The configuration on RT3 is as follows. You can control the routing of the two routers in AS200:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

08BGP's path selection principle

BGP The route selection principle
(1) If the next hop of the route to the destination network is unreachable, this route can be ignored
(2) Preferred-Value priority is the route with a high value
(3) Local-Preference priority is the route with a high value
(4) Aggregation route priority is higher than non-aggregated route
(5) Local manual aggregation route priority is higher than local automatic aggregation route
(6) Local route introduced through the Network command is higher than local route introduced through the Import-route command
(7) AS path with the shortest (minimum number) high priority is higher

(8) Comparison Origi n attribute, IGP priority is higher than EGP, EGP priority is higher than Incomplete
(9) Select the route with a smaller MED priority
(10) EBGP routing priority is higher than IBGP routing
(11) BGP priority is to select the path with low IGP metric
to BGP next hop
When all the above are the same, it is equivalent route and can be load-sharing (Note: AS-PATH must be consistent). When load-sharing, the following three principles are invalid

(12) Compare Cluster-List length, and shorter ones are preferred
(13) Compare Originator_ID (If there is no Originator_ID, use Router ID comparison), select the path with a smaller value
(14) and compare the IP address of the peer, select the path with the smallest IP address

3. BGP configuration example

The BGP theory above is so long-winded, but the real configuration is actually very simple (this also conforms to the characteristics of the network). Let’s configure it in an experimental diagram! network topology is as follows:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

01 requirements are as follows

1, AS 200 uses the OSPF protocol internally to make AS 200 interoperable, and runs the BGP protocol on each router within AS 200 (R1 and R2 and R3 establish neighbor relationships, R4 and R2, R3 and R5 establish neighbor relationships,), and runs the BGP protocol between each AS.

2, using the BGP protocols in R1 and R5, respectively, declare 21.0.0.0/24 and 20.0.0.0/24, so that all routers can learn these two routing information.

3. Control the routing through the attributes of BGP to realize routing communication of PC 1→R1→R2→R4→R5→PC 2→R5→R4→R3→R2→R1→PC 1. By the way, test multiple control path selection methods.

4. Inject local OSPF routing information into the BGP protocol on R2, R3 and R4 routers respectively to enable the entire network to communicate (although the third requirement is to control routing, it does not mean that PC1 can ping any router, such as R2).

5. In order to introduce the EBGP multi-hop configuration, try R1 and R4 to directly establish a peer relationship.

02 Start configuring

1, configure the IP addresses of each PC, router physical interface and loopback interface by yourself (I am a late-stage patient with lazy cancer, please wait for it). The router IP configuration reference:

R1sys

[R1]in g0/0/0

[R1-GigabitEthernet0/0/0]ip add 12.1.1.1 24

[R1-GigabitEthernet0/0/0]int loop 0

[R1-LoopBack0]ip add 1.1.1.1 32

2. Configure the OSPF routing protocol internal to AS 200:

R2 router configuration is as follows:

[R2]ospf 1

[R2-ospf-1]area 0

[R2-ospf-1-area-0.0.0.0]net 2.2.2.2 0.0.0.0.0

[R2-ospf-1-area-0.0.0.0]net 12.1.1.0 0.0.0.255

[R2-ospf-1-area-0.0.0.0]net 24.1.1.0 0.0.0.255

R3 router configuration is as follows (refer to R2 for the corresponding comment):

[R3]ospf 1

[R3-ospf-1]area 0

[R3-ospf-1-area-0.0.0.0]ne 3.3.3.3 0.0.0.0

[R3-ospf-1-area-0.0.0.0]ne 13.1.1.0 0.0.0.255

[R3-ospf-1-area-0.0.0.0]ne 34.1.1.0 0.0.0.255

R4 router configuration is as follows (refer to R2 for the corresponding comment):

[R4]ospf 1

[R4-ospf-1]area 0

[R4-ospf-1-area-0.0.0.0]ne 4.4.4.4 0.0.0.0

[R4-ospf-1-area-0.0.0.0]ne 24.1.1.0 0.0.0.255

[R4-ospf-1-area-0.0.0.0.0]ne 34.1.1.0 0.0.0.255

3. Start configuring BGP so that the corresponding router is a neighbor relationship:

R1 is configured as follows:

[R1]bgp 100

[R1-bgp]router-id 1.1.1.1

[R1-bgp]peer 12.1.1.2 as 200

[R1-bgp]peer 13.1.1.3 as 200

[R1-bgp]network 21.0.0.0 24

Since there are many repetitive commands when configuring BGP, there is no particularly different configuration, so I won't write comments.

R2 configuration is as follows:

[R2]bgp 200

[R2-bgp]router-id 2.2.2.2

[R2-bgp]peer 12.1.1.1 as 100

[R2-bgp]peer 4.4.4.4 as 200

[R2-bgp]peer 4.4.4.4 connect-interface LoopBack 0

[R2-bgp]peer 4.4.4.4 next-hop-local

R3 configuration is as follows:

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 13.1.1.1 as 100

[R3-bgp]peer 4.4.4.4 as 200

[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0

[R3-bgp]peer 4.4.4.4 next-hop-local

R4 configuration is as follows:

[R4]bgp 200

[R4-bgp]router-id 4.4.4.4

[R4-bgp]peer 2.2.2.2 as 200

[R4-bgp]peer 3.3.3.3 as 200

[R4-bgp]peer 2.2.2.2 next-hop-local

[R4-bgp]peer 2.2.2.2 connect-interface LoopBack 0

[R4-bgp]peer 3.3.3.3 connect-interface LoopBack 0

[R4-bgp]peer 45.1.1.5 as 300

R5 configuration is as follows:

[R5]bgp 300

[R5-bgp]router-id 5.5.5.5

[R5-bgp]peer 45.1.1.4 as 200

[R5-bgp]network 20.0.0.0 24

Now the neighbor relationship of BGP has been established, you can view it through the following command:

[R1]dis bgp peer
BGP local router ID: 1.1.1.1
Local AS number : 100
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
12.1.1.2 4 200 5 8 0 00:02:11 Established
1
13.1.1.3 4 200 7 10 0 00:04:34 Established
1

To this end, PC 1 can communicate with PC 2, of course it is done by the BGP protocol, but now, except for non-direct network segments and AS 200 internal routers, only PC1 and PC2 can communicate. For example, PC1 cannot ping the R2 router.

4. Start to make the third requirement, control the routing through the BGP attributes to realize routing communication of PC 1→R1→R2→R4→R5→PC 2→R5→R4→R3→R2→R1→PC 1.

First use the tracert command to view the routes when PC1 and PC2 communicate, and see which router they pass through.The router that

PC1 passes to PC5 is as follows:

PCtracert 20.0.0.1 #Use tracert command to view

traceroute to 20.0.0.1, 8 hops max

(ICMP), pressCtrl+Chtrl+Chtrl to to stop
1 21.0.0.254 1
ms 16 ms 15 ms
2 12.1.1.2 16
ms 15 ms 16 ms
3 24.1.1.4 31
ms 32 ms 31 ms
4 45.1.1.5 31
ms
47 ms 31 ms
5 *20.0.0.1 31
ms 32 ms

PC5 arrives at PC1 as follows:

PCtracert 21.0.0.1

tracerute to 21.0.0.1, 8 hops max

(ICMP), pressCtrl+Chtrl+Chtrl to to stop
1 20.0.0.254 15
ms 1 ms 16 ms
2 45.1.1.4 16
ms 31 ms 31 ms 31 ms 31 3ms 31 31 3ms 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 ms
4 12.1.1.1 47
ms 16 ms 47 ms
5 21.0.0.1 31
ms 31 ms 31 ms 31 ms 31 31 ms ms

Come on, start configuring the route selection problem (three methods can be implemented in total):

Implementation method 1: Modify the Local-Perf attribute to change the priority of the R3 router

Configuration on the R3 router is as follows:

[R3]route-policy lop permit node 10

Info: New Sequence of this List.

[R3-route-policy]apply local-preference 222

[R3-route-policy]quit

[R3]bgp 200

[R3-bgp]peer 4.4.4.4 route-policy lop exporttml3

[R3-bgp]quit

[R3]quitR3reset bgp all

At this time, check the router that PC5 arrives at PC1, and finds that it does not pass through R2 router, but passes through R3 router, as follows:

PCtracert 21.0.0.1

tracerute to 21.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+Chtrl to to stop

1 20.0.0.254 1 ms 16 ms 16 ms
2 45.1.1.4 15
ms 16 ms 31 ms
3 34.1.1.3 31
ms 32 ms 31 31 ms 31 34.1.1.3 31 ms 31 ms
4 13.1.1.1 47
ms 31 ms 47 ms
5 *21.0.0.1 47
ms 31 ms

Implementation method 2: Use the AS-PATH attribute to control the routing

In order to restore the initial effect of going R2, you need to clear the Local-Perf attribute configured by the R3 router in the previous step, and execute the following command in the R3 router to delete it:

[R3]bgp 200

[R3-bgp]undo peer 4.4.4.4 route-policy lop export

After deleting it, you can check it yourself after a while whether it has resumed the R2 router and not R3 when PC2 and PC1 are returned.

Then modify the AS-PATH attribute on the R2 router (that is, when the R2 router advertises the 21.0.0.0 network segment to the R4 router, it tells R4 that it has passed many areas. Of course, these areas are created, and the number of areas is definitely more than the number of areas that R3 passes, so R4 will choose to go R3 instead of R2 because it needs to take the optimal path):

R2 configuration is as follows:

[R2]route-policy as permit node 10

Info: New Sequence of this List.

[R2-route-policy]apply as-path 123 123 add

[R2-route-policy]quit

[R2]bgp 200

[R2-bgp]peer 4.4.4.4 route-policy as export

[R2-bgp]quit

[R2]quitR2reset bgp all

Now test it again on PC2, you will find that you have started to go to the R3 router again:

PCtracert 21.0.0.1

traceroute to 21.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+Chtrl to to stop

1 20.0.0.254 16 ms 1 ms 15 ms
2 45.1.1.4 32
ms 15 ms 31 ms
3 34.1.1.3 16
ms 32 ms
4 13.1.1.1 31
ms 31 ms 31 ms
5 *21.0.0.1 47
ms 31 31 ms

Implementation method 3: Use MED attributes to control the routing

. At the beginning, PC1 goes to PC5 and passes through the R2 router, not the R3 router. So now add the MED attributes of the R2 router and announce it to the R1 router, so that it passes through the R3 router instead of the R2 router.

[R2]route-policy med permit node 10

Info: New Sequence of this List.

[R2-route-policy]apply cost + 500

[R2-route-policy]quit

[R2]bgp 200

[R2-bgp]peer 12.1.1.1 route-policy med exporttml3

[R2-bgp]quit

[R2]quitR2reset bgp all

test on PC1:

PCtracert 20.0.0.1

tracerute 20.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+ChtrlChtrl to to stop

1 21.0.0.254 16 ms 1 ms 16 ms
2 13.1.1.3 15
ms
2 13.1.1.3 15
ms 16 ms 16 ms 16 ms 16 ms 16 ms 16 ms 16 ms
3 34.1.1.4 47
ms 16 ms 16 ms
4 45.1.1.5 31
ms
31 ms 31 ms
5 *20.0.0.1 32
ms 31 31 ms 31 ms

has been changed to the R3 router, indicating that the configuration is effective. It is not difficult to find through the implementation methods of these three route selections that BGP control route selection is mainly adjusted through the BGP attribute value. BGP contains a large number of attributes, and these attributes directly affect the selection of routes. All BGPs have stronger control capabilities than IGPs.

5, the fourth requirement: inject local OSPF routing information into the BGP protocol on R2, R3 and R4 routers respectively to enable the entire network to communicate.

R2 Router:

[R2]bgp 200
[R2-bgp]import-route ospf 1

R3:

[R3]bgp200[R3-bgp]import-route import-route ospf200[R3-bgp]import-route 2ospf200[R3-bgp]import-route 23ospf23200[R3-bgp]import-route 1

R4:

[R4]bgp 200[R4-bgp]import-route ospf 1

Click the router entries verification for each router! There are relevant viewing commands at the end of the article.

6, the fifth requirement: try R1 and R4 to directly establish a peer relationship.

R1 configuration is as follows:

[R1-bgp]bgp 100
[R1-bgp]peer 34.1.1.4 as 200
[R1-bgp]peer 34.1.1.4 ebgp-max-hop 2

R4 configuration is as follows:

[R4]bgp 200

[R4-bgp]peer 200

[R4-bgp]peer 13.1.1.1.1 as 100

[R4-bgp]peer 13.1.1.1 eb

[R4-bgp]peer 13.1.1.1 ebgp-max-hop 2

View verification (may need to wait a while before the neighbor is established successfully, the waiting time will not exceed two minutes)

[R1-bgp]dis bgp peer
BGP local router ID: 1.1.1.1
Local AS number: 100
Total number of peers: 3 Peers in established state: 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
12.1.1.2 4 200 27 38 0 00:17:49 Established
8
13.1.1.3 4 200 55 70 0 00:45:35 Established
8
34.1.1.4 4 200 12 13 0 00:00:02 Established
8

Related viewing command:

[R4]dis ip routing-table

[R4]dis ospf routing

[R4]dis bgp peer

[R1-bgp]dis bgp peer

4. Configuration summary

During the configuration process, you need to pay attention to the following points to avoid errors:

1. Before establishing a neighbor relationship and specifying the address of the peer router, be sure to ensure that the peer router can be pinged.

2. When establishing a BGP neighbor relationship within AS, it is best to specify the other party's Loopback address, but don't forget to update the source. Refer to the command: "[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0".

3. If there is more than one router running the BGP protocol within the AS, this is also the IBGP protocol within the AS. Don't forget to change the properties of the next hop, that is, the mentioned above, "ensure that the next hop of IBGP can reach" , the command reference: "[R4-bgp]peer 2.2.2.2 next-hop-local"

4. As mentioned earlier, if a neighbor relationship is established on two routers in different AS areas, even if the two routers are directly connected, its TTL value must be changed. The purpose is to allow the data packets used to establish neighbor relationships between the routers to pass through several more routers and then discarded.

Because although routers with different AS are directly connected, only one hop is enough, since the loopback address of the peer router is specified, the network segment of the loopback address must not be the same as the network segment directly connected to the router. After the router receives the packet, it treats it as the address on another router.

So when establishing a neighbor relationship between two ASs, you must change its hop number. If you establish a neighbor relationship between IBGP, you do not need to change the TTL value, because in IBGP, the TTL value of the data packet is default to 255. Reference command to change the TTL value: "[R1-bgp]peer 34.1.1.4 ebgp-max-hop 2"

The command needs to be skipped a few times and set the value to a few. It can be larger than the actual jump, but cannot be smaller than the actual jump.

4. Start to make the third requirement, control the routing through the BGP attributes to realize routing communication of PC 1→R1→R2→R4→R5→PC 2→R5→R4→R3→R2→R1→PC 1.

First use the tracert command to view the routes when PC1 and PC2 communicate, and see which router they pass through.

1. The concept of BGP

BGP (Border Gateway Protocol, Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is a protocol based on AS ( autonomous system ). BGP belongs to the external gateway routing protocol, which solves the problem of routing between AS. This is true, it is more suitable for use on the Internet. The key to BGP is to understand BGP messages, neighbor establishment, BGP routing attributes, routing principles, etc. What is the autonomous system of

01?

autonomous system (autonomous system, referred to as "AS"), is a collection of routers managed by the same technical management organization and using a unified routing strategy (running the same dynamic routing protocol). The number value range of the autonomous system is 1~65535. Among them, 1~64511 is a public AS number registered on the Internet, similar to a public IP address, and is the only and cannot be reused in the world; 64512~65535 is a private AS number, similar to a private IP address, which can be reused but is not visible on the Internet.

02Dynamic routing Category

Dynamic routing protocol has many classification methods, and the two most commonly used classifications are classified by autonomous system and protocol type.

1. Classification by autonomous system:

IGP: Internal gateway routing protocol, mainly including RIP, OSPF, ISIS, and EIGRP ( Cisco private protocol). The IGP routing protocol runs within the AS, solving the problem of routing within the AS. The main function is to discover and calculate routes.

EGP: External gateway routing protocol, usually refers to BGP, which runs between AS and AS, solving the problem of routing between AS. The main function of BGP is to control the propagation of routing entries and select the optimal route.

will generally first use the IGP protocol to calculate and discover routing entries within the autonomous system, and then pass the routes generated by the IGP protocol to other ASs (autonomous system) through the BGP protocol.

03BGP features

BGP solves the problem of routing learning between AS. Today's Internet is globally connected. In China, Internet operators include mobile, telecommunications and China Unicom. Each company has its own autonomous system and runs IGP protocols internally. However, the Internet requires interconnection, so through BGP, you can learn the other party's internal AS routing between Telecom and China Unicom, so that the users of Telecom and China Unicom can communicate with each other.

BGP has the following characteristics:

Transmission protocol: TCP, port number 179

BGP is an external routing protocol used to pass routing information between AS

is an enhanced path vector routing protocol

has a reliable routing update mechanism

has rich Metric (a metric standard) measurement methods

Loopless protocol design

is a routing entry with multiple attribute information

supports CIDR (that is, it supports subnet partition

rich routing filtering and routing strategies

No periodic update

Only incremental routes are sent

Periodically send KeepAlive (keep-alive) packets to maintain TCP connectivity

2. Working principle of BGP

BGP is a routing protocol across public networks and across AS (autonomous system), which can learn routing between AS. BGP's dynamic learning routing is also based on neighbors. BGP can work normally only if the neighbor relationship is normal.

01BGP neighbor relationship

The router running BGP is usually called a BGPSpeaker (speaker), and the speakers passing messages to each other are called peers (peers). The establishment, update and deletion of BGP neighbor relationships are completed through information such as 5 messages, 6 state machines and 5 tables between peers, and finally forming BGP neighbors.

(1) BGP message type and function: The type in the

BGP message header defines the BGP message type.BGP peers interact with routing information through five types of packets, including Open, Update, Notification, KeepAlive and Route-Refresh.

Open message: It is the first message sent after the TCP connection is established. It is used to establish the connection relationship between BGP peers, mainly including BGP version, local AS number, Holdtime (maintenance time) and other information.

update message: The update message is used to update routing information between BGP peers. The update message can advertise multiple accessible routing information with the same attributes, or revoke multiple unreachable routing information.

Notification message: When BGP detects an error state, the Notification message is immediately sent to the peer, and the BGP connection will be immediately interrupted. Regardless of the current state of BGP, the idle state will be returned as long as the Notification message is received.

Route-Refresh message: used to inform the peer of the refresh capability of the routes supported locally. When all BGP routers have Route-Refresh capabilities, if the BGP inlet routing policy changes, the local BGP router will send a Route-Refresh message to the peer. The peer receiving this message will resend its routing information to the local BGP router.

KeepAlive message: This message is sent periodically between peers to maintain the validity of the connection, similar to the hello packet in the OSPF protocol.

(2) BGP status:

BGP status describes the establishment process of BGP neighbors. There are six BGP statuses, namely Idle (idle), Connect (connect), Active (active), OpenSent (open send), OpenConfirm (open confirmation) and Established (established successfully).

Idle status: BGP rejects any incoming connection request, the Idle status is the initial state of BGP.

Connect status: In this state, BGP waits for the establishment of the TCP connection to be completed before deciding on subsequent operations.

Active status: In this state, BGP will try to establish a TCP connection, which is the intermediate state of BGP.

OpenSent status: In this state, BGP waits for the peer's Open message and checks the AS number, version number, Holdtime, etc. in the received Open message.

OpenConfirm status: In this state, BGP waits for KeepAlive or Notification packets.

Established state: In this state, BGP can exchange all messages between peers, which is also the normal working state of BGP.

During the process of establishing a BGP peer, the three usually visible states are Idle, Active, and Established. The status of both parties of the BGP peer must be established, so that the BGP neighbor relationship can be established, and both parties exchange routing information through Update messages.

(3) BGP database:

BGP database is the storage space required for BGP to work normally. According to the content saved, it can be divided into the following types:

IP routing table (IP-RIB): a global routing information database, including all the optimal IP routing information.

BGP routing table (Loc-RIB): BGP routing information library, including routing information advertised by local BGP Speaker, adds the optimal route to the IP routing table. Note: First, you should pay attention to the BGP routing table. If the BGP routing table is not the optimal route, it cannot be visible in the IP routing table.

neighbor table: a peer neighbor list list, including neighbor information at both ends of the peer, that is, a neighbor list.

Adi-RIB-In: The unprocessed routing information library declared by the peer to the local Speaker.

Adj-RIB-Out: The local Speaker declares to the routing information base of the specified peer.

(4) BGP neighbor relationship type:

can be roughly divided into two neighbor relationships in BGP: IBGP neighbor and EBGP neighbor.

IBGP: BGP neighbor relationship within the same AS. IBGP neighbor usually refers to the two ends of the peer running the BGP protocol are in the same AS domain and belonging to the same BGP AS.

EBGP: BGP neighbor relationship between AS. EBGP neighbor usually refers to the two ends of the peer running the BGP protocol in different ASs.The AS number of the

BGP neighbor is the same as the AS number of the local end, and the difference is the EBGP neighbor.

IGP (internal gateway protocol, such as OSPF) establishing neighbors generally requires direct connection between layer three devices and establishing neighbor relationships through broadcast or multicast. The neighbor relationship of BGP (external gateway protocol) is based on TCP, which means that as long as TCP/IP is accessible, BGP peers can establish neighbor relationships with each other regardless of whether they are directly connected. Therefore, the first thing BGP should consider before establishing a neighbor is that the path between peers is reachable (whether there is a route, it can be pinged). It is necessary to communicate between the two ends of the peer through IGP or static routing.

02 Method of advertised BGP routing

BGP routing is advertised through BGP commands, and there are two methods of advertised BGP routing: network and Import.

(1) network method:

Use the network command to publish the route (non-BGP) in the current device routing table to the BGP routing table and announce it to the neighbors. It is similar to the method of using the network command in OSPF, except that when BGP is announced, you only need to declare the network segment + mask number, such as: network 12.12.0.0 16.

(2) Import method:

Use the Import command to redistribute the routing information learned by the router to the BGP routing table. It is a way for BGP to declare routing. The routes that can be introduced include: direct connection routing, static routing and routes learned by dynamic routing protocols. Its command format is similar to redistribution of OSPF in RIP.

03BGP peer interaction principle

BGP device will add the optimal route to the BGP routing table to form a BGP route. After the BGP device establishes a neighbor relationship with the peer, the following interaction principle is adopted:

BGP route obtained from the IBGP peer, and the BGP device only passes it to its EBGP peer.

BGP route obtained from the EBGP peer, the BGP device passes it to all EBGP and IBGP peers (peer is IBGP only passes one hop, and peer is EBGP is not limited)

When there are multiple valid routes reaching the same destination address, the BGP device only publishes the optimal route to the peer

When there are multiple valid routes to the same destination address, the BGP device only publishes the optimal route to the peer

when the route is updated. The BGP device only sends the updated BGP route

all peers sent by all peers. The BGP device will receive the next hop during the delivery process. The next hop will be changed during the delivery process.

. All IBGP peers will not change during the delivery process (special attention is required)

. TTL value is 1 (special attention is required)

When passing the default IBGP The TTL value is 255

04 update source to establish neighbor relationship

To put it bluntly, when specifying a peer, use the other party's loopback port, because this interface is more stable than any physical interface. As long as the device is running, the loopback port will not be closed. As long as there is a link that can communicate with the other party's loopback address, it will not cause a change in the BGP state. If you use a physical interface, once this physical interface is down, then BGP is finished. Therefore, this method of using the loopback port to establish BGP neighbor is called the update source to establish neighbors. Usually, redundant link is used in the same AS to ensure the stability of BGP.(If you use the loopback address of the peer router in different ASs to establish a neighbor relationship, you need to change the TTL value on the two routers. For details, please refer to the configuration summary at the end of the blog post)

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

As in the figure above, the three routers are in the AS 100 area. If R1 and R3 want to use the update source to establish a neighbor relationship, then the configuration is as follows:

R1 router:

[R1]bgp 100

[R1-bgp]router-id 1.1.1.1

[R1-bgp]peer 3.3.3.3 as-number 100

[R1-bgp]peer 3.3.3.3 connect-interface LoopBack0

R3 router (refer to the configuration of R1 router for relevant command explanation):

[R3]bgp 100

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 1.1.1.1 as-number 100

[R3-bgp]peer 1.1.1.1 connect-interface LoopBack0

Note: local loopback interface must first make the peer reachable (that is, it can ping the other party's loopback address). You need to manually add the route entry of the peer loopback interface or use OSPF, RIP, etc. to automatically learn the route of the other party's loopback interface.

05 ensures that the next hop of IBGP can reach

BGP devices on the edge of the AS will receive the BGP routing information transmitted by its EBGP peer neighbor. As mentioned above: All EBGP peers change the next hop during the delivery process, while all IBGP peers remain unchanged during the delivery process. The previous figure will be intuitively explained: In the figure

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

, A-J is used instead of the router's interface IP address, and combined with the next hop of all EBGP peers during the transmission process, the next hop of all IBGP peers will not change during the transmission process. You can see what problems are in the figure (you can understand it yourself, it is in the late stage of lazy cancer, and I don't want to explain it). In the figure, the next hop in the router after the R3 router in the figure is wrong. The solution is to declare the next hop of R4 and R6 on the R3 and R5 routers as it is itself, and then you will find that the next hop address learned by R4 is E. The next jump that R6 learns is I. This only solves the problem that occurs when R1 declares routing. If R6 now announces another route, it is also necessary to declare the next hop for R3 and R1 on the R4 and R2 routers as it itself. This ensures that the next hop of IBGP is reachable.

configuration is as follows (take a router as an example. The explanation of the first three configuration commands can be referred to the comment above, mainly the last command to change the next hop of the route):

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 34.1.1.4 as-number 200

[R3-bgp]peer 34.1.1.4 as-number 200

[R3-bgp]peer 34.1.1.4 next-hop-local

06EBGP multi-hop

is easy to understand, because the TTL value between EBGP neighbors in the default BGP is 1, (TTL, the life cycle value of the packet, the value will be -1 every time a router passes through, and when the value is 0, the packet will be discarded). If the EBGP peer is not direct-connected (more than one router is required to communicate, and the TTL value is not enough), the TTL value limit will make the non-direct-connected peer unable to establish a neighbor relationship normally, so the EBGP multi-hop command needs to be used to solve the non-direct-connected neighbor relationship.As shown in the figure below, if EBGP multi-hop is not configured, then R1 and R3 will not be able to establish a neighbor relationship normally:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

Configure the R3 router multi-hop in the figure above (the R1 router also needs to perform a similar configuration, and then change the TTL value. Here we only take R3 as an example):

R3 Configuration is as follows:

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 12.0.0.1 as-number 100

[R3-bgp]peer 12.0.0.1 ebgp-max-hop 2 !-- indicates that the number of hops is 2, that is, TTL value is 2--

07 controls BGP routing

BGP protocol contains many routing attributes, these attributes can control BGP routing very flexibly. The attributes of

BGP are divided into four categories: arbitrary, optional transitions, and non-transitions. The following table is the attributes of BGP and the corresponding classification:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

(1) Public must-bearing: All BGP routers can recognize and must exist in the update message.


(2) Public arbitrary: All BGP routers can recognize it, but it does not require it to exist in the update message. You can decide whether to add it to the Update message according to the specific situation.


(3) Optional transition: The BGP router can choose whether to carry this attribute in the Update message. If the received router does not recognize this attribute, it can be forwarded to the neighbor router (this is what the transition means), which the neighbor router may recognize and use.


(4) Optional non-transition: The BGP router can choose whether to carry this attribute in the Update message. On the entire route published path, if some routers cannot recognize this property, it may cause the property to fail to work. Because if the received router does not recognize this attribute, it will discard this attribute and will no longer forward it to the neighbor router. Introduction to

BGP attributes:

BGP commonly used attributes include: Origin, AS-PATH, Next-Hop, Local-Perf and MED, etc.

(1) Origin attribute: It is a must-followed by public, used to define the source of path information, and its function is to mark how a route becomes a BGP route. It has the following three types:


IGP(I): The highest priority is, the route injected into the BGP routing table through the Network command, and its Origin property is IGP.


EGP(e): priority. The routing information obtained through EGP has the Origin attribute of EGP.


Incomplete(?): The lowest priority. Routing information learned through other ways. If BGP redistributes the routes introduced through the Import-route command, its Origin property is Incomplete. You can use the
display bgp routing-table command to view it and it will be displayed in the last column. The column name is Path/Ogn

(2) AS-PATH (AS path) attribute: This attribute records all AS numbers to pass through for a route from the local to the destination address in vector order. When accepting the route, if the device finds that there is this AS number in the AS-PATH list, it will not receive the route, thus avoiding the routing loop between AS.


If you see the AS number when viewing the BGP routing table, such as (100,200,300), it means that the routing entry has been propagated to the device through AS300, AS200 and AS100, where AS100 is the AS closest to this device.

(3) Next-Hop (next hop) attribute: It's back to the issue of ensuring that the next hop of IBGP can reach. Let's put it this way, the aforementioned guarantee that the next hop of IBGP can reach is to use the Next-Hop attribute, and it will not be explained.

(4) Local-Perf attribute: used to identify the priority of BGP routing, and is used to determine the optimal route when traffic leaves AS.When the BGP device obtains multiple routes with the same destination address but different next hops through different IBGP peers, a route with a higher priority Local-Perf attribute value will be selected. The Local-Perf attribute is only valid between IBGP peers and will not be advertised to other ASs. Local priority is passed inside the AS, and the higher the value, the more priority it is. The default priority is 100 and can be changed manually. Below is a configuration diagram I found online (you can use ACL to define some traffic, or you can directly modify the local priority. The following figure is based on ACL to set different priority levels for different network segments).

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

(5) MED attribute: used to judge the optimal route when traffic enters the neighbor AS. When a device running BGP obtains multiple routes with the same destination address but the next hop is different, under the same other conditions, the one with a smaller MED value will be selected as the best route to change the downstream route selection. The


MED attribute is only passed between two adjacent ASs, and the AS party receiving this attribute will no longer advertise it to any other third-party AS. The MED attribute can be configured manually, the default is 0. See the picture for the specific configuration:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

. The configuration on RT3 is as follows. You can control the routing of the two routers in AS200:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

08BGP's path selection principle

BGP The route selection principle
(1) If the next hop of the route to the destination network is unreachable, this route can be ignored
(2) Preferred-Value priority is the route with a high value
(3) Local-Preference priority is the route with a high value
(4) Aggregation route priority is higher than non-aggregated route
(5) Local manual aggregation route priority is higher than local automatic aggregation route
(6) Local route introduced through the Network command is higher than local route introduced through the Import-route command
(7) AS path with the shortest (minimum number) high priority is higher

(8) Comparison Origi n attribute, IGP priority is higher than EGP, EGP priority is higher than Incomplete
(9) Select the route with a smaller MED priority
(10) EBGP routing priority is higher than IBGP routing
(11) BGP priority is to select the path with low IGP metric
to BGP next hop
When all the above are the same, it is equivalent route and can be load-sharing (Note: AS-PATH must be consistent). When load-sharing, the following three principles are invalid

(12) Compare Cluster-List length, and shorter ones are preferred
(13) Compare Originator_ID (If there is no Originator_ID, use Router ID comparison), select the path with a smaller value
(14) and compare the IP address of the peer, select the path with the smallest IP address

3. BGP configuration example

The BGP theory above is so long-winded, but the real configuration is actually very simple (this also conforms to the characteristics of the network). Let’s configure it in an experimental diagram! network topology is as follows:

1. The concept of BGP BGP (Border Gateway Protocol) is a distance vector routing protocol. Unlike the traditional IGP protocol based on next hop, it is an AS (autonomous system) protocol. BGP belongs to the external gateway routing protocol, which solves the problem of routing be - DayDayNews

01 requirements are as follows

1, AS 200 uses the OSPF protocol internally to make AS 200 interoperable, and runs the BGP protocol on each router within AS 200 (R1 and R2 and R3 establish neighbor relationships, R4 and R2, R3 and R5 establish neighbor relationships,), and runs the BGP protocol between each AS.

2, using the BGP protocols in R1 and R5, respectively, declare 21.0.0.0/24 and 20.0.0.0/24, so that all routers can learn these two routing information.

3. Control the routing through the attributes of BGP to realize routing communication of PC 1→R1→R2→R4→R5→PC 2→R5→R4→R3→R2→R1→PC 1. By the way, test multiple control path selection methods.

4. Inject local OSPF routing information into the BGP protocol on R2, R3 and R4 routers respectively to enable the entire network to communicate (although the third requirement is to control routing, it does not mean that PC1 can ping any router, such as R2).

5. In order to introduce the EBGP multi-hop configuration, try R1 and R4 to directly establish a peer relationship.

02 Start configuring

1, configure the IP addresses of each PC, router physical interface and loopback interface by yourself (I am a late-stage patient with lazy cancer, please wait for it). The router IP configuration reference:

R1sys

[R1]in g0/0/0

[R1-GigabitEthernet0/0/0]ip add 12.1.1.1 24

[R1-GigabitEthernet0/0/0]int loop 0

[R1-LoopBack0]ip add 1.1.1.1 32

2. Configure the OSPF routing protocol internal to AS 200:

R2 router configuration is as follows:

[R2]ospf 1

[R2-ospf-1]area 0

[R2-ospf-1-area-0.0.0.0]net 2.2.2.2 0.0.0.0.0

[R2-ospf-1-area-0.0.0.0]net 12.1.1.0 0.0.0.255

[R2-ospf-1-area-0.0.0.0]net 24.1.1.0 0.0.0.255

R3 router configuration is as follows (refer to R2 for the corresponding comment):

[R3]ospf 1

[R3-ospf-1]area 0

[R3-ospf-1-area-0.0.0.0]ne 3.3.3.3 0.0.0.0

[R3-ospf-1-area-0.0.0.0]ne 13.1.1.0 0.0.0.255

[R3-ospf-1-area-0.0.0.0]ne 34.1.1.0 0.0.0.255

R4 router configuration is as follows (refer to R2 for the corresponding comment):

[R4]ospf 1

[R4-ospf-1]area 0

[R4-ospf-1-area-0.0.0.0]ne 4.4.4.4 0.0.0.0

[R4-ospf-1-area-0.0.0.0]ne 24.1.1.0 0.0.0.255

[R4-ospf-1-area-0.0.0.0.0]ne 34.1.1.0 0.0.0.255

3. Start configuring BGP so that the corresponding router is a neighbor relationship:

R1 is configured as follows:

[R1]bgp 100

[R1-bgp]router-id 1.1.1.1

[R1-bgp]peer 12.1.1.2 as 200

[R1-bgp]peer 13.1.1.3 as 200

[R1-bgp]network 21.0.0.0 24

Since there are many repetitive commands when configuring BGP, there is no particularly different configuration, so I won't write comments.

R2 configuration is as follows:

[R2]bgp 200

[R2-bgp]router-id 2.2.2.2

[R2-bgp]peer 12.1.1.1 as 100

[R2-bgp]peer 4.4.4.4 as 200

[R2-bgp]peer 4.4.4.4 connect-interface LoopBack 0

[R2-bgp]peer 4.4.4.4 next-hop-local

R3 configuration is as follows:

[R3]bgp 200

[R3-bgp]router-id 3.3.3.3

[R3-bgp]peer 13.1.1.1 as 100

[R3-bgp]peer 4.4.4.4 as 200

[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0

[R3-bgp]peer 4.4.4.4 next-hop-local

R4 configuration is as follows:

[R4]bgp 200

[R4-bgp]router-id 4.4.4.4

[R4-bgp]peer 2.2.2.2 as 200

[R4-bgp]peer 3.3.3.3 as 200

[R4-bgp]peer 2.2.2.2 next-hop-local

[R4-bgp]peer 2.2.2.2 connect-interface LoopBack 0

[R4-bgp]peer 3.3.3.3 connect-interface LoopBack 0

[R4-bgp]peer 45.1.1.5 as 300

R5 configuration is as follows:

[R5]bgp 300

[R5-bgp]router-id 5.5.5.5

[R5-bgp]peer 45.1.1.4 as 200

[R5-bgp]network 20.0.0.0 24

Now the neighbor relationship of BGP has been established, you can view it through the following command:

[R1]dis bgp peer
BGP local router ID: 1.1.1.1
Local AS number : 100
Total number of peers : 2 Peers in established state : 2
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
12.1.1.2 4 200 5 8 0 00:02:11 Established
1
13.1.1.3 4 200 7 10 0 00:04:34 Established
1

To this end, PC 1 can communicate with PC 2, of course it is done by the BGP protocol, but now, except for non-direct network segments and AS 200 internal routers, only PC1 and PC2 can communicate. For example, PC1 cannot ping the R2 router.

4. Start to make the third requirement, control the routing through the BGP attributes to realize routing communication of PC 1→R1→R2→R4→R5→PC 2→R5→R4→R3→R2→R1→PC 1.

First use the tracert command to view the routes when PC1 and PC2 communicate, and see which router they pass through.The router that

PC1 passes to PC5 is as follows:

PCtracert 20.0.0.1 #Use tracert command to view

traceroute to 20.0.0.1, 8 hops max

(ICMP), pressCtrl+Chtrl+Chtrl to to stop
1 21.0.0.254 1
ms 16 ms 15 ms
2 12.1.1.2 16
ms 15 ms 16 ms
3 24.1.1.4 31
ms 32 ms 31 ms
4 45.1.1.5 31
ms
47 ms 31 ms
5 *20.0.0.1 31
ms 32 ms

PC5 arrives at PC1 as follows:

PCtracert 21.0.0.1

tracerute to 21.0.0.1, 8 hops max

(ICMP), pressCtrl+Chtrl+Chtrl to to stop
1 20.0.0.254 15
ms 1 ms 16 ms
2 45.1.1.4 16
ms 31 ms 31 ms 31 ms 31 3ms 31 31 3ms 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 31 ms
4 12.1.1.1 47
ms 16 ms 47 ms
5 21.0.0.1 31
ms 31 ms 31 ms 31 ms 31 31 ms ms

Come on, start configuring the route selection problem (three methods can be implemented in total):

Implementation method 1: Modify the Local-Perf attribute to change the priority of the R3 router

Configuration on the R3 router is as follows:

[R3]route-policy lop permit node 10

Info: New Sequence of this List.

[R3-route-policy]apply local-preference 222

[R3-route-policy]quit

[R3]bgp 200

[R3-bgp]peer 4.4.4.4 route-policy lop exporttml3

[R3-bgp]quit

[R3]quitR3reset bgp all

At this time, check the router that PC5 arrives at PC1, and finds that it does not pass through R2 router, but passes through R3 router, as follows:

PCtracert 21.0.0.1

tracerute to 21.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+Chtrl to to stop

1 20.0.0.254 1 ms 16 ms 16 ms
2 45.1.1.4 15
ms 16 ms 31 ms
3 34.1.1.3 31
ms 32 ms 31 31 ms 31 34.1.1.3 31 ms 31 ms
4 13.1.1.1 47
ms 31 ms 47 ms
5 *21.0.0.1 47
ms 31 ms

Implementation method 2: Use the AS-PATH attribute to control the routing

In order to restore the initial effect of going R2, you need to clear the Local-Perf attribute configured by the R3 router in the previous step, and execute the following command in the R3 router to delete it:

[R3]bgp 200

[R3-bgp]undo peer 4.4.4.4 route-policy lop export

After deleting it, you can check it yourself after a while whether it has resumed the R2 router and not R3 when PC2 and PC1 are returned.

Then modify the AS-PATH attribute on the R2 router (that is, when the R2 router advertises the 21.0.0.0 network segment to the R4 router, it tells R4 that it has passed many areas. Of course, these areas are created, and the number of areas is definitely more than the number of areas that R3 passes, so R4 will choose to go R3 instead of R2 because it needs to take the optimal path):

R2 configuration is as follows:

[R2]route-policy as permit node 10

Info: New Sequence of this List.

[R2-route-policy]apply as-path 123 123 add

[R2-route-policy]quit

[R2]bgp 200

[R2-bgp]peer 4.4.4.4 route-policy as export

[R2-bgp]quit

[R2]quitR2reset bgp all

Now test it again on PC2, you will find that you have started to go to the R3 router again:

PCtracert 21.0.0.1

traceroute to 21.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+Chtrl to to stop

1 20.0.0.254 16 ms 1 ms 15 ms
2 45.1.1.4 32
ms 15 ms 31 ms
3 34.1.1.3 16
ms 32 ms
4 13.1.1.1 31
ms 31 ms 31 ms
5 *21.0.0.1 47
ms 31 31 ms

Implementation method 3: Use MED attributes to control the routing

. At the beginning, PC1 goes to PC5 and passes through the R2 router, not the R3 router. So now add the MED attributes of the R2 router and announce it to the R1 router, so that it passes through the R3 router instead of the R2 router.

[R2]route-policy med permit node 10

Info: New Sequence of this List.

[R2-route-policy]apply cost + 500

[R2-route-policy]quit

[R2]bgp 200

[R2-bgp]peer 12.1.1.1 route-policy med exporttml3

[R2-bgp]quit

[R2]quitR2reset bgp all

test on PC1:

PCtracert 20.0.0.1

tracerute 20.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+ChtrlChtrl to to stop

1 21.0.0.254 16 ms 1 ms 16 ms
2 13.1.1.3 15
ms
2 13.1.1.3 15
ms 16 ms 16 ms 16 ms 16 ms 16 ms 16 ms 16 ms
3 34.1.1.4 47
ms 16 ms 16 ms
4 45.1.1.5 31
ms
31 ms 31 ms
5 *20.0.0.1 32
ms 31 31 ms 31 ms

has been changed to the R3 router, indicating that the configuration is effective. It is not difficult to find through the implementation methods of these three route selections that BGP control route selection is mainly adjusted through the BGP attribute value. BGP contains a large number of attributes, and these attributes directly affect the selection of routes. All BGPs have stronger control capabilities than IGPs.

5, the fourth requirement: inject local OSPF routing information into the BGP protocol on R2, R3 and R4 routers respectively to enable the entire network to communicate.

R2 Router:

[R2]bgp 200
[R2-bgp]import-route ospf 1

R3:

[R3]bgp200[R3-bgp]import-route import-route ospf200[R3-bgp]import-route 2ospf200[R3-bgp]import-route 23ospf23200[R3-bgp]import-route 1

R4:

[R4]bgp 200[R4-bgp]import-route ospf 1

Click the router entries verification for each router! There are relevant viewing commands at the end of the article.

6, the fifth requirement: try R1 and R4 to directly establish a peer relationship.

R1 configuration is as follows:

[R1-bgp]bgp 100
[R1-bgp]peer 34.1.1.4 as 200
[R1-bgp]peer 34.1.1.4 ebgp-max-hop 2

R4 configuration is as follows:

[R4]bgp 200

[R4-bgp]peer 200

[R4-bgp]peer 13.1.1.1.1 as 100

[R4-bgp]peer 13.1.1.1 eb

[R4-bgp]peer 13.1.1.1 ebgp-max-hop 2

View verification (may need to wait a while before the neighbor is established successfully, the waiting time will not exceed two minutes)

[R1-bgp]dis bgp peer
BGP local router ID: 1.1.1.1
Local AS number: 100
Total number of peers: 3 Peers in established state: 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
12.1.1.2 4 200 27 38 0 00:17:49 Established
8
13.1.1.3 4 200 55 70 0 00:45:35 Established
8
34.1.1.4 4 200 12 13 0 00:00:02 Established
8

Related viewing command:

[R4]dis ip routing-table

[R4]dis ospf routing

[R4]dis bgp peer

[R1-bgp]dis bgp peer

4. Configuration summary

During the configuration process, you need to pay attention to the following points to avoid errors:

1. Before establishing a neighbor relationship and specifying the address of the peer router, be sure to ensure that the peer router can be pinged.

2. When establishing a BGP neighbor relationship within AS, it is best to specify the other party's Loopback address, but don't forget to update the source. Refer to the command: "[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0".

3. If there is more than one router running the BGP protocol within the AS, this is also the IBGP protocol within the AS. Don't forget to change the properties of the next hop, that is, the mentioned above, "ensure that the next hop of IBGP can reach" , the command reference: "[R4-bgp]peer 2.2.2.2 next-hop-local"

4. As mentioned earlier, if a neighbor relationship is established on two routers in different AS areas, even if the two routers are directly connected, its TTL value must be changed. The purpose is to allow the data packets used to establish neighbor relationships between the routers to pass through several more routers and then discarded.

Because although routers with different AS are directly connected, only one hop is enough, since the loopback address of the peer router is specified, the network segment of the loopback address must not be the same as the network segment directly connected to the router. After the router receives the packet, it treats it as the address on another router.

So when establishing a neighbor relationship between two ASs, you must change its hop number. If you establish a neighbor relationship between IBGP, you do not need to change the TTL value, because in IBGP, the TTL value of the data packet is default to 255. Reference command to change the TTL value: "[R1-bgp]peer 34.1.1.4 ebgp-max-hop 2"

The command needs to be skipped a few times and set the value to a few. It can be larger than the actual jump, but cannot be smaller than the actual jump.

Then modify the AS-PATH attribute on the R2 router (that is, when the R2 router advertises the 21.0.0.0 network segment to the R4 router, it tells R4 that it has passed many areas. Of course, these areas are created, and the number of areas is definitely more than the number of areas that R3 passes, so R4 will choose to go R3 instead of R2 because it needs to take the optimal path):

R2 configuration is as follows:

[R2]route-policy as permit node 10

Info: New Sequence of this List.

[R2-route-policy]apply as-path 123 123 add

[R2-route-policy]quit

[R2]bgp 200

[R2-bgp]peer 4.4.4.4 route-policy as export

[R2-bgp]quit

[R2]quitR2reset bgp all

Now test it again on PC2, you will find that you have started to go to the R3 router again:

PCtracert 21.0.0.1

traceroute to 21.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+Chtrl to to stop

1 20.0.0.254 16 ms 1 ms 15 ms
2 45.1.1.4 32
ms 15 ms 31 ms
3 34.1.1.3 16
ms 32 ms
4 13.1.1.1 31
ms 31 ms 31 ms
5 *21.0.0.1 47
ms 31 31 ms

Implementation method 3: Use MED attributes to control the routing

. At the beginning, PC1 goes to PC5 and passes through the R2 router, not the R3 router. So now add the MED attributes of the R2 router and announce it to the R1 router, so that it passes through the R3 router instead of the R2 router.

[R2]route-policy med permit node 10

Info: New Sequence of this List.

[R2-route-policy]apply cost + 500

[R2-route-policy]quit

[R2]bgp 200

[R2-bgp]peer 12.1.1.1 route-policy med exporttml3

[R2-bgp]quit

[R2]quitR2reset bgp all

test on PC1:

PCtracert 20.0.0.1

tracerute 20.0.0.1, 8 hops max

(ICMP), press Ctrl+Chtrl+ChtrlChtrl to to stop

1 21.0.0.254 16 ms 1 ms 16 ms
2 13.1.1.3 15
ms
2 13.1.1.3 15
ms 16 ms 16 ms 16 ms 16 ms 16 ms 16 ms 16 ms
3 34.1.1.4 47
ms 16 ms 16 ms
4 45.1.1.5 31
ms
31 ms 31 ms
5 *20.0.0.1 32
ms 31 31 ms 31 ms

has been changed to the R3 router, indicating that the configuration is effective. It is not difficult to find through the implementation methods of these three route selections that BGP control route selection is mainly adjusted through the BGP attribute value. BGP contains a large number of attributes, and these attributes directly affect the selection of routes. All BGPs have stronger control capabilities than IGPs.

5, the fourth requirement: inject local OSPF routing information into the BGP protocol on R2, R3 and R4 routers respectively to enable the entire network to communicate.

R2 Router:

[R2]bgp 200
[R2-bgp]import-route ospf 1

R3:

[R3]bgp200[R3-bgp]import-route import-route ospf200[R3-bgp]import-route 2ospf200[R3-bgp]import-route 23ospf23200[R3-bgp]import-route 1

R4:

[R4]bgp 200[R4-bgp]import-route ospf 1

Click the router entries verification for each router! There are relevant viewing commands at the end of the article.

6, the fifth requirement: try R1 and R4 to directly establish a peer relationship.

R1 configuration is as follows:

[R1-bgp]bgp 100
[R1-bgp]peer 34.1.1.4 as 200
[R1-bgp]peer 34.1.1.4 ebgp-max-hop 2

R4 configuration is as follows:

[R4]bgp 200

[R4-bgp]peer 200

[R4-bgp]peer 13.1.1.1.1 as 100

[R4-bgp]peer 13.1.1.1 eb

[R4-bgp]peer 13.1.1.1 ebgp-max-hop 2

View verification (may need to wait a while before the neighbor is established successfully, the waiting time will not exceed two minutes)

[R1-bgp]dis bgp peer
BGP local router ID: 1.1.1.1
Local AS number: 100
Total number of peers: 3 Peers in established state: 3
Peer V AS MsgRcvd MsgSent OutQ Up/Down State Pre
fRcv
12.1.1.2 4 200 27 38 0 00:17:49 Established
8
13.1.1.3 4 200 55 70 0 00:45:35 Established
8
34.1.1.4 4 200 12 13 0 00:00:02 Established
8

Related viewing command:

[R4]dis ip routing-table

[R4]dis ospf routing

[R4]dis bgp peer

[R1-bgp]dis bgp peer

4. Configuration summary

During the configuration process, you need to pay attention to the following points to avoid errors:

1. Before establishing a neighbor relationship and specifying the address of the peer router, be sure to ensure that the peer router can be pinged.

2. When establishing a BGP neighbor relationship within AS, it is best to specify the other party's Loopback address, but don't forget to update the source. Refer to the command: "[R3-bgp]peer 4.4.4.4 connect-interface LoopBack 0".

3. If there is more than one router running the BGP protocol within the AS, this is also the IBGP protocol within the AS. Don't forget to change the properties of the next hop, that is, the mentioned above, "ensure that the next hop of IBGP can reach" , the command reference: "[R4-bgp]peer 2.2.2.2 next-hop-local"

4. As mentioned earlier, if a neighbor relationship is established on two routers in different AS areas, even if the two routers are directly connected, its TTL value must be changed. The purpose is to allow the data packets used to establish neighbor relationships between the routers to pass through several more routers and then discarded.

Because although routers with different AS are directly connected, only one hop is enough, since the loopback address of the peer router is specified, the network segment of the loopback address must not be the same as the network segment directly connected to the router. After the router receives the packet, it treats it as the address on another router.

So when establishing a neighbor relationship between two ASs, you must change its hop number. If you establish a neighbor relationship between IBGP, you do not need to change the TTL value, because in IBGP, the TTL value of the data packet is default to 255. Reference command to change the TTL value: "[R1-bgp]peer 34.1.1.4 ebgp-max-hop 2"

The command needs to be skipped a few times and set the value to a few. It can be larger than the actual jump, but cannot be smaller than the actual jump.

hotcomm Category Latest News