Quagga 简介及Quagga使用基础谈用Quagga配置RIP路由协议

3600阅读 0评论2015-03-01 woaimaidong
分类:LINUX

Quagga 简介

什么是Quagga

  Quagga软件原名是Zebra是由一个日本开发团队编写的一个以GNU版权方式发布的软件。Quagga项目开始与1996年,当前版本是0.98.4版 可以使用Quagga将linux机器打造成一台功能完备的路由器。

Quagga支持的路由协议

  Quagga能够同时支持RIPv1、RIPv2、RIPng、OSPFv2、OSPFv3、BGP-4和 BGP-4+等诸多TCP/IP协议。其中:

  RIPv1、RIPv2、OSPFv2适用于Ipv4的自治域系统内部网络路由协议。

  BGP-4是用于Ipv4的自治域系统之间的外部网络路由协议。

  RIPng、OSPFv3、BGP-4+主要扩展对Ipv6的支持。

Quagga的特性

  模块化设计:Quagga基于模块化方案的设计,即对每一个路由协议使用单独的守护进程。

  运行速度快:因为使用了模块化的设计,使得Quagga的运行速度比一般的路由选择程序要快。

  可靠性高:在所有软件模块都失败的情况下,路由器可以继续保持连接并且daemons也会继续运行。故障诊断不必离线的状态下被诊断和更正

  支持Ipv6:Quagga不仅支持Ipv4,还支持Ipv6。

Quagga的运行机制

  由于Quagga采用模块化的设计,因此Quagga运行时要运行多个守护进程,包括ripd ripngd ospfd ospf6d bgpd 和Zebra。

  其中,Zebra守护进程用来更新内核的路由表,而其他的守护进程负责进行相应路由选择协议的路由更新。

Quagga的好处

  就路由器而论,虽然有各种硬件可用,但是费用较高。所以想到用一个运行Linux系统构件的功能丰富的路由器作为代替。Quagga路由守护程序已经使这一切变为现实。因为Quagga支持Ipv4、Ipv6和其他各式各样的协议,所以能够满足通常所有的路由需要。

  使用Quagga的另一个好处是,这个软件配置的很多方面跟Cisco的IOS配置几乎完全相同,如果你在Cisco IOS环境中工作,可以轻松的过渡到Quagga系统,同时,使用Quagga特能让你积累起丰富的类似于使用Cisco IOS路由器的经验和知识。

  总之,现在完全可以拿一台PC机来完成一些必须用昂贵的Cisco路由器才能完成的比较复杂的路由协议处理控制功能。

Quagga使用基础

1、 Quagga的安装与启动

Red Hat EL 3自带了Quagga,下面以RPM包的安装为例介绍Quagga的安装。若用户已经安装了Quagga则可跳过下面的安装步骤。


//将Red Hat EL3 的第一章光盘放入光驱然后挂载

cd /mnt/cdrom/Red Hat/RPMS

rpm –ivh quagga*

//程序将自动安装quagga-0.96.2-4.3E.i386.rpm软件包
 

用户也可以到网站自行下载最新版的软件源代码包安装。

2、 Quagga的配置文件

Quagga的配置文件均放在/etc/quagga目录下。

可以使用下面命令察看Quagga默认的配置文件:

 


# ll /etc/quagga

-rw-------    1 root     root          570 Nov 14  2003 bgpd.conf

-rw-------    1 root     root         1170 Nov 14  2003 ospf6d.conf

-rw-------    1 quagga   quagga        420 Aug  8 09:41 ospfd.conf

-rw-------    1 quagga   quagga        177 Aug  1 16:52 ripd.conf

-rw-------    1 quagga   quagga        439 Aug  1 14:29 zebra.conf

-rw-r-----    1 root     root            0 Jul 25  09:32 vtysh.conf
 

其中:vtysh.conf为配置Quagga所使用的shell的配置文件,zebra.conf是Quagga的主要配置文件。

Quagga对每钟路由选择协议有单独的配置文件:

RIP 所需的 ripd.conf

OSPF所需的ospf.conf

BGP所需的 bgp.conf

这些配置文件也存放在/etc/quagga目录下。

3、 Quagga的配置模式

下面列表说明Quagga的配置模式。

 


配置子模式
 

提示符
 

说明
 

 

Ineterface
 

Quagga(config-if)#
 

端口配置
 

 

Subinterface
 

Quagga(config-subif)#
 

子端口配置
 

 

Controller
 

Quagga(config-controller)#
 

控制器配置
 

 

Map-list
 

Quagga(config-map-list)#
 

影象表配置
 

 

Map-class
 

Quagga(config-map-class)#
 

影象类配置
 

 

Line
 

Quagga(config-line)#
 

线路配置
 

 

Router
 

Quagga(config-router)#
 

路由配置
 

 

Ipx router
 

Quagga(config-ipx-router)#
 

IPX路由配置
 

 

Router map
 

Quagga(config-router-map)#
 

路由影象配置
 

4.启动Quagga

   使用如下命令启动Quagga

 


//启动Quagga

# service zebra start

Starting zebra:                                        [  OK  ]
 

软件Quagga的总控制台启动了,管理端口号2601。

5.基本路由配置命令

直接用telnet连接:

 


# telnet localhost 2601

Trying 127.0.0.1...

Connected to vpntest.huatech.com (127.0.0.1).

Escape character is '^]'.

Hello, this is quagga (version 0.96.2).

Copyright 1996-2002 Kunihiro Ishiguro.

User Access Verification

Password:

Quagga会提示输入口令,我们通过/etc/quagga/zebra可以看到口令是zebra,enable口令也是zebra。输 入口令zebra,得到路由器用户模式提示符:

Router>

进入特权模式:

Router> enable

Password:

Router#

输入一个问号,看看Quagga提供了多少路由命令:

Router# ?

  configure  Configuration from vty interface

  copy       Copy configuration

  debug      Debugging functions (see also 'undebug')

  disable    Turn off privileged mode command

  end        End current mode and change to enable mode.

  exit       Exit current mode and down to previous mode

  help       Description of the interactive help system

  list       Print command list

  no         Negate a command or set its defaults

  quit       Exit current mode and down to previous mode

  show       Show running system information

  terminal   Set terminal line parameters

  who        Display who is on vty

  write      Write running configuration to memory, network, or terminal

察看一下当前的配置

Router# show running-config

Current configuration:

!

hostname Router

password zebra

enable password zebra

!

interface lo

!

interface eth0

!

interface eth1

!

line vty

!

end

Quagga把操作系统的网络接口当做路由器的接口,所以在做比较复杂的路由实验,会需要比较多的网卡。

进入全局模式,尽可能把实际可用的配置命令都实验一遍:

Router# configure terminal

Router(config)#

取一个路由器名字:

Router(config)# hostname r1

r1(config)#

Quagga比较简单,登陆口令不是在line下修改,而是直接在全局模式下用password修改

r1(config)# password {password}

Quagga不支持enable secret {password}这种MD5加密口令,只能使用enable password {password}来修改 enable口令:

r1# configure terminal

r1(config)# enable password {password}

在路由器配置中加密所有的口令:

r1(config)# service password-encryption

回到特权模式:

r1(config)# exit

r1# show running-config

Current configuration:

!

hostname r1

password 8 alA5.vcyMAwXQ

enable password 8 ksbxOFN8xcFMc

service password-encryption

!

interface lo

!

interface eth0

!

interface eth1

!

line vty

!

end

我们看到刚才的明文密码都进行加密了,给我们的实验机也提高安全性。Quagga有一点要值得注意,如果我 们先设置了service password-encryption,然后再修改口令,show running-config就发现口令又都是明文的了,但是由 于有service password-encryption,所以就无法登陆了。

去掉会话超时,免得10分钟没有动作,就把我们给踢了。但是在实际的路由器配置中,为安全起见我们 最好还是设上会话超时。

r1# conf t

r1(config)# line vty

r1(config-line)# exec-timeout 0 0

设置日志记录,Quagga可以把日志记录到标准输出、syslog、以及指定输出文件:

r1(config-line)# exit

r1(config)# log stdout

r1(config)# no log stdout

r1(config)# log syslog

r1(config)# no log syslog

r1(config)# log file /usr/local/etc/zebra.log

配置接口IP地址:

r1(config)# interface lo

r1(config-if)# ip address 127.0.0.1/8

r1(config-if)# exit

r1(config)# interface eth0

r1(config-if)# ip address 192.9.200.231/24

r1(config)# interface eth1

r1(config-if)# ip address 192.168.1.232/24

Quagga比较奇怪,不能使用ip address 192.9.200.179 255.255.255.0这种形式设置IP。测试一下,就设置成 和Linux中使用的一样。

保存我们刚才的配置:

r1(config-if)# exit

r1(config)# exit

r1# copy running-config startup-config

Configuration saved to /usr/quagga/zebra.conf

r1#
 

这样一个完整的Quagga自身的配置就完成了,希望读者在下面自己多多练习,熟悉基本命令。下面我们将要以RIP OSPF BGP协议为基础讲解具体的Quagga在网络中路由器的应用并以下图为网络环境

用Quagga配置RIP路由协议

RIP是应用较早、使用较普遍的IGP,适用于小型同类网络,是典型的距离向量(distance-vector)协 议。RIP通过广播UDP报文来交换路由信息,每30秒发送一次路由信息更新。RIP提供跳跃计数(hop count)作为尺度来衡量路由距离,跳跃计数是一个包到达目标所必须经过的路由器的数目。如果到相同 目标有二个不等速或不同带宽的路由器,但跳跃计数相同,则RIP认为两个路由是等距离的。RIP最多支 持的跳数为15,即在源和目的网间所要经过的最多路由器的数目为15,跳数16表示不可达。RIPv2支持 验证、密钥管理、路由汇总、无类域间路由(CIDR)和变长子网掩码(VLSMs)。

Quagga支持RIPv2,使用ripd程序实现RIP路由功能,但ripd程序需要在zebra程序读取接口信息,所以zebra 一定要在ripd之前启动。由于条件所限,下面的RIP实验是在两台双网卡的RedHat  El 3下做的,所以只是网络环境不复杂的情况下配置RIP.

按照上面基本配置的方法初始化第一台机器:

 


#  telnet localhost 2601

Password:

Router> enable

Password:

Router# configure terminal

Router(config)# hostname r1

r1(config)# interface eth0

r1(config-if)# ip address 192.9.200.179/24

r1(config-if)# ctrl+z

r1(config)# interface eth1

r1(config-if)# ip address 192.168.2.179/24

r1# copy run start

进入第一台机器的rip设置

# service ripd start

# telnet localhost 2602

Password:

ripd> enable

ripd# configure terminal

ripd(config)# hostname r1_ripd !改个名字好辨认

r1_ripd(config)# router rip !启动rip

r1_ripd(config-router)# network 192.9.200.0/24

!RIPv1是有类别路由协议,RIPv2是无类别路由协议,Quagga 默认支持RIPv2,指定网络需要子网掩码

r1的RIP简单配置这样就可用了,下面来检验一下:

ri_ripd#show ip rip status

Routing Protocol is "rip"

  Sending updates every 30 seconds with +/-50%, next due in 10 seconds

  Timeout after 180 seconds, garbage collect after 120 seconds

  Outgoing update filter list for all interface is not set

  Incoming update filter list for all interface is not set

  Default redistribution metric is 1

  Redistributing:

  Default version control: send version 2, receive any version

    Interface        Send  Recv   Key-chain

    eth1             2     1 2

  Routing for Networks:

    192.168.2.0/24

    192.9.200.179

  Routing Information Sources:

    Gateway          BadPackets BadRoutes  Distance Last Update

  Distance: (default is 120)

在shell下 用tail命令查看。

r1_ripd# debug rip events

r1_ripd# debug rip packet

r1_ripd(config)# log file /usr/local/etc/ripd.log

然后我们在shell下查看debug信息

# tail -f /usr/local/etc/ripd.log

--------------------------------8<---------------------------------------<>