配置OSPF协议<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

OSPF配置的基本元素:

1 启用OSPF

2 配置OSPF地区

 

链路状态路由协议对以下信息进行跟踪:

1 邻居信息

2 本区域内的所有路由器

3 到达网络目标的最佳方式

 

OSPF引入了区域的概念,OSPF区域分为2种:

1 骨干区域。(area0

2 常规区域

注意:所有的常规区域必须和骨干区域相连。

OSPF的邻接关系的建立是依赖于hello包的。

DRBDR的选举:

DRBDR的选择是通过HELLO协议来完成的,在每个网络分段上,HELLO数据包是通过IP组播来交换的,然而,只有在广播和非广播的多路访问网络。在广播和非广播的多路访问网络上,网络分段中带有最高OSPF优先级的路由器将会成为本网络分段中的DR,这个优先级在默认时取值为1。如果所有的路由器都使用默认优先级,那么带有最高路由器RID的路由器会胜出。

 

OSPF和环回接口:

不管路由器是否配置OSPF,都最好配置一个环回接口,环回接口是些逻辑接口,并不是真正的路由器接口,在OSPF配置中使用环回接口,是为了确保在OSPF进程中总有一个激活的接口。

 

OSPF的优点:

1 对网络发生的变化能够快速反应

2 当网络发生变化时发送触发式更新(triggered update)

3 支持VLSM

4 方便管理

 

配置单区域的OSPF

Router(config)#router ospf process-id

启用OSPF

Router(config-router)#network address wild card bits area area-id

将网段指派到指定的区域中

试验配置单区域的OSPF拓扑图:

实验环境介绍:

R1ip地址为192.168.6.2 (E1/0)   192.168.7.1 (S0/0)   网络掩码为255.255.255.0

R2ip地址为 192.168.7.2 (S0/0)   192.168.8.1S0/1 网络掩码为255.255.255.0

R3ip地址为192.168.8.2 (S0/1)    192.168.9.1(E1/0)   网络掩码为255.255.255.0

R1S0/0  R2S0/1 DCE

PC1ip地址为192.168.6.1 网络掩码为 255.255.255.0

PC2ip地址为192.168.9.2 网络掩码为 255.255.255.

Process-id100

area0

实验要求;

通过路由器配置单区域OSPF协议,是PC1PC2互通,实现全网全通!

下面开始配置:

R1

Router>en

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#host r1

r1(config)#int e1/0

r1(config-if)#ip addr 192.168.6.2 255.255.255.0

r1(config-if)#no shut

r1(config-if)#exit

r1(config)#int s0/0

r1(config-if)#ip addr 192.168.7.1 255.255.255.0

r1(config-if)#clock rate 64000

r1(config-if)#no shut

r1(config-if)#exit

r1(config)#router ospf 100

r1(config-router)#network 192.168.6.2 <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />0.0.0.0 area 0

r1(config-router)#network 192.168.7.1 0.0.0.0 area

R2

Router>en

Router#conf

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#host r2

r2(config)#int s0/0

r2(config-if)#ip addr 192.168.7.2 255.255.255.0

r2(config-if)#no shut

r2(config-if)#exit

r2(config)#int s0/1

r2(config-if)#ip addr 192.168.8.1 255.255.255.0

r2(config-if)#clock rate 64000

r2(config-if)#no shut

r2(config-if)#exit

r2(config)#router ospf 100

r2(config-router)#network 192.168.7.2 0.0.0.0 area 0

r2(config-router)#network 192.168.8.1 0.0.0.0 area 0

R3

Router>en

Router#conf t

Enter configuration commands, one per line.  End with CNTL/Z.

Router(config)#host r3

r3(config)#int s0/1

r3(config-if)#ip addr 192.168.8.2 255.255.255.0

r3(config-if)#no shut

r3(config-if)#exit

r3(config)#int e1/0

r3(config-if)#ip addr 192.168.9.1 255.255.255.0

r3(config-if)#no shut

r3(config-if)#exit

r3(config)#router ospf 100

r3(config-router)#network 192.168.8.2 0.0.0.0 area 0

r3(config-router)#network 192.168.9.1 0.0.0.0 area 0

PC机的配置:

VPCS 1 >ip 192.168.6.1 192.168.6.2

PC1 : 192.168.6.1 255.255.255.0 gateway 192.168.6.2

 

VPCS 1 >2

VPCS 2 >ip 192.168.9.2 192.168.9.1

PC2 : 192.168.9.2 255.255.255.0 gateway 192.168.9.

如果是PC1PC2Ping通,那就说明全网全通!

VPCS 2 >ping 192.168.6.1

192.168.6.1 icmp_seq=1 timeout

192.168.6.1 icmp_seq=2 time=157.000 ms

192.168.6.1 icmp_seq=3 time=297.000 ms

192.168.6.1 icmp_seq=4 time=172.000 ms

192.168.6.1 icmp_seq=5 time=172.000 ms

VPCS 2 >ping 192.168.9.2

192.168.9.2 icmp_seq=1 time =157.000 ms

192.168.9.2 icmp_seq=2 time=157.000 ms

192.168.9.2 icmp_seq=3 time=297.000 ms

192.168.9.2 icmp_seq=4 time=172.000 ms

 

192.168.9.2 icmp_seq=5 time=172.000 ms

下面分别在R1/R2/R3Show ip router查看路由协议,表明路由器通过OSPF实现全网全通的!

R1

 

r1#show ip protocols

Routing Protocol is "ospf 100"

  Outgoing update filter list for all interfaces is not set

  Incoming update filter list for all interfaces is not set

  Router ID 192.168.7.1

  Number of areas in this router is 1. 1 normal 0 stub 0 nssa

  Maximum path: 4

  Routing for Networks:

    192.168.6.2 0.0.0.0 area 0

    192.168.7.1 0.0.0.0 area 0

 Reference bandwidth unit is 100 mbps

  Routing Information Sources:

    Gateway         Distance      Last Update

    192.168.9.1          110      00:04:49

    192.168.8.1          110      00:04:49

  Distance: (default is 110)

R2

r2>show ip protocols

Routing Protocol is "ospf 100"

  Outgoing update filter list for all interfaces is not set

  Incoming update filter list for all interfaces is not set

  Router ID 192.168.8.1

  Number of areas in this router is 1. 1 normal 0 stub 0 nssa

  Maximum path: 4

  Routing for Networks:

    192.168.7.2 0.0.0.0 area 0

    192.168.8.1 0.0.0.0 area 0

 Reference bandwidth unit is 100 mbps

  Routing Information Sources:

    Gateway         Distance      Last Update

    192.168.9.1          110      00:05:23

    192.168.7.1          110      00:05:23

  Distance: (default is 110)

R3

r3#show ip protocols

Routing Protocol is "ospf 100"

  Outgoing update filter list for all interfaces is not set

  Incoming update filter list for all interfaces is not set

  Router ID 192.168.9.1

  Number of areas in this router is 1. 1 normal 0 stub 0 nssa

  Maximum path: 4

  Routing for Networks:

    192.168.8.2 0.0.0.0 area 0

    192.168.9.1 0.0.0.0 area 0

 Reference bandwidth unit is 100 mbps

  Routing Information Sources:

    Gateway         Distance      Last Update

    192.168.8.1          110      00:06:20

    192.168.7.1          110      00:06:20

  Distance: (default is 110)

下面可以用命令查看配置:

查看启用的路由协议

Router#show ip protocols

查看路由表

Router#show ip route

查看区域号和与此相关的信息

Router#show ip ospf interface

查看在每一个接口上的邻居信息

Router#show ip ospf neighbor

 

 

到这配置试验就完成了