用Zebra做OSPF實驗

來源:互聯網
上載者:User

用Zebra做OSPF實驗
關鍵字: zebra
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也是一樣。-

文章出處:http://www.diybl.com/course/6_system/linux/Linuxjs/2008929/146644.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.