Zebra基本配置

前言

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-router)# network 192.168.5.0/24 !RIPv1是有類別路由協議,RIPv2是無類別路由協議,

Zebra 默認支持RIPv2,指定網絡需要子網掩碼。

r1的RIP簡單配置這樣就可用了,下面來檢驗一下:

r1_ripd# sh ip protocols
Routing Protocol is "rip"
  Sending updates every 30 seconds with +/-50%, next due in 3 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 version 2
    Interface        Send  Recv   Key-chain
    eth0             2     2
  Routing for Networks:
    192.168.5.0/24
  Routing Information Sources:
    Gateway          BadPackets BadRoutes  Distance Last Update
  Distance: (default is 120)

我們看到RIP已經起來了,是RIPv2。

r1_ripd# sh ip rip
Codes: R - RIP, C - connected, O - OSPF, B - BGP

   Network            Next Hop         Metric From            Time

由於就兩個接口直連,沒有其它網絡,所以sh ip rip看不到什麼。

Zebra對log處理可能有些問題,使用log stdout不能顯示各種debug信息,所以只能記錄到文件,在shell下 用

tail命令查看。

r1_ripd# debug rip events
r1_ripd# debug rip packet
r1_ripd(config)# log file /usr/local/etc/ripd.log

然後我們在shell下查看debug信息

shell_1> tail -f /usr/local/etc/ripd.log
--------------------------------8<---------------------------------------
2002/04/28 22:17:44 RIP: update timer fire!
2002/04/28 22:17:44 RIP: SEND UPDATE to eth0 ifindex 2
2002/04/28 22:17:44 RIP: multicast announce on eth0
2002/04/28 22:17:44 RIP: update routes on interface eth0 ifindex 2
2002/04/28 22:18:23 RIP: update timer fire!
2002/04/28 22:18:23 RIP: SEND UPDATE to eth0 ifindex 2
2002/04/28 22:18:23 RIP: multicast announce on eth0
2002/04/28 22:18:23 RIP: update routes on interface eth0 ifindex 2
2002/04/28 22:19:04 RIP: update timer fire!
2002/04/28 22:19:04 RIP: SEND UPDATE to eth0 ifindex 2
2002/04/28 22:19:04 RIP: multicast announce on eth0
2002/04/28 22:19:04 RIP: update routes on interface eth0 ifindex 2
--------------------------------8<---------------------------------------

RIP每隔30秒發送一次更新,在sh ip prot可以看到Sending updates every 30 seconds with +/-50%

第二臺機器的設置

前面的初始化和第一臺一樣,不過這裏名字設成r2便於辨認,IP設成了192.168.5.123/24。

進入第二臺機器的rip設置

shell_2> ripd -d
shell_2> telnet localhost 2602
Password:
ripd> en
ripd# conf t
ripd(config)# hostname r2_ripd
r2_ripd(config)# router rip
r2_ripd(config-router)# network 192.168.5.0/24

執行完network命令,我們看到第一臺機器的tail -f /usr/local/etc/ripd.log輸出下面的信息:

--------------------------------8<---------------------------------------
2002/04/28 22:19:15 RIP: RECV packet from 192.168.5.123 port 520 on eth0
2002/04/28 22:19:15 RIP: RECV REQUEST version 2 packet size 24
2002/04/28 22:19:15 RIP:   0.0.0.0/0 -> 0.0.0.0 family 0 tag 0 metric 16
2002/04/28 22:19:15 RIP: update routes to neighbor 192.168.5.123
2002/04/28 22:19:35 RIP: update timer fire!
2002/04/28 22:19:35 RIP: SEND UPDATE to eth0 ifindex 2
2002/04/28 22:19:35 RIP: multicast announce on eth0
2002/04/28 22:19:35 RIP: update routes on interface eth0 ifindex 2
--------------------------------8<---------------------------------------

r1通過UDP廣播接收到192.168.5.123的更新包,並且把192.168.5.123設爲neighbor。

保存一下配置

r1_ripd# copy run start
Configuration saved to /usr/local/etc/ripd.conf
r2_ripd# copy run start
Configuration saved to /usr/local/etc/ripd.conf

Zebra還支持很多RIP功能,如果Filtering RIP Routes, RIP route-map, RIP Authentication等,有條件有時

間 的話可以做更復雜的實驗。

3、用Zebra做OSPF實驗

OSPF(開放最短路徑優先)路由協議是一項鍊路狀態型技術,是目前IGP中應用最廣、性能最優的一個 協議,

解決了RIP不能解決的大型、可擴展的網絡需求而寫的,適用於大規模的網絡。

Zebra支持OSPFv2和OSPFv3(用於IPv6的OSPF,CISCO還未對其封裝),由於條件所限,下面的OSPF實 驗同樣是

在兩臺單網卡的RedHat7.2下做的。

Zebra使用ospfd程序實現OSPF路由功能,但ospfd需要從zebra程序獲得接口信息,所以zebra程序必須在 ospfd

程序之前運行。ospfd不支持多個OSPF進程,我們不能指定OSPF進程號。

初始化第一臺機器:

shell_1> cd /usr/local/etc
shell_1> cp zebra.conf.sample zebra.conf
shell_1> cp ospfd.conf.sample ospfd.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

進入第一臺機器的ospf設置

shell_1> ospfd -d
shell_1> telnet localhost 2604
Password:
ospfd> en
ospfd# conf t
ospfd(config)# hostname r1_ospfd !改個名字好辨認
r1_ospfd(config)# router ospf !啓動ospf
r1_ospfd(config-router)# ospf router-id 192.168.5.121 !設置router-id
r1_ospfd(config-router)# network 192.168.5.0/24 area 0
!最關鍵的,來標識路由器上哪些IP網絡號是OSPF的一部分,對於每個網絡,我們必須標識該網絡所屬 的區域

。由於我們只有兩臺機器,當然只有一個網絡,所以只需執行一個network命令就夠了。

對於我們的小網絡,ospf就算配好了,下面來檢驗一下:

r1_ospfd(config-router)# ctrl+z
r1_ospfd# sh ip ospf route
============ OSPF network routing table ============
N    192.168.5.0/24        [10] area: 0.0.0.0
                           directly attached to eth0

============ OSPF router routing table =============

============ OSPF external routing table ===========

r1_ospfd# sh ip ospf database

       OSPF Router with ID (192.168.5.121)

                Router Link States (Area 0.0.0.0)

Link ID         ADV Router      Age  Seq#       CkSum  Link count
192.168.5.121   192.168.5.121    126 0x80000002 0x8584 1

r1_ospfd# sh ip ospf int eth0
eth0 is up, line protocol is up

  Internet Address 192.168.5.121/24, Area 0.0.0.0
  Router ID 192.168.5.121, Network Type BROADCAST, Cost: 10
  Transmit Delay is 1 sec, State DR, Priority 1
  Designated Router (ID) 192.168.5.121, Interface Address 192.168.5.121
  No backup designated router on this network
  Timer intarvals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    Hello due in 00:00:07
  Neighbor Count is 0, Adjacent neighbor count is 0

由於網絡裏沒有其它的路由器,r1就把自己選爲DR(指定路由器)了。Zebra對log處理可能有些問題,使 用

log stdout不能顯示各種debug信息,所以只能記錄到文件,在shell下用tail命令查看。而且debug命令和 實

際路由器也有不同。

r1_ospfd# debug ospf event
r1_ospfd(config)# log file /usr/local/etc/ospfd.log

然後我們在shell下查看debug信息

shell_1> tail -f /usr/local/etc/ospfd.log
--------------------------------8<---------------------------------------
2002/04/28 14:24:27 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:24:37 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:24:47 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:24:57 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:25:07 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
--------------------------------8<---------------------------------------

我們錯過了最開始的信息,看到路由器每隔10秒發送一個hello數據包。hello數據包通過多目組播地址

224.0.0.5被髮送出去,如果我們打開debug ospf packet all就能很清楚的看到。

第二臺機器的設置

前面的初始化和第一臺一樣,不過這裏名字設成r2便於辨認,IP設成了192.168.5.123/24。

進入第二臺機器的ospf設置

shell_2> ospfd -d
shell_2> telnet localhost 2604
Password:
ospfd> en
ospfd# conf t
ospfd(config)# hostname r2_ospfd
r2_ospfd(config)# router ospf
r2_ospfd(config-router)# ospf router-id 192.168.5.123
r2_ospfd(config-router)# network 192.168.5.0/24 area 0

執行完network命令,我們看到第一臺機器的tail -f /usr/local/etc/ospfd.log輸出下面的信息:

--------------------------------8<---------------------------------------
2002/04/28 14:25:51 OSPF: Packet 192.168.5.123 [Hello:RECV]: Options *|*|-|-|-|-|E|*
2002/04/28 14:25:51 OSPF: NSM[eth0:192.168.5.121:0.0.0.0]: start
2002/04/28 14:25:52 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 14:25:52 OSPF: couldn't find any VL to associate the packet with
2002/04/28 14:25:52 OSPF: DR-Election[1st]: Backup 192.168.5.123
2002/04/28 14:25:52 OSPF: DR-Election[1st]: DR     192.168.5.121
2002/04/28 14:25:52 OSPF: Packet[DD]: Negotiation done (Slave).
--------------------------------8<---------------------------------------

r1收到r2(192.168.5.123)發過來的hello數據包,交換信息後選舉DR,由於本身192.168.5.121是DR了,所以

只選舉了BDR就好了。這時在r1上就能看到r2了。

r1_ospfd# sh ip ospf neig

Neighbor ID     Pri   State           Dead Time   Address         Interface              RXmtL

RqstL DBsmL
192.168.5.123     1   Full/Backup     00:00:37    192.168.5.123   eth0:192.168.5.121     0     0 

   0

檢驗其它信息

r1_ospfd# sh ip ospf database

       OSPF Router with ID (192.168.5.121)

                Router Link States (Area 0.0.0.0)

Link ID         ADV Router      Age  Seq#       CkSum  Link count
192.168.5.121   192.168.5.121   1259 0x80000008 0x534e 1
192.168.5.123   192.168.5.123   1265 0x80000006 0x534a 1

                Net Link States (Area 0.0.0.0)

Link ID         ADV Router      Age  Seq#       CkSum
192.168.5.123   192.168.5.123   1265 0x80000001 0x5a5a

r1_ospfd# sh ip ospf int eth0
eth0 is up, line protocol is up

  Internet Address 192.168.5.121/24, Area 0.0.0.0
  Router ID 192.168.5.121, Network Type BROADCAST, Cost: 10
  Transmit Delay is 1 sec, State DR, Priority 1
  Designated Router (ID) 192.168.5.121, Interface Address 192.168.5.121
  Backup Designated Router (ID) 192.168.5.123, Interface Address 192.168.5.123
  Timer intarvals configured, Hello 10, Dead 40, Wait 40, Retransmit 5
    Hello due in 00:00:01
  Neighbor Count is 1, Adjacent neighbor count is 1

和前面的輸出信息相比,發生了很多變化,兩臺路由器已經相互識別了。OSPF不象RIP一樣,每隔30秒 給所有

的鄰居廣播一次完整的路由表,而是通過IP多目組播地址224.0.0.5每隔10秒發送一個很小的hello 數據包來維

護鄰居關係,當鏈路發生變化的時候,才重新計算。

拔掉兩臺機器連接的網線,看ospfd.log的記錄:

--------------------------------8<---------------------------------------
2002/04/28 16:25:53 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:25:57 OSPF: Packet 192.168.5.123 [Hello:RECV]: Options *|*|-|-|-|-|E|*
2002/04/28 16:26:03 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:13 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:23 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:33 OSPF: make_hello: options: 2, int: eth0:192.168.5.121
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): Start
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): looked through areas
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_act_attached: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_act_attached: 1
2002/04/28 16:26:37 OSPF: nsm_change_status(): scheduling new router-LSA origination
2002/04/28 16:26:37 OSPF: DR-Election[1nd]: Backup 0.0.0.0
2002/04/28 16:26:37 OSPF: DR-Election[1nd]: DR     192.168.5.121
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): Start
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): looked through areas
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): bb_act_attached: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_configured: 1
2002/04/28 16:26:37 OSPF: ospf_check_abr_status(): areas_act_attached: 1
2002/04/28 16:26:37 OSPF: Timer[router-LSA]: (router-LSA Refresh expire)
2002/04/28 16:26:37 OSPF: counting fully adjacent virtual neighbors in area 0.0.0.0
2002/04/28 16:26:37 OSPF: there are 0 of them
2002/04/28 16:26:37 OSPF: SPF: calculation timer scheduled
2002/04/28 16:26:37 OSPF: SPF: calculation timer delay = 5
2002/04/28 16:26:37 OSPF: ospf_flood_through_interface(): considering int eth0:192.168.5.121
2002/04/28 16:26:37 OSPF: ospf_flood_through_interface(): considering nbr 192.168.5.121
2002/04/28 16:26:42 OSPF: SPF: Timer (SPF calculation expire)
2002/04/28 16:26:42 OSPF: ospf_spf_calculate: Start
2002/04/28 16:26:42 OSPF: ospf_spf_calculate: running Dijkstra for area 0.0.0.0
2002/04/28 16:26:42 OSPF: SPF Result: 0 [R] 192.168.5.121
2002/04/28 16:26:42 OSPF: ========== OSPF routing table ==========
2002/04/28 16:26:42 OSPF: ========================================
2002/04/28 16:26:42 OSPF: ospf_process_stub():processing stubs for area 0.0.0.0
2002/04/28 16:26:42 OSPF: ospf_process_stub():processing router LSA, id: 192.168.5.121
2002/04/28 16:26:42 OSPF: ospf_process_stub(): we have 1 links to process
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): Start
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): processing route to 192.168.5.0/24
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): calculated cost is 0 + 10 = 10
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): installing new route
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): this network is on this router
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): the interface is eth0:192.168.5.121
2002/04/28 16:26:42 OSPF: ospf_intra_add_stub(): Stop
2002/04/28 16:26:42 OSPF: children of V:
2002/04/28 16:26:42 OSPF: ospf_spf_calculate: Stop
2002/04/28 16:26:42 OSPF: ospf_ia_routing():start
2002/04/28 16:26:42 OSPF: ospf_ia_routing():not ABR, considering all areas
2002/04/28 16:26:42 OSPF: Pruning unreachable networks
2002/04/28 16:26:42 OSPF: Pruning unreachable routers
2002/04/28 16:26:42 OSPF: Route: Router Routing Table free
2002/04/28 16:26:42 OSPF: SPF: calculation complete
--------------------------------8<---------------------------------------

我們看到r1生成一個LSA包,通知其它路由器,由於網絡裏只有自己了,又選自己爲DR。r2也是一樣。 我們再

插上網線,查看ospfd.log:

--------------------------------8<---------------------------------------
2002/04/28 16:52:08 OSPF: Packet 192.168.5.123 [Hello:RECV]: Options *|*|-|-|-|-|E|*
2002/04/28 16:52:08 OSPF: NSM[eth0:192.168.5.121:0.0.0.0]: start
2002/04/28 16:52:08 OSPF: DR-Election[1st]: Backup 192.168.5.123
2002/04/28 16:52:08 OSPF: DR-Election[1st]: DR     192.168.5.121
2002/04/28 16:52:08 OSPF: DR-Election[1st]: Backup 0.0.0.0
2002/04/28 16:52:08 OSPF: DR-Election[1st]: DR     192.168.5.123
2002/04/28 16:52:08 OSPF: DR-Election[2nd]: Backup 192.168.5.121
2002/04/28 16:52:08 OSPF: DR-Election[2nd]: DR     192.168.5.123
--------------------------------8<---------------------------------------

由於拔了網線,r1和r2都把自己選爲DR,一個網絡只能有一個DR,所以恢復連接後它們重新進行了DR選 舉,由

於192.168.5.123的router id大,所以它被選爲DR。

保存一下配置

r1_ospfd# copy run start
Configuration saved to /usr/local/etc/ospfd.conf
r2_ospfd# copy run start
Configuration saved to /usr/local/etc/ospfd.conf

以上只是演示了最簡單的OSPF的配置,而OSPF在大型網絡才廣泛的使用,配置也複雜多很多。即使是 Zebra,

也還可用做複雜的多的OSPF實驗。

4、用Zebra做BGP實驗

RIP和OSPF都是內部網關協議(IGP),BGP屬於外部網關協議(EGP)。BGP廣泛用於Internet以連接 ISP,並將

企業與ISP互連。

當BGP的影響被完全瞭解,並且至少下列情況之一存在時,在AS中使用BGP纔是最恰當的:
  1 AS允許數據包穿過它到達其它自治系統(例如,某個服務提供商)。
  2 AS有到其它自治系統的多條連接。
  3 必須對進入和離開AS的數據流進行控制。

對於互連的自治系統來說,BGP並不總是恰當的解決方案,如果有如下情況中的一個或多個時,不要使 用BGP:
  1 只有到Internet或另一AS的單一連接。
  2 無需考慮路由策略或路由選擇。
  3 路由器缺乏經常性的BGP更新的內存或處理器。
  4 對路由過濾和BGP路徑選擇過程的瞭解十分有限。
  5 在自治系統間的帶寬較低。
在這些情況下,應該使用靜態路由。

Zebra支持BGP-4和BGP-4+,下面實驗只是演示BGP的基本命令,以及debug的一些信息。一個比較複雜 的用

Zebra做BGP實驗見http://www.unixreview.com/print/documentID=15977,有條件可以做一下。

Zebra使用bgpd程序實現BGP路由功能,但bgpd需要從zebra程序獲得接口信息,所以zebra程序必須在 bgpd程序

之前運行。

初始化第一臺機器:

shell_1> cd /usr/local/etc
shell_1> cp zebra.conf.sample zebra.conf
shell_1> cp bgpd.conf.sample bgpd.conf
shell_1> zebra -d

還有一個bgpd.conf.sample2配置樣例是用於IPv6的。

進入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

進入第一臺機器的bgp設置

shell_1> bgpd -d

啓動bgpd,我們看到TCP端口179已經打開。兩臺BGP路由器相互間建立一條TCP連接,交換消息以打開 和確認連

接參數。這兩臺路由器被稱爲對等路由器,或者鄰居。

shell_1> telnet localhost 2605
Password:
bgpd> en
bgpd# conf t
bgpd(config)# hostname r1_bgpd
r1_bgpd(config)# router bgp 7675

配置樣例裏已經指定了AS爲7675,我們懶的改就拿來用。AS是一個16bit的數字,其範圍從1到 65535。RFC

1930給出了AS編號使用指南。從64512到65535的AS編號範圍是留作私用的,類似私有IP。

r1_bgpd(config-router)# network 192.168.5.0/24
r1_bgpd(config-router)# neighbor 192.168.5.121 remote-as 7676

查看bgp信息:

r1_bgpd# sh ip bgp
BGP table version is 0, local router ID is 192.168.5.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*> 192.168.5.0      0.0.0.0                            32768 i

Total number of prefixes 1

把log記錄到文件:

r1_bgpd# conf t
r1_bgpd(config)# log file /usr/local/etc/bgpd.log

打開debug選項:

r1_bgpd(config)# exit
r1_bgpd debug bgp events
r1_bgpd debug bgp keepalives
r1_bgpd debug bgp updates

然後在shell下用tail查看log記錄:

shell_1> tail -f /usr/local/etc/bgpd.log
--------------------------------8<---------------------------------------
2002/04/29 19:13:08 BGP: 192.168.5.121 [Event] Connect start to 192.168.5.121 fd 10
2002/04/29 19:13:11 BGP: 192.168.5.121 [Event] Connect failed (Operation now in progress)
--------------------------------8<---------------------------------------

r1不能連接鄰居192.168.5.121。

第二臺機器的設置

前面的初始化和第一臺一樣,不過這裏名字設成r2便於辨認,IP設成了192.168.5.123/24。

進入第二臺機器的bgp設置

shell_2> bgpd -d
shell_2> telnet localhost 2605
Password:
bgpd> en
bgpd# conf t
bgpd(config)# hostname r2_bgpd

AS要設成不一樣,所以修改一下:

r2_bgpd(config)# no router bgp 7675
r2_bgpd(config)# router bgp 7676
r2_bgpd(config-router)# network 192.168.5.0/24
r2_bgpd(config-router)# neighbor 192.168.5.123 remote-as 7675

這時第一臺機器的log出現如下信息:

--------------------------------8<---------------------------------------
2002/04/29 19:16:35 BGP: [Event] BGP connection from host 192.168.5.121
2002/04/29 19:16:35 BGP: [Event] Make dummy peer structure until read Open packet
2002/04/29 19:16:35 BGP: 192.168.5.121 [Event] Transfer temporary BGP peer to existing one
2002/04/29 19:16:35 BGP: 192.168.5.121 [Event] Accepting BGP peer delete
2002/04/29 19:16:35 BGP: 192.168.5.121 send UPDATE 192.168.5.0/24 nexthop 192.168.5.123, origin

i, path
2002/04/29 19:16:35 BGP: 192.168.5.121 rcvd UPDATE w/ attr: nexthop 192.168.5.121, origin i, path

7676
2002/04/29 19:16:35 BGP: 192.168.5.121 rcvd 192.168.5.0/24
--------------------------------8<---------------------------------------

兩臺bgp已經互連了。再看一下第一臺機器的bgp信息:

r1_bgpd# sh ip bgp
BGP table version is 0, local router ID is 192.168.5.123
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal
Origin codes: i - IGP, e - EGP, ? - incomplete

   Network          Next Hop            Metric LocPrf Weight Path
*  192.168.5.0      192.168.5.121                          0 7676 i
*>                  0.0.0.0                            32768 i

Total number of prefixes 1

r1_bgpd# sh ip bgp neighbors
BGP neighbor is 192.168.5.121, remote AS 7676, local AS 7675, external link
  BGP version 4, remote router ID 192.168.5.121
  BGP state = Established, up for 00:01:13
  Last read 00:00:13, hold time is 180, keepalive interval is 60 seconds
  Neighbor capabilities:
    Route refresh: advertised and received (old and new)
    Address family IPv4 Unicast: advertised and received
  Received 98 messages, 0 notifications, 0 in queue
  Sent 103 messages, 0 notifications, 0 in queue
  Route refresh request: received 0, sent 0
  Minimum time between advertisement runs is 0 seconds

For address family: IPv4 Unicast
  Community attribute sent to this neighbor (both)
  1 accepted prefixes

  Connections established 2; dropped 1
Local host: 192.168.5.123, Local port: 179
Foreign host: 192.168.5.121, Foreign port: 1029
Nexthop: 192.168.5.123
Read thread: on  Write thread: off

Zebra還支持很多BGP的特性,請參考GNU Zebra Manual,有條件的可以做一下那些實驗。

Zebra的Mailing List比較活躍,有許多人在那裏討論Zebra的開發和配置等等,有問題的話,在那裏應該 能得

到解答。

Reference

GNU Zebra Manual
http://www.pointless.net/~jasper/zebra-html/zebra_toc.html#SEC_Contents
組建可擴展的Cisco網絡
http://www.unixreview.com/print/documentID=15977]


                       

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章