search
HomeSystem TutorialLINUXTurn your CentOS into an OSPF router

Turn your CentOS into an OSPF router

Jan 10, 2024 am 09:10 AM
linuxlinux tutorialRed Hatlinux systemlinux commandlinux certificationred hat linuxlinux video

Introduction Quagga is an open source routing software suite that turns Linux into a router that supports major routing protocols such as RIP, OSPF, BGP and IS-IS. It has full support for IPv4 and IPv6 and supports route/prefix filtering. Quagga can be a lifesaver in case your production router ever goes down and you don't have a spare but are waiting for a replacement. With proper configuration, Quagga can even function as a production router.

将你的 CentOS 变成 OSPF 路由器

In this tutorial, we will connect two branch office networks assuming there is a dedicated line connection between them (for example, 192.168.1.0/24 and 172.17.1.0/24).

将你的 CentOS 变成 OSPF 路由器

Our CentOS is on both ends of said private link. The two host names are set to "site-A-RTR" and "site-B-RTR' respectively. The following are the details of the IP addresses.
•Site-A: 192.168.1.0/24
•Site-B: 172.16.1.0/24
•Peer-to-peer network between two Linux routers: 10.10.10.0/30

Quagga includes several daemons that work together. In this tutorial, we will focus on setting up the following daemons.
1.Zebra: Core daemon, responsible for kernel interface and static routing.
2.Ospfd: IPv4 OSPF daemon.

Installing Quagga on CentOS

We use yum to install Quagga.

# yum install quagga

In CentOS7, SELinux will prevent quagga from writing configuration files to /usr/sbin/zebra by default. This SELinux policy will interfere with the installation process we will introduce next, so we need to disable this policy. For this, either turning off SELinux (not recommended here) or enabling "zebrawriteconfig" as follows will work. If you are using CentOS 6 please skip this step.

# setsebool -P zebra_write_config 1

If this modification is not made, we will see the following error when we try to save the configuration in the Quagga command line.

Can't open configuration file /etc/quagga/zebra.conf.OS1Uu5.

After installing Quagga, we need to configure the necessary peer IP addresses and update OSPF settings. Quagga comes with a command line called vtysh. The Quagga commands used in vtysh are similar to those of major router manufacturers such as Cisco and Juniper.

Step 1: Configure Zebra

We first create the Zebra configuration file and enable the Zebra daemon.

# cp /usr/share/doc/quagga-XXXXX/zebra.conf.sample /etc/quagga/zebra.conf
# service zebra start
# chkconfig zebra on 

Start vtysh command line:

#vtysh

First, we configure the log file for Zebra. Enter the following command to enter the global configuration mode of vtysh:

site-A-RTR# configure terminal

Specify the log file location, then exit the mode:

site-A-RTR(config)# log file /var/log/quagga/quagga.log
site-A-RTR(config)# exit

Save configuration permanently:

site-A-RTR# write

Next, we need to identify the available interfaces and configure their IP addresses as needed.

site-A-RTR# show interface
Interface eth0 is up, line protocol detection is disabled
. . . . .
Interface eth1 is up, line protocol detection is disabled
. . . . .

Configure eth0 parameters:

site-A-RTR# configure terminal
site-A-RTR(config)# interface eth0
site-A-RTR(config-if)# ip address 10.10.10.1/30
site-A-RTR(config-if)# description to-site-B
site-A-RTR(config-if)# no shutdown

Continue to configure eth1 parameters:

site-A-RTR(config)# interface eth1
site-A-RTR(config-if)# ip address 192.168.1.1/24
site-A-RTR(config-if)# description to-site-A-LAN
site-A-RTR(config-if)# no shutdown

Now verify the configuration:

site-A-RTR(config-if)# do show interface
Interface eth0 is up, line protocol detection is disabled
. . . . .
  inet 10.10.10.1/30 broadcast 10.10.10.3
. . . . .
Interface eth1 is up, line protocol detection is disabled
. . . . .
  inet 192.168.1.1/24 broadcast 192.168.1.255
. . . . .
site-A-RTR(config-if)# do show interface description
Interface      Status  Protocol  Description
eth0           up      unknown   to-site-B
eth1           up      unknown   to-site-A-LAN

Save configuration permanently:

site-A-RTR(config-if)# do write

Repeat the above steps to configure the IP address on site-B.

If all goes well, you should be able to ping the peer IP address 10.10.10.2 on site-B from site-A's server.

Note: Once the Zebra daemon is started, any changes in the vtysh command line will take effect immediately. Therefore there is no need to restart the Zebra daemon after changing the configuration.

Step 2: Configure OSPF

We first create the OSPF configuration file and start the OSPF daemon:

# cp /usr/share/doc/quagga-XXXXX/ospfd.conf.sample /etc/quagga/ospfd.conf
# service ospfd start
# chkconfig ospfd on

Now start the vtysh command line to continue OSPF configuration:

# vtysh

Enter routing configuration mode:

site-A-RTR# configure terminal
site-A-RTR(config)# router ospf

Optional configuration routing id:

site-A-RTR(config-router)# router-id 10.10.10.1

Network added in OSPF:

site-A-RTR(config-router)# network 10.10.10.0/30 area 0
site-A-RTR(config-router)# network 192.168.1.0/24 area 0

Save configuration permanently:

site-A-RTR(config-router)# do write

Repeat OSPF configuration similar to above on site-B:

site-B-RTR(config-router)# network 10.10.10.0/30 area 0
site-B-RTR(config-router)# network 172.16.1.0/24 area 0
site-B-RTR(config-router)# do write

The OSPF neighbor should now be started. As long as ospfd is running, any OSPF-related configuration changes made through vtysh will take effect immediately without restarting ospfd.

verify

1. Pass ping test

First you should be able to ping the same LAN subnet as site-B from site-A. Make sure your firewall is not blocking ping traffic.

[root@site-A-RTR ~]# ping 172.16.1.1 -c 2

2. Check routing table

The necessary routes should appear in both the kernel and Quagga reason tables.

[root@site-A-RTR ~]# ip route
10.10.10.0/30 dev eth0  proto kernel  scope link  src 10.10.10.1
172.16.1.0/30 via 10.10.10.2 dev eth0  proto zebra  metric 20
192.168.1.0/24 dev eth1  proto kernel  scope link  src 192.168.1.1
[root@site-A-RTR ~]# vtysh
site-A-RTR# show ip route
Codes: K - kernel route, C - connected, S - static, R - RIP, O - OSPF,
      I - ISIS, B - BGP, > - selected route, * - FIB route
 
O>* 10.10.10.0/30 [110/10] is directly connected, eth0, 00:14:29
C>* 10.10.10.0/30 is directly connected, eth0
C>* 127.0.0.0/8 is directly connected, lo
O>* 172.16.1.0/30 [110/20] via 10.10.10.2, eth0, 00:14:14
C>* 192.168.1.0/24 is directly connected, eth1

3. Verify OSPF neighbors and routes

In the vtysh command line, you can check whether the necessary neighbors are online and whether appropriate routes have been learned.

[root@site-A-RTR ~]# vtysh
site-A-RTR# show ip ospf neighbor

In this tutorial, we will focus on configuring basic OSPF using Quagga. In general, Quagga allows us to easily configure dynamic routing protocols such as OSPF, RIP or BGP on an ordinary Linux machine. Quagga-enabled machines can communicate and exchange routing information with other routers on your network. Because it supports the major open standard routing protocols, it may be the first choice in many situations. What's more, Quagga's command line interface is nearly identical to that of major router vendors such as Cisco and Juniper, which makes deploying and maintaining Quagga machines very easy.


The above is the detailed content of Turn your CentOS into an OSPF router. For more information, please follow other related articles on the PHP Chinese website!

Statement
This article is reproduced at:Linux就该这么学. If there is any infringement, please contact admin@php.cn delete
How to Install and Run FreeDOS on Linux Using QEMUHow to Install and Run FreeDOS on Linux Using QEMUApr 29, 2025 am 10:36 AM

This guide shows you how to set up the free and open-source DOS-compatible operating system, FreeDOS, within a Linux environment using the QEMU emulator. This allows you to run legacy DOS software and games on modern hardware without needing a separ

How to Install KDE Plasma on Linux Mint 22How to Install KDE Plasma on Linux Mint 22Apr 29, 2025 am 10:10 AM

Linux Mint, an operating system known for its simplicity, stability and ease of use, is popular with users and is especially suitable for beginners. It uses the Cinnamon desktop environment by default, providing a simple and friendly user interface. But if you prefer a different look or need more customization options, you can install other desktop environments such as KDE Plasma. KDE Plasma is a feature-rich, highly customizable and visually excellent desktop environment that provides a modern and stylish user experience. It has a wide range of customization options, advanced window management capabilities and sophisticated aesthetics, perfect for users who want to have a better control over the desktop experience. This guide will guide you step by step to install KDE Pl on Linux Mint 22

How to Reduce High RAM & CPU Usage on LinuxHow to Reduce High RAM & CPU Usage on LinuxApr 29, 2025 am 10:05 AM

Linux system performance optimization: Reduce RAM and CPU usage Linux systems are powerful and efficient, but high RAM and CPU usage can reduce performance, slow down applications, and even cause servers, workstations, or embedded systems to crash. Therefore, optimizing resource usage is crucial for the smooth operation of the system. This guide will explore practical ways to reduce RAM and CPU usage in Linux systems, covering monitoring tools, process management, kernel tuning and system optimization technologies to help you keep your system running efficiently. Identify resource-intensive processes The first step in reducing RAM and CPU usage is to identify which processes consume the most resources. To do this, you can use the following command-line tools: a. Use top

How to Boot Into Single User Mode in AlmaLinux 8/9How to Boot Into Single User Mode in AlmaLinux 8/9Apr 29, 2025 am 09:46 AM

Single User Mode (also known as Rescue Mode) Guide for AlmaLinux 8 and 9 Single-user mode is a streamlined Linux environment that allows system administrators to perform maintenance tasks, troubleshoot problems, and recover from system failures. Single-user mode is especially useful when you need to reset your root password, fix configuration errors, fix corrupt file systems, or investigate system errors that prevent normal startup. As RHEL-based distributions, AlmaLinux 8 and 9 provide an easy way to enter single-user mode via the GRUB boot loader. This guide will explain step by step how to enter single-user mode on AlmaLinux 8 and 9. What is single use

Linux Troubleshooting: 5 Common Problems & How to Fix ThemLinux Troubleshooting: 5 Common Problems & How to Fix ThemApr 29, 2025 am 09:42 AM

Linux systems are known for their power and reliability, but even experienced users will encounter unexpected problems. Whether it is an unexpectedly deleted file, a forgotten root password, or a slow system running, efficient troubleshooting skills are the key to becoming a Linux expert. This guide will introduce common Linux problem solving scenarios and step-by-step solutions that are common among system administrators, developers, and everyday Linux users. Scene 1: Unexpected deletion of important files You accidentally deleted an important file using the rm command and now you need to restore it. Unlike Windows and macOS, Linux does not have a built-in "recycle bin" to store files deleted from the terminal. Recovery options depend on

How to Permanently Change Docker Folder Permissions on LinuxHow to Permanently Change Docker Folder Permissions on LinuxApr 29, 2025 am 09:35 AM

Docker is a powerful tool that allows you to run applications in an isolated environment called containers. However, sometimes you may need to change the permissions of the Docker folder to ensure that your application has access to the necessary files and directories. This article will guide you through the process of permanently changing Docker folder permissions on Linux systems. Understand Docker folder permissions By default, Docker stores its data, including images, containers, and volumes, in specific directories on Linux systems. The most common directory is /var/lib/docker. The permissions of these folders determine who can read, write, or execute the files in it. if

Manage Docker Like a Pro: Install Portainer CE on LinuxManage Docker Like a Pro: Install Portainer CE on LinuxApr 29, 2025 am 09:24 AM

Simplify Docker Management with Portainer CE on Linux: A Step-by-Step Guide Managing Docker containers via the command line can be daunting, especially for newcomers. Portainer CE (Community Edition) offers a free, lightweight, and intuitive solutio

How to Use Whisper AI for Live Audio Transcription on LinuxHow to Use Whisper AI for Live Audio Transcription on LinuxApr 29, 2025 am 09:18 AM

This guide details how to install and use Whisper AI for real-time speech-to-text transcription on Linux systems. Whisper AI, an OpenAI creation, offers high-accuracy transcription across multiple languages. While primarily designed for batch proces

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),