How to make BGP routes in CentOS? Many novices are not very clear about this. To help you solve this problem, Micronet will explain it to you in detail below. Those who need it can learn from it. I hope you can get something.
Quagga is an open source routing software suite. In this tutorial, I will focus on how to turn a Linux system into a BGP router, or use Quagga to demonstrate how to establish BGP peer with other BGP routers.
Before entering into details, it is necessary to know some background knowledge of BGP. Border Gateway Protocol (BGP) is the actual standard of Internet inter domain routing protocol. In BGP terminology, the global Internet consists of thousands of related autonomous systems (as), each of which represents a network management domain provided by each specific operator (it is said that former US President George W. Bush has his own AS number).
In order to enable its network to route globally, each autonomous system needs to know how to reach other autonomous systems in the Internet. BGP is required to play this role at this time. BGP is a language for autonomous systems to exchange routing information with adjacent autonomous systems. These routing information are usually called BGP lines or BGP prefixes. Includes the AS number (ASN; worldwide unique number) and the associated IP address block. Once all BGP lines are learned and recorded by the local BGP routing table, each AS will know how to reach any public IP address of the Internet.
The routing capability between different domains is the main reason why BGP is called External Gateway Protocol (EGP) or Inter Domain Protocol. For example, some routing protocols, such as OSPF, IS-IS, RIP and EIGRP, are internal gateway protocols or intra domain routing protocols, which are used to handle the routing in the domain. Test plan
In this tutorial, let's use the following topology.
Let's assume that operator A wants to establish a BGP to communicate with the operator
Communicate
Peer to peer switching route of merchant b. The details of their access numbers and IP address spaces are as follows:
Operator A: ASN (100), IP address space (100.100.0.0/22), IP address (100.100.1.1) assigned to the eth2 network card of the BGP router
Operator B: ASN (200), IP address space (200.200.0.0/22), IP address (200.200.1.1) assigned to the eth2 network card of the BGP router
Router a and router b are connected to each other using 100.100.0.0/30 subnets. In theory, any subnet can be reached and interconnected from the operator. In the actual scenario, it is recommended to use the public IP address space with a mask of 30 bits to realize the communication between operator A and operator B Installing Quagga in CentOS
If Quagga has not been installed, we can use yum to install Quagga.
The codes are as follows:
# yum install quagga
If you are using CentOS7, you need to apply a policy to set SELinux. Otherwise, SELinux will prevent the Zebra daemon from writing to its configuration directory. If you are using CentOS6, you can skip this step.
The codes are as follows:
# setsebool-P zebra _ write _ config 1
The Quagga software suite contains several daemons that work together. For BGP routing, we will focus on establishing the following two daemons.
Zebra: It is the core daemon of the kernel interface and static routing.
BGPd: is a BGP daemon.
Configure Logging
After installing Quagga, the next step is to configure Zebra to manage the network interface of the BGP router. We started the first step by creating a zebra configuration file and enabling logging.
The codes are as follows:
# CP/usr/share/doc/quagga-XXXXXX/zebra . conf . sample/etc/quagga/zebra . conf
In CentOS6:
The codes are as follows:
#Service zebra starts
#Chkconfig Zebra On
In CentOS7,
The codes are as follows:
#Systemctl starts zebra
#Systemctl Enable Zebra
Quagga provides a unique command line tool called vtysh that allows you to enter commands that are compatible with and supported by router vendors such as Cisco and Juniper. We will use the vtysh shell to configure BGP routing in the rest of this tutorial.
To start the vtysh shell command, enter:
The codes are as follows:
# vtysh
The prompt will be changed to the hostname, which indicates that you are in the vtysh shell.
The codes are as follows:
Recurrent oral ulcer
ter-A# Now we will use the following command to configure the log file for Zebra:
The codes are as follows:
Router-A# configure terminal
Router-A(config)# log file /var/log/quagga/quagga.log
Router-A(config)# exit
Permanently save Zebra configuration:
The codes are as follows:
Router-A# write
Follow the same steps in Router B.
Configure peer IP address
Next, we will configure the peer IP address on the available interface.
The codes are as follows:
Router-A # show interface # Display interface information</p> <p> Interface eth0 is up, line protocol detection is disabled
. . . . .
Interface eth2 is up, line protocol detection is disabled
. . . . .
Configure the parameters of eth0 interface:
The codes are as follows:
site-A-RTR# configure terminal
site-A-RTR(config)# interface eth0
site-A-RTR(config-if)# ip address 100.100.0.1/30
site-A-RTR(config-if)# description "to Router-B"
site-A-RTR(config-if)# no shutdown
site-A-RTR(config-if)# exit
Continue to configure the parameters of the eth2 interface:
The codes are as follows:
site-A-RTR(config)# interface eth2
site-A-RTR(config-if)# ip address 100.100.1.1/24
site-A-RTR(config-if)# description "test ip from provider A network"
site-A-RTR(config-if)# no shutdown
site-A-RTR(config-if)# exit
Now confirm the configuration:
The codes are as follows:
Router-A# show interface </p> <p> Interface eth0 is up, line protocol detection is disabled
Description: "to Router-B"
inet 100.100.0.1/30 broadcast 100.100.0.3
Interface eth2 is up, line protocol detection is disabled
Description: "test ip from provider A network"
inet 100.100.1.1/24 broadcast 100.100.1.255</p> <p>Router-A # show interface description # Display interface description</p> <p> Interface Status Protocol Description
eth0 up unknown "to Router-B"
eth2 up unknown "test ip from provider A network"
If everything looks normal, don't forget to save the configuration.
The codes are as follows:
Router-A# write
Similarly, repeat the configuration at router B.
Before we continue, confirm that the IP addresses of each other can be pinged.
The codes are as follows:
Router-A# ping 100.100.0.2 </p> <p> PING 100.100.0.2 (100.100.0.2) 56(84) bytes of data.
64 bytes from 100.100.0.2: icmp_seq=1 ttl=64 time=0.616 ms
Configure BGP peer
The service that the Quagga daemon is responsible for BGP is called bgpd. First, we will prepare its configuration file.
The codes are as follows:
# cp /usr/share/doc/quagga-XXXXXXX/bgpd.conf.sample /etc/quagga/bgpd.conf
In CentOS6:
The codes are as follows:
# service bgpd start
# chkconfig bgpd on
In CentOS7:
The codes are as follows:
# systemctl start bgpd
# systemctl enable bgpd
Now, let's enter Quagga's shell.
The codes are as follows:
# vtysh
The first step is to confirm that there is no BGP session configured. In some versions, we may find a BGP session with AS number 7675. Since we don't need this session, we remove it.
The codes are as follows:
Router-A# show running-config </p> <p> ... ... ...
router bgp 7675
bgp router-id 200.200.1.1
... ... ...
We will remove some preconfigured BGP sessions and establish the sessions we need instead.
The codes are as follows:
Router-A# configure terminal
Router-A(config)# no router bgp 7675
Router-A(config)# router bgp 100
Router-A(config)# no auto-summary
Router-A(config)# no synchronizaiton
Router-A(config-router)# neighbor 100.100.0.2 remote-as 200
Router-A(config-router)# neighbor 100.100.0.2 description "provider B"
Router-A(config-router)# exit
Router-A(config)# exit
Router-A# write
Router B will be configured in the same way, and the following configuration is provided as a reference.
The codes are as follows:
Router-B# configure terminal
Router-B(config)# no router bgp 7675
Router-B(config)# router bgp 200
Router-B(config)# no auto-summary
Router-B(config)# no synchronizaiton
Router-B(config-router)# neighbor 100.100.0.1 remote-as 100
Router-B(config-router)# neighbor 100.100.0.1 description "provider A"
Router-B(config-router)# exit
Router-B(config)# exit
Router-B# write
When the relevant routers are configured, the peer between the two routers will be established. Now let's confirm by running the following command:
The codes are as follows:
Router-A# show ip bgp summary

From the output, we can see the "State/PfxRcd" section. If the peer is turned off, the output will display "Idle" or "Active". Remember that the word "Active" always has a bad meaning in the router. It means that the router is actively looking for neighbors, prefixes or routes. When the peer is in the up state, the output state under "State/PfxRcd" will receive a prefix number from the special neighbor.
In the output of this example, the BGP peer is only up between AS100 and AS200. Therefore, no prefix has been changed, so the value of the rightmost column is 0.
Configure prefix advertisements
As mentioned at the beginning, AS 100 will take 100.100.0.0/22 as the announcement, and in our example, AS 200 will also take 200.200.0.0/22 as the announcement. These prefixes need to be added to the BGP configuration as follows.
In Router-A:
The codes are as follows:
Router-A# configure terminal
Router-A(config)# router bgp 100
Router-A(config)# network 100.100.0.0/22
Router-A(config)# exit
Router-A# write
In Router-B:
The codes are as follows:
Router-B# configure terminal
Router-B(config)# router bgp 200
Router-B(config)# network 200.200.0.0/22
Router-B(config)# exit
Router-B# write
At this point, the two routers will start to advertise prefixes as needed.
Test prefix notification
First, let's confirm whether the number of prefixes has been changed.
The codes are as follows:
Router-A# show ip bgp summary

To view more prefix details received, we can use the following command, which is used to display the total number of prefixes received by neighbors 100.100.0.2.
The codes are as follows:
Router-A# show ip bgp neighbors 100.100.0.2 advertised-routes

Check which prefix we received from our neighbor:
The codes are as follows:
Router-A# show ip bgp neighbors 100.100.0.2 routes

We can also view all BGP routers:
The codes are as follows:
Router-A# show ip bgp

The above commands can be used to check which router is learned in the router table through BGP.
The codes are as follows:
Router-A# show ip route
Code: K - kernel routing, C - linked, S - static, R - routing information protocol, O - open shortest path first protocol,
I - routing protocol from the intermediate system to the intermediate system, B - border gateway protocol,>- routing, * - FIB routing
The codes are as follows:
C>* 100.100.0.0/30 is directly connected, eth0
C>* 100.100.1.0/24 is directly connected, eth2
B>* 200.200.0.0/22 [20/0] via 100.100.0.2, eth0, 00:06:45</p> <p align="left"> Router-A# show ip route bgp </p> <p align="left"> B>* 200.200.0.0/22 [20/0] via 100.100.0.2, eth0, 00:08:13
The routes learned by BGP will also appear in the Linux routing table.
The codes are as follows:
[ root@Router-A ~]# ip route </p> <p> 100.100.0.0/30 dev eth0 proto kernel scope link src 100.100.0.1
100.100.1.0/24 dev eth2 proto kernel scope link src 100.100.1.1
200.200.0.0/22 via 100.100.0.2 dev eth0 proto zebra
Finally, we will use the ping command to test connectivity. The result will be successful pinging.
The codes are as follows:
[ root@Router-A ~]# ping 200.200.1.1 -c 2
In summary, this tutorial will focus on how to run a basic BGP router in the CentOS system. This tutorial allows you to learn about BGP configuration. Some more advanced settings, such as setting filters, BGP attribute adjustment, local priority and pre path preparation, will be covered in the following tutorials.
Is it helpful for you to read the above contents? If you want to further understand relevant knowledge or read more relevant articles, please follow the Yisu Cloud industry information channel, and thank you for your support for Yisu Cloud.