自由路由软件ZEBRA基本配置完全攻略

来源:互联网 发布:multisim mac下载 编辑:程序博客网 时间:2024/04/28 01:07
前言

  Zebra是一个路由软件包,提供基于TCP/IP路由服务,支持RIPv1, RIPv2, RIPng, OSPFv2, OSPFv3, BGP- 4, 和 BGP-4+等众多路由协议。Zebra还支持BGP特性路由反射器(Route Reflector)。除了传统的 IPv4路由协议,Zebra也支持IPv6路由协议。如果运行的SNMP守护进程(需要ucd-snmp)支持SMUX协 议,Zebra还能支持路由协议MIBs。

  由以上可见,Zebra的确是一个很不错的路由系统,但比起真正的路由器就简直是小儿科,所以网络高手 就当这文章是小孩子过家家吧,而对于象我这样的初学者(特别是没有真实设备或足够设备进行实验) 也不失为一个学习和熟悉路由配置、路由协议的好工具。我没有实际的配置经验,对路由的技术细节也 不是十分清晰,完全是在扔破砖头。希望路由高手指正概念错误。

  安装

  Zebra目前最新的版本是0.92a,它的安装非常简单,我们只需从http://www.zebra.org/下载zebra- 0.92a.tar.gz,然后执行以下命令安装(本文环境是RedHat7.2):

  shell> tar xzf zebra-0.92a.tar.gz

  shell> cd zebra-0.92a

  shell> ./configure

  shell> make

  shell> make install

  这样Zebra就安装好了,安装的执行文件:

  shell> ls /usr/local/sbin

  bgpd

  ospfd

  ripd

  zebra

  配置文件:

  shell> ls /usr/local/etc

  bgpd.conf.sample

  ospfd.conf.sample

  zebra.conf.sample

  bgpd.conf.sample2

  ripd.conf.sample

  运行

  编译安装完Zebra后,可以看到有4个可执行文件和5个配置样本文件,我们就使用它的配置样本文件:

  shell> cd /usr/local/etc

  shell> cp zebra.conf.sample zebra.conf

  Zebra的各进程有各自的终端接口或VTY,如果我们需要给连接到它们的端口设置别名的话,在/etc/ services文件添加如下内容:

  zebrasrv

  2600/tcp

  # zebra service

  zebra

  2601/tcp

  # zebra vty

  ripd

  2602/tcp

  # RIPd vty

  ripngd

  2603/tcp

  # RIPngd vty

  ospfd

  2604/tcp

  # OSPFd vty

  bgpd

  2605/tcp

  # BGPd vty

  ospf6d

  2606/tcp

  # OSPF6d vty

  然后就可以启动Zebra了:

  shell> zebra -d

  这样,Zebra就以守护进程启动了,其它的参数请参考zebra -h。

  基本路由配置命令

  直接用telnet连接:

  shell> telnet localhost 2601

  Trying 127.0.0.1...

  Connected to localhost.

  Escape character is '^]'.

  Hello, this is zebra (version 0.92a).

  Copyright 1996-2001 Kunihiro Ishiguro.

  User Access Verification

  Password:

  Zebra会提示输入口令,我们通过/usr/local/etc/zebra.conf可以看到口令是zebra,enable口令也是zebra。

  输 入口令zebra,得到路由器用户模式提示符:

  Router>

  进入特权模式:

  Router> en

  Password:

  Router#

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

  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# sh run

  Current configuration:

  !

  hostname Router

  password zebra

  enable password zebra

  !

  interface lo

  !

  interface eth0

  !

  line vty

  !

  end

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

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

  Router# conf t

  Router(config)#

  自己取一个路由器名字:

  Router(config)# hostname r1

  r1(config)#

  Zebra比较简单,登陆口令不是在line下修改,而是直接在全局模式下用password修改r1(config)# password {password}

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

  r1# conf t

  r1(config)# enable password {password}

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

  r1(config)# service password-encryption

  回到特权模式:

  r1(config)# exit

  r1# sh run

  Current configuration:

  !

  hostname r1

  password 8 alA5.vcyMAwXQ

  enable password 8 ksbxOFN8xcFMc

  service password-encryption

  !

  interface lo

  !

  interface eth0

  !

  line vty

  !

  end

  我们看到刚才的明文密码都进行加密了,给我们的实验机也提高安全性。Zebra有一点比较恶心,如果我 们先设置了service password-encryption,然后再修改口令,sh run就发现口令又都是明文的了,但是由 于有service password-encryption,所以就无法登陆了。

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

  r1# conf t

  r1(config)# line vty

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

  设置日志记录,Zebra可以把日志记录到标准输出、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)# int lo

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

  r1(config-if)# exit

  r1(config)# int eth0

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

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

  保存我们刚才的配置:

  r1(config-if)# exit

  r1(config)# exit

  r1# copy run start

  Configuration saved to /usr/local/etc/zebra.conf

  r1#

  2、用Zebra做简单的RIP实验

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

  Zebra支持RIPv2,使用ripd程序实现RIP路由功能,但ripd程序需要在zebra程序读取接口信息,所以zebra 一定要在ripd之前启动。由于条件所限,下面的RIP实验是在两台单网卡的RedHat7.2下做的,所以只是 最简单的演示。

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

  shell_1> cd /usr/local/etc

  shell_1> cp zebra.conf.sample zebra.conf

  shell_1> cp ripd.conf.sample ripd.conf

  shell_1> zebra -d

  进入zebra设置IP

  shell_1> telnet localhost 2601

  Password:

  Router> en

  Password:

  Router# conf t

  Router(config)# hostname r1

  r1(config)# int eth0

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

  r1(config-if)# ctrl+z

  r1# copy run start

  进入第一台机器的rip设置

  shell_1> ripd -d

  shell_1> telnet localhost 2602

  Password:

  ripd> en

  ripd# conf t

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

  r1_ripd(config)# router rip !启动rip

  r1_ripd(config-rout


本文转自http://doc.linuxpk.com/40619.html