- 掌握OSPF配置指定Router ID的方法
- 掌握多区域OSPF的配置方法
- 掌握OSPF区域之间路由汇总的配置方法
- 掌握OSPF参考带宽的配置方法
- 掌握OSPF引入外部路由的配置方法
- 掌握OSPF引入的外部路由时进行路由汇总的方法
- 掌握向OSPF导入缺省路由的方法
- 掌握对OSPF中各类路由的管理距离的修改方法
你是公司的网络管理员。现在公司的网络中有五台ARG3路由器,其中R1、R2和R4在公司总部,通过以太网互联。R3、与R5在公司分部,R3通过专线与公司总部的R2相连,R5与R3之间也通过专项相连。由于网络规模较大,为了控制LSA的洪泛,你设计了多区域的OSPF互联方式。
其中R2与R3的Loopback0接口、互联接口属于区域0;R3与R5互联的网段、R5的Loopback0/1/2接口属于区域1;R1、R2与R4互联的网段以及R1、R4的Loopback0接口属于区域2。
同时为了明确设备的Router-ID,你配置设备使用固定的地址作为Router ID。
为了使路由器进行路由转发时效率更高,在区域的边界你配置了自动汇总。
R1路由器连接到公司以外的网络,你配置将这些OSPF区域之外的路由信息引入到OSPF区域。
R4路由器连接到Internet,你需要配置一条缺省路由,引入到OSPF区域,以便于OSPF区域的所有路由器都知道如何访问Internet。
同时OSPF路由信息中区分了内部路由和外部路由,你修改了OSPF路由信息的优先级信息,以避免潜在的风险。
OSPF中特定路由信息的度量值是将到达目的网络所经过的所有链路的代价值进行累加得到的。而链路的代价值是路由器将接口带宽与参考带宽进行对比得到。参考带宽值为100Mbps,实际接口带宽可能为1000Mbps,而度量值都是整数,所以快速以太网接口和千兆以太网接口的OSPF代价值均为1。为了能够相互区分这些链路,你定义参考带宽值为10Gbps。
在配置设备的同时,出现了一些网络故障,你通过使用display和debug命令进行了故障排除。
- 基础配置与IP编址
给所有路由器配置IP地址和掩码。配置时注意所有的Loopback接口配置掩码均为24位,模拟成一个单独的网段。如果遇到实验需要创建多条loopback口,可以使用sub模式
<R1>system-view
Enter system view, return user view with Ctrl+Z.
[R1]interface GigabitEthernet 0/0/0
[R1-GigabitEthernet0/0/0]ip address 10.0.124.1 24
[interface LoopBack0
ip address 10.1.1.1 255.255.255.0
ip address 10.2.0.1 255.255.255.0 sub
ip address 10.2.1.1 255.255.255.0 sub
ospf network-type broadcast
<R2>system-view
Enter system view, return user view with Ctrl+Z.
[R2]interface GigabitEthernet 0/0/0
[R2-GigabitEthernet0/0/0]ip address 10.0.124.2 24
[R2-GigabitEthernet0/0/0]interface Serial 2/0/0
[R2-Serial2/0/0]ip address 10.0.23.2 24
[R2-Serial2/0/0]interface LoopBack 0
[R2-LoopBack0]ip address 10.0.2.2 24
<R3>system-view
Enter system view, return user view with Ctrl+Z.
[R3]interface Serial 2/0/0
[R3-Serial2/0/0]ip address 10.0.23.3 24
[R3-Serial2/0/0]interface Serial 3/0/0
[R3-Serial3/0/0]ip address 10.0.35.3 24
[R3-Serial3/0/0]interface LoopBack 0
[R3-LoopBack0]ip address 10.0.3.3 24
<R4>system-view
Enter system view, return user view with Ctrl+Z.
[R4]interface GigabitEthernet 0/0/0
[R4-GigabitEthernet0/0/0]ip address 10.0.124.4 24
[R4-GigabitEthernet0/0/0]interface LoopBack 0
[R4-LoopBack0]ip address 10.0.4.4 24
<R5>system-view
Enter system view, return user view with Ctrl+Z.
[R5]interface Serial 1/0/0
[R5-Serial1/0/0]ip address 10.0.35.5 24
[R5-Serial1/0/0]interface LoopBack 0
[R5-LoopBack0]ip address 10.0.5.5 24
[R5-LoopBack0]interface LoopBack 1
[R5-LoopBack1]ip address 10.1.0.1 24
[R5-LoopBack1]interface LoopBack 2
[R5-LoopBack2]ip address 10.1.1.1 24
配置完成后,测试直连链路的连通性。
[R2]ping -c 1 10.0.124.1
PING 10.0.124.1: 56 data bytes, press CTRL_C to break
Reply from 10.0.124.1: bytes=56 Sequence=1 ttl=255 time=5 ms
--- 10.0.124.1 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 5/5/5 ms
[R2]ping -c 1 10.0.124.4
PING 10.0.124.4: 56 data bytes, press CTRL_C to break
Reply from 10.0.124.4: bytes=56 Sequence=1 ttl=255 time=14 ms
--- 10.0.124.4 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 14/14/14 ms
[R2]ping -c 1 10.0.23.3
PING 10.0.23.3: 56 data bytes, press CTRL_C to break
Reply from 10.0.23.3: bytes=56 Sequence=1 ttl=255 time=41 ms
--- 10.0.23.3 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 41/41/41 ms
[R3]ping -c 1 10.0.35.5
PING 10.0.35.5: 56 data bytes, press CTRL_C to break
Reply from 10.0.35.5: bytes=56 Sequence=1 ttl=255 time=38 ms
--- 10.0.35.5 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 38/38/38 ms
- 配置多区域OSPF
为保证OSPF的Router ID稳定,我们通常手工指定路由器的Router ID。有2种方法可以手工指定一台路由器运行OSPF的Router ID,第一种方式是在系统视图下使用router id的命令。
[R1]router id 10.0.1.1
第二种方式是在启动OSPF进程时加上参数router-id。
[R1]ospf 1 router-id 10.0.1.1
当路由器上同时配置了这两条命令以后,路由器最终会选取第二种方式配置的值作为Router ID。如果在一台路由器上需要起多个OSPF进程,且每个OSPF进程的Router ID需要不一样时,我们只能使用第二种方式来指定Router ID。
在R1上配置Loopback 0接口及GigabitEthernet 0/0/0属于区域2。这里我们将所有OSPF区域的Loopback接口,修改其OSPF网络类型为Broadcast类型,以便于OSPF发布Loopback口的真实掩码信息。
[R1]ospf 1 router-id 10.0.1.1
[R1-ospf-1]area 2
[R1-ospf-1-area-0.0.0.2]network 10.0.124.1 0.0.0.0
[R1-ospf-1-area-0.0.0.2]quit
[R1-ospf-1]quit
[R1]interface LoopBack 0
[R1-LoopBack0]ospf network-type broadcast
[R1-LoopBack0]quit
在R2上配置Loopback 0和Serial 2/0/0接口属于区域0,GigabitEthernet 0/0/0属于区域2。
[R2]ospf 1 router-id 10.0.2.2
[R2-ospf-1]area 0
[R2-ospf-1-area-0.0.0.0]network 10.0.23.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]network 10.0.2.2 0.0.0.0
[R2-ospf-1-area-0.0.0.0]quit
[R2-ospf-1]area 2
[R2-ospf-1-area-0.0.0.2]network 10.0.124.2 0.0.0.0
[R2-ospf-1-area-0.0.0.2]quit
[R2-ospf-1]quit
[R2]interface LoopBack 0
[R2-LoopBack0]ospf network-type broadcast
[R2-LoopBack0]quit
在R3上配置Loopback 0和Serial 2/0/0接口属于区域0,Serial 3/0/0属于区域1。
[R3]ospf 1 router-id 10.0.3.3
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 10.0.3.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]network 10.0.23.3 0.0.0.0
[R3-ospf-1-area-0.0.0.0]quit
[R3-ospf-1]area 1
[R3-ospf-1-area-0.0.0.1]network 10.0.35.3 0.0.0.0
[R3-ospf-1-area-0.0.0.1]quit
[R3-ospf-1]quit
[R3]interface LoopBack 0
[R3-LoopBack0]ospf network-type broadcast
[R3-LoopBack0]quit
在R4上配置Loopback 0及GigabitEthernet 0/0/0属于区域2。
[R4]ospf 1 router-id 10.0.4.4
[R4-ospf-1]area 2
[R4-ospf-1-area-0.0.0.2]network 10.0.4.4 0.0.0.0
[R4-ospf-1-area-0.0.0.2]network 10.0.124.4 0.0.0.0
[R4-ospf-1-area-0.0.0.2]quit
[R4-ospf-1]quit
[R4]interface LoopBack 0
[R4-LoopBack0]ospf network-type broadcast
[R4-LoopBack0]quit
在R5上配置所有的Loopback接口及Serial 1/0/0属于区域1。
[R5]ospf 1 router-id 10.0.5.5
[R5-ospf-1]area 1
[R5-ospf-1-area-0.0.0.1]network 10.0.5.5 0.0.0.0
[R5-ospf-1-area-0.0.0.1]network 10.1.0.1 0.0.0.0
[R5-ospf-1-area-0.0.0.1]network 10.1.1.1 0.0.0.0
[R5-ospf-1-area-0.0.0.1]network 10.0.35.5 0.0.0.0
[R5-ospf-1-area-0.0.0.1]quit
[R5-ospf-1]quit
[R5]interface LoopBack 0
[R5-LoopBack0]ospf network-type broadcast
[R5-LoopBack0]quit
[R5]interface LoopBack 1
[R5-LoopBack1]ospf network-type broadcast
[R5-LoopBack1]quit
[R5]interface LoopBack 2
[R5-LoopBack2]ospf network-type broadcast
[R5-LoopBack2]quit
配置完成后,在R1上查看路由表。
[R1]display ip routing-table
Route Flags: R - relay, D - download to fib
---------------------------------------------------------------------------
Routing Tables: Public
Destinations : 24 Routes : 24
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.0/24 Direct 0 0 D 10.0.1.1 LoopBack0
10.0.1.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
10.0.1.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
10.0.2.0/24 OSPF 10 1 D 10.0.124.2 GigabitEthernet0/0/0
10.0.3.0/24 OSPF 10 1563 D 10.0.124.2 GigabitEthernet0/0/0
10.0.4.0/24 OSPF 10 1 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 3125 D 10.0.124.2 GigabitEthernet0/0/0
10.0.23.0/24 OSPF 10 1563 D 10.0.124.2 GigabitEthernet0/0/0
10.0.35.0/24 OSPF 10 3125 D 10.0.124.2 GigabitEthernet0/0/0
10.0.124.0/24 Direct 0 0 D 10.0.124.1 GigabitEthernet0/0/0
10.0.124.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
10.0.124.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
10.1.0.0/24 OSPF 10 3125 D 10.0.124.2 GigabitEthernet0/0/0
10.1.1.0/24 OSPF 10 3125 D 10.0.124.2 GigabitEthernet0/0/0
10.2.0.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
10.2.1.0/24 Direct 0 0 D 10.2.1.1 LoopBack2
10.2.1.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
10.2.1.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.0/8 Direct 0 0 D 127.0.0.1 InLoopBack0
127.0.0.1/32 Direct 0 0 D 127.0.0.1 InLoopBack0
127.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
255.255.255.255/32 Direct 0 0 D 127.0.0.1 InLoopBack0
该路由器上已拥有全网所有的路由条目。
在R1上测试到其他路由器Loopback接口的连通性。
[R1]ping -c 1 10.0.2.2
PING 10.0.2.2: 56 data bytes, press CTRL_C to break
Reply from 10.0.2.2: bytes=56 Sequence=1 ttl=255 time=3 ms
--- 10.0.2.2 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 3/3/3 ms
[R1]ping -c 1 10.0.5.5
PING 10.0.5.5: 56 data bytes, press CTRL_C to break
Reply from 10.0.5.5: bytes=56 Sequence=1 ttl=253 time=88 ms
--- 10.0.5.5 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 88/88/88 ms
[R1]ping -c 1 10.0.4.4
PING 10.0.4.4: 56 data bytes, press CTRL_C to break
Reply from 10.0.4.4: bytes=56 Sequence=1 ttl=255 time=3 ms
--- 10.0.4.4 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 3/3/3 ms
我们使用display ospf brief命令在R2上查看路由器运行的基本OSPF信息。
[R2]display ospf brief
OSPF Process 1 with Router ID 10.0.2.2
OSPF Protocol Information
RouterID: 10.0.2.2 Border Router: AREA
Multi-VPN-Instance is not enabled
Global DS-TE Mode: Non-Standard IETF Mode
Graceful-restart capability: disabled
Helper support capability : not configured
Spf-schedule-interval: max 10000ms, start 500ms, hold 1000ms
Default ASE parameters: Metric: 1 Tag: 1 Type: 2
Route Preference: 10
ASE Route Preference: 150
SPF Computation Count: 19
RFC 1583 Compatible
Retransmission limitation is disabled
Area Count: 2 Nssa Area Count: 0
ExChange/Loading Neighbors: 0
Area: 0.0.0.0
Authtype: None Area flag: Normal
SPF scheduled Count: 19
ExChange/Loading Neighbors: 0
Interface: 10.0.2.2 (LoopBack0)
Cost: 0 State: DR Type: Broadcast MTU: 1500
Priority: 1
Designated Router: 10.0.2.2
Backup Designated Router: 0.0.0.0
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
Interface: 10.0.23.2 (Serial2/0/0) --> 10.0.23.3
Cost: 1562 State: P-2-P Type: P2P MTU: 1500
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
Area: 0.0.0.2
Authtype: None Area flag: Normal
SPF scheduled Count: 17
ExChange/Loading Neighbors: 0
Interface: 10.0.124.2 (GigabitEthernet0/0/0)
Cost: 1 State: BDR Type: Broadcast MTU: 1500
Priority: 1
Designated Router: 10.0.124.1
Backup Designated Router: 10.0.124.2
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
第一行Border Router: AREA 表示该路由器是一台ABR;如果路由器是一台区域内路由器,该值为空;如果路由器是一台ASBR,该值为 AS。
该路由器共有三个接口参加OSPF运算,我们已手工将Loopback 0接口的网络类型修改为Broadcast。Serial2/0/0的封装类型为PPP,所以默认的网络类型为点对点。另外GigabitEthernet 0/0/0连接到区域2,是广播型网络。
我们在R2上使用display ospf peer brief命令查看路由器的OSPF邻居关系建立情况。可以看到,在区域0,R2有一个邻居10.0.3.3,在区域2,R2有2个邻居:10.0.1.1和10.0.4.4,R2与他们都形成了邻接关系(Full)。
[R2]display ospf peer brief
OSPF Process 1 with Router ID 10.0.2.2
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 Serial2/0/0 10.0.3.3 Full
0.0.0.2 GigabitEthernet0/0/0 10.0.1.1 Full
0.0.0.2 GigabitEthernet0/0/0 10.0.4.4 Full
----------------------------------------------------------------------------
我们在R2上使用display ospf lsdb命令查看路由器的OSPF数据库信息。我们可以发现由于R2是一台ABR,所以在该路由器上维护了2个LSDB,分别用来描述区域0和区域2的路由。
[R2]display ospf lsdb
OSPF Process 1 with Router ID 10.0.2.2
Link State Database
Area: 0.0.0.0
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 10.0.3.3 10.0.3.3 788 60 80000008 0
Router 10.0.2.2 10.0.2.2 869 60 80000008 0
Sum-Net 10.0.35.0 10.0.3.3 846 28 80000002 1562
Sum-Net 10.0.124.0 10.0.2.2 1259 28 80000002 1
Sum-Net 10.1.1.0 10.0.3.3 1565 28 80000001 1562
Sum-Net 10.0.5.0 10.0.3.3 1594 28 80000001 1562
Sum-Net 10.1.0.0 10.0.3.3 1584 28 80000001 1562
Sum-Net 10.0.4.0 10.0.2.2 538 28 80000002 1
Area: 0.0.0.2
Type LinkState ID AdvRouter Age Len Sequence Metric
Router 10.0.4.4 10.0.4.4 504 48 80000008 1
Router 10.0.2.2 10.0.2.2 558 36 80000006 1
Router 10.0.1.1 10.0.1.1 568 60 80000011 1
Network 10.0.124.1 10.0.1.1 559 36 80000005 0
Sum-Net 10.0.35.0 10.0.2.2 846 28 80000002 3124
Sum-Net 10.0.3.0 10.0.2.2 830 28 80000002 1562
Sum-Net 10.0.2.0 10.0.2.2 1249 28 80000002 0
Sum-Net 10.1.1.0 10.0.2.2 1565 28 80000001 3124
Sum-Net 10.0.5.0 10.0.2.2 1595 28 80000001 3124
Sum-Net 10.1.0.0 10.0.2.2 1584 28 80000001 3124
Sum-Net 10.0.23.0 10.0.2.2 1261 28 80000002 1562
- 配置OSPF区域之间的路由汇总
首先查看R2和R3的OSPF路由表。
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 8 Routes : 8
OSPF routing table status : <Active>
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.3.0/24 OSPF 10 1562 D 10.0.23.3 Serial2/0/0
10.0.4.0/24 OSPF 10 1 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 3124 D 10.0.23.3 Serial2/0/0
10.0.35.0/24 OSPF 10 3124 D 10.0.23.3 Serial2/0/0
10.1.0.0/24 OSPF 10 3124 D 10.0.23.3 Serial2/0/0
10.1.1.0/24 OSPF 10 3124 D 10.0.23.3 Serial2/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
[R3]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 8 Routes : 8
OSPF routing table status : <Active>
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.2.0/24 OSPF 10 1562 D 10.0.23.2 Serial2/0/0
10.0.4.0/24 OSPF 10 1563 D 10.0.23.2 Serial2/0/0
10.0.5.0/24 OSPF 10 1562 D 10.0.35.5 Serial3/0/0
10.0.124.0/24 OSPF 10 1563 D 10.0.23.2 Serial2/0/0
10.1.0.0/24 OSPF 10 1562 D 10.0.35.5 Serial3/0/0
10.1.1.0/24 OSPF 10 1562 D 10.0.35.5 Serial3/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
10.1.0.0/24和10.1.1.0/24两条路由信息均以详细条目出现。
对于这样的路由信息,可以进行汇总,再向其他区域发送。一方面减少其他区域的路由表条目,另外一方面还可以减少路由振荡情况的发生。我们可在R3上使用abr-summary的命令将R5的Loopback1和Loopback2接口的网段进行汇总发送。
[R3]ospf 1
[R3-ospf-1]area 1
[R3-ospf-1-area-0.0.0.1]abr-summary 10.1.0.0 255.255.254.0
配置完成后在R3和R2上分别查看汇总路由信息。
[R3]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 8 Routes : 8
OSPF routing table status : <Active>
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.2.0/24 OSPF 10 1562 D 10.0.23.2 Serial2/0/0
10.0.4.0/24 OSPF 10 1563 D 10.0.23.2 Serial2/0/0
10.0.5.0/24 OSPF 10 1562 D 10.0.35.5 Serial3/0/0
10.0.124.0/24 OSPF 10 1563 D 10.0.23.2 Serial2/0/0
10.1.0.0/24 OSPF 10 1562 D 10.0.35.5 Serial3/0/0
10.1.1.0/24 OSPF 10 1562 D 10.0.35.5 Serial3/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 7 Routes : 7
OSPF routing table status : <Active>
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.3.0/24 OSPF 10 1562 D 10.0.23.3 Serial2/0/0
10.0.4.0/24 OSPF 10 1 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 3124 D 10.0.23.3 Serial2/0/0
10.0.35.0/24 OSPF 10 3124 D 10.0.23.3 Serial2/0/0
10.1.0.0/23 OSPF 10 3124 D 10.0.23.3 Serial2/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
通过输出可以看到,在R3的路由表中,这2条路由仍以明细路由的形式出现,在R2上,仅存在汇总路由10.1.0.0/23。
配置完成后,测试其他路由器与网络10.1.0.0/24与10.1.1.0/24的连通性。
[R1]ping -c 1 10.1.0.1
PING 10.1.0.1: 56 data bytes, press CTRL_C to break
Reply from 10.1.0.1: bytes=56 Sequence=1 ttl=253 time=66 ms
--- 10.1.0.1 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 66/66/66 ms
[R1]ping -c 1 10.1.1.1
PING 10.1.1.1: 56 data bytes, press CTRL_C to break
Reply from 10.1.1.1: bytes=56 Sequence=1 ttl=253 time=66 ms
--- 10.1.1.1 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 66/66/66 ms
[R2]ping -c 1 10.1.0.1
PING 10.1.0.1: 56 data bytes, press CTRL_C to break
Reply from 10.1.0.1: bytes=56 Sequence=1 ttl=254 time=69 ms
--- 10.1.0.1 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 69/69/69 ms
[R3]ping -c 1 10.1.0.1
PING 10.1.0.1: 56 data bytes, press CTRL_C to break
Reply from 10.1.0.1: bytes=56 Sequence=1 ttl=255 time=29 ms
--- 10.1.0.1 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 29/29/29 ms
- 修改OSPF的参考带宽值
在实际网络我们可能使用了千兆甚至万兆以太网。但是由于OSPF的默认参考带宽值为100Mbps,并且接口代价值仅为整数,所以OSPF无法在带宽上区分百兆以太网和千兆以太网。
在R2上修改OSPF的参考带宽值为10Gbps。这里,使用命令bandwidth-reference进行修改,相应带宽参数值的单位为Mbps。
[R2-ospf-1]bandwidth-reference 10000
在R2上查看OSPF邻居关系,以及路由信息学习情况,我们可以看到,在路由表中,Cost值已经发生了变化。
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 7 Routes : 7
OSPF routing table status : <Active>
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.3.0/24 OSPF 10 65535 D 10.0.23.3 Serial2/0/0
10.0.4.0/24 OSPF 10 10 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 67097 D 10.0.23.3 Serial2/0/0
10.0.35.0/24 OSPF 10 67097 D 10.0.23.3 Serial2/0/0
10.1.0.0/23 OSPF 10 67097 D 10.0.23.3 Serial2/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
在运行OSPF的多个区域内,OSPF的参考带宽值必须一致,否则OSPF无法正常工作。修改所有路由器的OSPF参考带宽值为10Gbps。
[R1-ospf-1]bandwidth-reference 10000
[R3-ospf-1]bandwidth-reference 10000
[R4-ospf-1]bandwidth-reference 10000
[R5-ospf-1]bandwidth-reference 10000
在R2上查看邻居列表、路由表,观察OSPF邻居关系以及路由信息是否正常。
[R2]display ospf peer brief
OSPF Process 1 with Router ID 10.0.2.2
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 Serial2/0/0 10.0.3.3 Full
0.0.0.2 GigabitEthernet0/0/0 10.0.1.1 Full
0.0.0.2 GigabitEthernet0/0/0 10.0.4.4 Full
----------------------------------------------------------------------------
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 7 Routes : 7
OSPF routing table status : <Active>
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.3.0/24 OSPF 10 65535 D 10.0.23.3 Serial2/0/0
10.0.4.0/24 OSPF 10 10 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.0.35.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.1.0.0/23 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
如上所示,路由信息正常。另外可测试网络的连通性。
- 配置将直连路由汇总并引入到OSPF区域
R1的Loopback1和Loopback2接口不属于OSPF区域。将这两条直连路由引入到OSPF区域,并在R1上执行路由汇总。
[R1]ospf
[R1-ospf-1]import-route direct
[R1-ospf-1]asbr-summary 10.2.0.0 255.255.254.0
在R1上查看外部路由信息。
[R1]display ospf lsdb ase 10.2.0.0
OSPF Process 1 with Router ID 10.0.1.1
Link State Database
Type : External
Ls id : 10.2.0.0
Adv rtr : 10.0.1.1
Ls age : 293
Len : 36
Options : E
seq# : 80000001
chksum : 0x2b6
Net mask : 255.255.254.0
TOS 0 Metric: 2
E type : 2
Forwarding Address : 0.0.0.0
Tag : 1
Priority : Low
R1通过一条第五类LSA向其他路由器通告了网段10.2.0.0,子网掩码是255.255.254.0。
在其他路由器上查看汇总路由,并测试网络连通性。
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 7 Routes : 7
OSPF routing table status : <Active>
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.0/24 O_ASE 150 1 D 10.0.124.1 GigabitEthernet0/0/0
10.0.3.0/24 OSPF 10 65535 D 10.0.23.3 Serial2/0/0
10.0.4.0/24 OSPF 10 10 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.0.35.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.1.0.0/23 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.2.0.0/23 O_ASE 150 2 D 10.0.124.1 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
[R2]ping -c 1 10.2.0.1
PING 10.2.0.1: 56 data bytes, press CTRL_C to break
Reply from 10.2.0.1: bytes=56 Sequence=1 ttl=255 time=2 ms
--- 10.2.0.1 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 2/2/2 ms
[R2]ping -c 1 10.2.1.1
PING 10.2.1.1: 56 data bytes, press CTRL_C to break
Reply from 10.2.1.1: bytes=56 Sequence=1 ttl=255 time=2 ms
--- 10.2.1.1 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 2/2/2 ms
在R2上可以看到一条掩码为23位的汇总路由。
将R1的Loopback 2接口删除,查看R2上路由条目变化情况。我们可以看到,当Loopback 2接口不存在了,汇总路由仍然存在。
[R1]undo interface LoopBack 2
[R2]display ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 7 Routes : 7
OSPF routing table status : <Active>
Destinations : 7 Routes : 7
Destination/Mask Proto Pre Cost Flags NextHop Interface
10.0.1.0/24 O_ASE 150 1 D 10.0.124.1 GigabitEthernet0/0/0
10.0.3.0/24 OSPF 10 65535 D 10.0.23.3 Serial2/0/0
10.0.4.0/24 OSPF 10 10 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.0.35.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.1.0.0/23 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.2.0.0/23 O_ASE 150 2 D 10.0.124.1 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
在R5设备上向10.2.1.1地址发送Tracert数据包。
<R5>tracert 10.2.1.1
traceroute to 10.2.1.1(10.2.1.1), max hops: 30 ,packet length: 40,press CTRL_C to break
1 10.0.35.3 62 ms 28 ms 27 ms
2 10.0.23.2 54 ms 58 ms 57 ms
3 * * *
...
我们可以看到虽然Loopback 2接口被删除了,到达该目的地址的数据包仍然被R2和R3转发,直到R1上该数据包被丢弃。
- OSPF引入缺省路由
R4的Loopback0接口连接到Internet。在R4上配置缺省路由,下一跳指向Loopback0。
[R4]ip route-static 0.0.0.0 0.0.0.0 LoopBack 0
将这条缺省路由引入到OSPF区域,定义类型为1,Cost值为10,并且定义为永久引入。
[R4]ospf 1
[R4-ospf-1]default-route-advertise always type 1
在R2上查看缺省路由的学习情况。我们可以看到R2通过第五类LSA学习到了一条默认路由,下一跳是R4的接口地址。
[R2]dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 8 Routes : 8
OSPF routing table status : <Active>
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 O_ASE 150 11 D 10.0.124.4 GigabitEthernet0/0/0
10.0.1.0/24 O_ASE 150 1 D 10.0.124.1 GigabitEthernet0/0/0
10.0.3.0/24 OSPF 10 65535 D 10.0.23.3 Serial2/0/0
10.0.4.0/24 OSPF 10 10 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.0.35.0/24 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.1.0.0/23 OSPF 10 131070 D 10.0.23.3 Serial2/0/0
10.2.0.0/23 O_ASE 150 2 D 10.0.124.1 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
最后测试R5路由器与10.0.4.4之间的连通性。
[R5]ping -c 1 10.0.4.4
PING 10.0.4.4: 56 data bytes, press CTRL_C to break
Reply from 10.0.4.4: bytes=56 Sequence=1 ttl=253 time=78 ms
--- 10.0.4.4 ping statistics ---
1 packet(s) transmitted
1 packet(s) received
0.00% packet loss
round-trip min/avg/max = 78/78/78 ms
- 修改OSPF中两类路由的优先级
查看R1的路由表,关注OSPF不同类型路由的优先级信息。
[R1]dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 8 Routes : 8
OSPF routing table status : <Active>
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 O_ASE 150 11 D 10.0.124.4 GigabitEthernet0/0/0
10.0.2.0/24 OSPF 10 10 D 10.0.124.2 GigabitEthernet0/0/0
10.0.3.0/24 OSPF 10 65545 D 10.0.124.2 GigabitEthernet0/0/0
10.0.4.0/24 OSPF 10 10 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 10 131080 D 10.0.124.2 GigabitEthernet0/0/0
10.0.23.0/24 OSPF 10 65545 D 10.0.124.2 GigabitEthernet0/0/0
10.0.35.0/24 OSPF 10 131080 D 10.0.124.2 GigabitEthernet0/0/0
10.1.0.0/23 OSPF 10 131080 D 10.0.124.2 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
默认情况下,OSPF区域内和区域之间的路由,优先级为10。OSPF外部路由,优先级为150。
修改R1和R4路由器上的OSPF区域内和区域之间的路由优先级为20,修改OSPF外部路由的优先级为50。
[R1]ospf
[R1-ospf-1]preference 20
[R1-ospf-1]preference ase 50
[R4]ospf
[R4-ospf-1]preference 20
[R4-ospf-1]preference ase 50
查看路由表中OSPF内部路由及外部路由的优先级,确认已修改成功。
[R1]dis ip routing-table protocol ospf
Route Flags: R - relay, D - download to fib
----------------------------------------------------------------------------
Public routing table : OSPF
Destinations : 8 Routes : 8
OSPF routing table status : <Active>
Destinations : 8 Routes : 8
Destination/Mask Proto Pre Cost Flags NextHop Interface
0.0.0.0/0 O_ASE 50 11 D 10.0.124.4 GigabitEthernet0/0/0
10.0.2.0/24 OSPF 20 10 D 10.0.124.2 GigabitEthernet0/0/0
10.0.3.0/24 OSPF 20 65545 D 10.0.124.2 GigabitEthernet0/0/0
10.0.4.0/24 OSPF 20 10 D 10.0.124.4 GigabitEthernet0/0/0
10.0.5.0/24 OSPF 20 131080 D 10.0.124.2 GigabitEthernet0/0/0
10.0.23.0/24 OSPF 20 65545 D 10.0.124.2 GigabitEthernet0/0/0
10.0.35.0/24 OSPF 20 131080 D 10.0.124.2 GigabitEthernet0/0/0
10.1.0.0/23 OSPF 20 131080 D 10.0.124.2 GigabitEthernet0/0/0
OSPF routing table status : <Inactive>
Destinations : 0 Routes : 0
路由优先级仅在本地有效,用于衡量在本地通过多种方式学到的路由的优略程度。本地区域的不同路由器,如果优先级信息不同,也可以正常工作。