Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make BGP Router in CentOS

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to make a BGP router in CentOS". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn how to make a BGP router in CentOS.

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 set up BGP peers with other BGP routers.

Before we get into the details, some background knowledge of BGP is necessary. Border Gateway Protocol (BGP) is the actual standard of inter-domain routing protocols on the Internet. In BGP terminology, the global Internet is made up of thousands of associated autonomous systems (AS), each of which represents a network management domain provided by each particular operator. (it is said that former US President George. Bush has his own AS number.

In order for its network to be routed globally, every AS needs to know how to reach other AS on the Internet. At this point, BGP is needed to play this role. BGP is a language for AS to exchange routing information with neighboring AS. This routing information is often referred to as BGP lines or BGP prefixes. Includes the AS number (ASN; globally 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 on the Internet.

The ability to route between different domains (AS) 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 interior gateway protocols (IGPs) or intra-domain routing protocols, which are used to handle routing in a domain.

Test scheme

In this tutorial, let's use the following topology.

Let's assume that operator A wants to establish a BGP to peer-to-peer exchange routes with operator B. The details of their AS number and IP address space are as follows:

Operator A: ASN (100), IP address space (100.100.0.0plus 22), IP address assigned to the eth2 network card of the BGP router (100.100.1.1)

Operator B: ASN, IP address space (200.200.0.0swap 22), IP address assigned to the eth2 card of the BGP router (200.200.1.1)

Routers An and B use 100.100.0.0 / 30 subnets to connect to each other. In theory, any subnet is reachable and interconnected from the operator. In real scenarios, it is recommended to use a public network IP address space with a mask of 30 bits to achieve connectivity between operator An and operator B.

Install Quagga in CentOS

If Quagga is not already installed, we can use yum to install Quagga.

The code is as follows:

# yum install quagga

If you are using a CentOS7 system, you need to apply a policy to set up 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 code is as follows:

# setsebool-P zebra_write_config 1

The Quagga software suite contains several daemons that can work together. With regard to BGP routing, we will focus on establishing the following two daemons.

Zebra: a core daemon is used for kernel interfaces and static routing.

BGPd: a BGP daemon.

Configure logging

After Quagga is installed, the next step is to configure Zebra to manage the network interface of the BGP router. We start the first step by creating a Zebra configuration file and enabling logging.

The code is as follows:

# cp / usr/share/doc/quagga-XXXXX/zebra.conf.sample / etc/quagga/zebra.conf

In CentOS6 systems:

The code is as follows:

# service zebra start

# chkconfig zebra on

In CentOS7 systems:

The code is as follows:

# systemctl start zebra

# systemctl enable zebra

Quagga provides a unique command-line tool called vtysh that allows you to enter commands that are compatible and supported with router vendors such as Cisco and Juniper. We will use vtysh shell to configure BGP routing for the rest of the tutorial.

Start the vtysh shell command and enter:

The code is as follows:

# vtysh

The prompt will be changed to the hostname, which indicates that you are in vtysh shell.

The code is as follows:

Router-A#

Now we will configure the log file for Zebra using the following command:

The code is as follows:

Router-A# configure terminal

Router-A (config) # log file / var/log/quagga/quagga.log

Router-A (config) # exit

Permanently save the Zebra configuration:

The code is as follows:

Router-A# write

Perform the same steps on router B.

Configure peer IP address

Next, we will configure the peer IP address on the available interfaces.

The code is as follows:

Router-A# show interface # displays interface information

Interface eth0 is up, line protocol detection is disabled

. . . . .

Interface eth2 is up, line protocol detection is disabled

. . . . .

Configure the parameters of the eth0 interface:

The code is as follows:

Site-A-RTR# configure terminal

Site-A-RTR (config) # interface eth0

Site-A-RTR (config-if) # ip address 100.100.0.1 Universe 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 code is as follows:

Site-A-RTR (config) # interface eth2

Site-A-RTR (config-if) # ip address 100.100.1.1 Universe 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 code is as follows:

Router-A# show interface

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

Router-A# show interface description # displays the interface description

Interface Status Protocol Description

Eth0 up unknown "to Router-B"

Eth2 up unknown "test ip from provider A network"

If everything looks fine, don't forget to save the configuration.

The code is as follows:

Router-A# write

Similarly, repeat the configuration on router B.

Before we move on to the next step, make sure that each other's IP is ping accessible.

The code is as follows:

Router-A# ping 100.100.0.2

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

Next, we will continue to configure BGP peer and prefix settings.

Configure BGP Peer

The service that the Quagga daemon is responsible for BGP is called bgpd. First, let's prepare its configuration file.

The code is as follows:

# cp / usr/share/doc/quagga-XXXXXXX/bgpd.conf.sample / etc/quagga/bgpd.conf

In CentOS6 systems:

The code is as follows:

# service bgpd start

# chkconfig bgpd on

In CentOS7:

The code is as follows:

# systemctl start bgpd

# systemctl enable bgpd

Now, let's enter Quagga's shell.

The code is as follows:

# vtysh

As a first step, we want to confirm that there are currently no configured BGP sessions. In some versions, we may find a BGP session with AS number 7675. Since we don't need this session, we remove it.

The code is as follows:

Router-A# show running-config

.........

Router bgp 7675

Bgp router-id 200.200.1.1

.........

We will remove some preconfigured BGP sessions and establish the sessions we need to replace them.

The code is 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 provides a reference.

The code is 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 code is 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 show "Idle" or "Active'". Remember, the word 'Active'' always means bad in the router. It means that the router is actively looking for neighbors, prefixes, or routes. When the peer is up, the output status under "State/PfxRcd" will receive a prefix number from a special neighbor.

In the output of this example, the BGP peer is only in the up state between AS100 and AS200. So no prefix has been changed, so the value in the rightmost column is 0.

Configure prefix advertisement

As mentioned at the beginning, AS 100 will be advertised as 100.100.0.0 AS 22, and in our example as well as 200.200.0.0swap 22. These prefixes need to be added to the BGP configuration as follows.

In router-A:

The code is as follows:

Router-A# configure terminal

Router-A (config) # router bgp 100

Router-A (config) # network 100.100.0.0 Universe 22

Router-A (config) # exit

Router-A# write

In router-B:

The code is as follows:

Router-B# configure terminal

Router-B (config) # router bgp 200

Router-B (config) # network 200.200.0.0Universe 22

Router-B (config) # exit

Router-B# write

At this point, both routers start advertising prefixes as needed.

Test prefix advertisement

First, let's make sure that the number of prefixes has been changed.

The code is as follows:

Router-A# show ip bgp summary

To see more prefix details received, we can use the following command, which displays the total number of prefixes received by neighbor 100.100.0.2.

The code is as follows:

Router-A# show ip bgp neighbors 100.100.0.2 advertised-routes

See which prefix we received from our neighbors:

The code is as follows:

Router-A# show ip bgp neighbors 100.100.0.2 routes

We can also look at all the BGP routers:

The code is as follows:

Router-A# show ip bgp

All of the above commands can be used to check which router is learned in the router table through BGP.

The code is 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-Intermediate system to Intermediate system routing Protocol, B-Border Gateway Protocol, >-selective routing, *-FIB routing

The code is as follows:

C > * 100.100.0.0 30 is directly connected, eth0

C > * 100.100.1.0 is directly connected 24, eth2

B > * 200.200.0.0 via 22 [20 shock 0] 100.100.0.2, eth0, 00:06:45

Router-A# show ip route bgp

B > * 200.200.0.0 via 22 [20 shock 0] 100.100.0.2, eth0, 00:08:13

Routes learned by BGP will also appear in the Linux routing table.

The code is as follows:

[root@Router-A~] # ip route

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. As a result, ping will be successful.

The code is as follows:

[root@Router-A~] # ping 200.200.1.1-c 2

All in all, this tutorial focuses on how to run a basic BGP router on a CentOS system. This tutorial allows you to start learning about BGP configuration, more advanced settings such as setting filters, BGP property adjustments, local priorities, and pre-path preparation, which I will cover in subsequent tutorials.

Thank you for reading, the above is the content of "how to make a BGP router in CentOS". After the study of this article, I believe you have a deeper understanding of how to make a BGP router in CentOS, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report