OSPF实验记录
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OSPF实验记录相关的知识,希望对你有一定的参考价值。
R1配置
一、配置接口IP
[r1]interface GigabitEthernet0/0/0
[r1-GigabitEthernet0/0/0]ip address 12.0.0.1 255.255.255.252
[r1-GigabitEthernet0/0/0]quit
[r1]interface GigabitEthernet0/0/1
[r1-GigabitEthernet0/0/1]ip address 16.0.0.1 255.255.255.252
[r1-GigabitEthernet0/0/0]quit
[r1]interface LoopBack0
[r1-LoopBack0]ip address 1.1.1.1 255.255.255.255
[r1-LoopBack0]quit
<r1>display ip interface brief //查看接口IP信息
*down: administratively down
!down: FIB overload down
^down: standby
(l): loopback
(s): spoofing
(d): Dampening Suppressed
The number of interface that is UP in Physical is 4
The number of interface that is DOWN in Physical is 8
The number of interface that is UP in Protocol is 4
The number of interface that is DOWN in Protocol is 8
Interface IP Address/Mask Physical Protocol
Ethernet0/0/0 unassigned down down
Ethernet0/0/1 unassigned down down
GigabitEthernet0/0/0 12.0.0.1/30 up up
GigabitEthernet0/0/1 16.0.0.1/30 up up
GigabitEthernet0/0/2 unassigned down down
GigabitEthernet0/0/3 unassigned down down
LoopBack0 1.1.1.1/32 up up(s)
二、配置OSPF协议,将区域网段发布出去
[r1]ospf 1
[r1-ospf-1]area 1
[r1-ospf-1-area-0.0.0.1]
[r1-ospf-1-area-0.0.0.1]network 12.0.0.0 0.0.0.3
//将area 1区域中的接口网段发布出去,后面为反掩码
[r1-ospf-1-area-0.0.0.1]network 1.1.1.1 0.0.0.0
//将环回口也发布出去,另一个接口是和R6相连接的,不需要进行发布,而且运行的是RIP协议
[r1-ospf-1-area-0.0.0.1]
三、指定router id
- 第一种方法
[r1]router id 1.1.1.1 //指定router id,全局,所有协议都会使用这个router id
- 第二种方法
[r1]ospf 1 router-id 1.1.1.1 //只针对ospf指定router id
四、重启OSPF进程,使router id生效
<r1>reset ospf 1 process
<r1>dis ospf brief //查看OSPF的一些信息
五、配置与R6间的RIP协议
[r1]rip
[r1-rip-1]version 2
[r1-rip-1]undo summary
[r1-rip-1]network 16.0.0.0
六、查看RIP协议
[r1-rip-1]dis ip routing-table protocol rip
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Public routing table : RIP
Destinations : 1 Routes : 1
RIP routing table status : <Active>
Destinations : 1 Routes : 1
Destination/Mask Proto Pre Cost Flags NextHop Interface
6.6.6.6/32 RIP 100 1 D 16.0.0.2 GigabitEthernet 0/0/1
RIP routing table status : <Inactive>
Destinations : 0 Routes : 0
[r1-rip-1]
七、在R1进行一个路由引入的动作
- 1)把RIP路由引入到OSPF域
[r1]ospf 1
[r1-ospf-1]import-route rip 1 //把RIP引入到了OSPF,默认用的类型是type 2,即cost不累加
//在R3上通过<r3>dis ip routing-table 可以看到一条路由
6.6.6.6/32 O_ASE 150 1(这个1就是cost) D 23.0.0.1 GigabitEthernet 0/0/0
cost值是1,并没有累加,如果累加了应该是2
//再在R3上通过<r3>dis ospf routing 可以看到
Routing for ASEs
Destination Cost Type Tag NextHop AdvRouter
6.6.6.6/32 1 Type2 1 23.0.0.1 1.1.1.1
16.0.0.0/30 1 Type2 1 23.0.0.1 1.1.1.1
这里的Type是2,说明刚才的import-route rip 1命令默认是使用的类型2,即cost值不会累加
重新在R1配置该命令如下
[r1-ospf-1]import-route rip 1 type 1 cost 5
//手动设置为类型1,且设置cost值为5,那么经过R2到达R3 cost值应该变为了7
再在R3上通过<r3>dis ospf routing 来查看
Routing for ASEs
Destination Cost Type Tag NextHop AdvRouter
6.6.6.6/32 7 Type1 1 23.0.0.1 1.1.1.1
16.0.0.0/30 7 Type1 1 23.0.0.1 1.1.1.1
//验证确实cost变为了7
- 2)同时也把OSPF的域引入到RIP
[r1]rip
[r1-rip-1]import-route ospf 1
[r1-rip-1]dis th
#
rip 1
undo summary
version 2
network 16.0.0.0
import-route ospf 1
#
导入路由完成后在R1查看路由表
[r1-rip-1]dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 15 Routes : 15
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 Direct 0 0 D 127.0.0.1 LoopBack0
2.2.2.2/32 OSPF 10 1 D 12.0.0.2 GigabitEthernet 0/0/0
3.3.3.3/32 OSPF 10 2 D 12.0.0.2 GigabitEthernet 0/0/0
4.4.4.4/32 OSPF 10 3 D 12.0.0.2 GigabitEthernet 0/0/0
5.5.5.5/32 OSPF 10 4 D 12.0.0.2 GigabitEthernet 0/0/0
6.6.6.6/32 RIP 100 1 D 16.0.0.2 GigabitEthernet 0/0/1
12.0.0.0/30 Direct 0 0 D 12.0.0.1 GigabitEthernet 0/0/0
12.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
16.0.0.0/30 Direct 0 0 D 16.0.0.1 GigabitEthernet 0/0/1
16.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
23.0.0.0/30 OSPF 10 2 D 12.0.0.2 GigabitEthernet 0/0/0
34.0.0.0/30 OSPF 10 3 D 12.0.0.2 GigabitEthernet 0/0/0
45.0.0.0/30 OSPF 10 4 D 12.0.0.2 GigabitEthernet 0/0/0
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
在R6查看路由表
<r6>dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 14 Routes : 14
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
2.2.2.2/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
3.3.3.3/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
4.4.4.4/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
5.5.5.5/32 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
6.6.6.6/32 Direct 0 0 D 127.0.0.1 LoopBack0
12.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
16.0.0.0/30 Direct 0 0 D 16.0.0.2 GigabitEthernet 0/0/0
16.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
23.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
34.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
45.0.0.0/30 RIP 100 1 D 16.0.0.1 GigabitEthernet 0/0/0
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
<r6>ping 5.5.5.5 //测试从R6ping R5的环回口IP地址
PING 5.5.5.5: 56 data bytes, press CTRL_C to break
Reply from 5.5.5.5: bytes=56 Sequence=1 ttl=251 time=160 ms
Reply from 5.5.5.5: bytes=56 Sequence=2 ttl=251 time=170 ms
Reply from 5.5.5.5: bytes=56 Sequence=3 ttl=251 time=110 ms
Reply from 5.5.5.5: bytes=56 Sequence=4 ttl=251 time=120 ms
Reply from 5.5.5.5: bytes=56 Sequence=5 ttl=251 time=170 ms
--- 5.5.5.5 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 110/146/170 ms
<r5>ping 6.6.6.6 //再从R5ping R6的环回口IP地址
PING 6.6.6.6: 56 data bytes, press CTRL_C to break
Reply from 6.6.6.6: bytes=56 Sequence=1 ttl=251 time=160 ms
Reply from 6.6.6.6: bytes=56 Sequence=2 ttl=251 time=160 ms
Reply from 6.6.6.6: bytes=56 Sequence=3 ttl=251 time=120 ms
Reply from 6.6.6.6: bytes=56 Sequence=4 ttl=251 time=110 ms
Reply from 6.6.6.6: bytes=56 Sequence=5 ttl=251 time=160 ms
--- 6.6.6.6 ping statistics ---
5 packet(s) transmitted
5 packet(s) received
0.00% packet loss
round-trip min/avg/max = 110/142/160 ms
※备注
-
1、RID的选举,即router id的选举
一般默认从环回口选择一个最大的,如果环回口没有地址,就会从物理口选个最大的;
建议手动指定router id,这样心里有数,便于排错; - 2、DR的选举
在一个以太网里面router id大的是DR,第二大的是BDR;
在现网中也不会去关心,让他自己去选举就可以了;
R2配置
一、接口IP
interface GigabitEthernet0/0/0
ip address 12.0.0.2 255.255.255.252
#
interface GigabitEthernet0/0/1
ip address 23.0.0.1 255.255.255.252
#
interface LoopBack0
ip address 2.2.2.2 255.255.255.255
#
二、OSPF配置,指定router id,发布网段
[r2]ospf 10 router-id 2.2.2.2
//进程号多少无所谓,只有本地意义,这里使用的是10,同时指定router id
[r2-ospf-10]area 1
[r2-ospf-10-area-0.0.0.1]network 12.0.0.0 0.0.0.3
[r2-ospf-10-area-0.0.0.1]network 2.2.2.2 0.0.0.0
[r2-ospf-10-area-0.0.0.1]network 23.0.0.0 0.0.0.3
R3配置
一、接口IP
interface GigabitEthernet0/0/0
ip address 23.0.0.2 255.255.255.252
#
interface GigabitEthernet0/0/1
ip address 34.0.0.1 255.255.255.252
#
interface LoopBack0
ip address 3.3.3.3 255.255.255.255
#
二、OSPF配置,指定router id,发布网段
[r3]ospf 10 router-id 3.3.3.3
[r3-ospf-10]area 1
[r3-ospf-10-area-0.0.0.1]network 23.0.0.0 0.0.0.3
[r3-ospf-10-area-0.0.0.1]q
[r3-ospf-10]area 0
[r3-ospf-10-area-0.0.0.0]network 34.0.0.0 0.0.0.3
[r3-ospf-10-area-0.0.0.0]network 3.3.3.3 0.0.0.0 //环回口也可以放到区域1中
R4配置
一、接口IP
interface GigabitEthernet0/0/0
ip address 34.0.0.2 255.255.255.252
#
interface GigabitEthernet0/0/1
ip address 45.0.0.1 255.255.255.252
#
interface LoopBack0
ip address 4.4.4.4 255.255.255.255
#
二、OSPF配置,指定router id,发布网段
[r4]ospf 10 router-id 4.4.4.4
[r4-ospf-10]area 0
[r4-ospf-10-area-0.0.0.0]network 4.4.4.4 0.0.0.0
[r4-ospf-10-area-0.0.0.0]network 34.0.0.0 0.0.0.3
[r4-ospf-10-area-0.0.0.0]q
[r4-ospf-10]area 2
[r4-ospf-10-area-0.0.0.2]network 45.0.0.0 0.0.0.3
[r4-ospf-10-area-0.0.0.2]
三、查看OSPF的邻接关系
[r4-ospf-10-area-0.0.0.2]return //直接回到用户视图
<r4>display ospf peer brief
OSPF Process 10 with Router ID 4.4.4.4
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.0 GigabitEthernet0/0/0 3.3.3.3 Full
0.0.0.2 GigabitEthernet0/0/1 5.5.5.5 Full
----------------------------------------------------------------------------
//可以看到R4的邻接关系有3和5
四、查看OSPF接口的信息
<r4>dis ospf interface GigabitEthernet 0/0/0
OSPF Process 10 with Router ID 4.4.4.4
Interfaces
Interface: 34.0.0.2 (GigabitEthernet0/0/0)
Cost: 1 State: BDR Type: Broadcast MTU: 1500
Priority: 1
Designated Router: 34.0.0.1
Backup Designated Router: 34.0.0.2
Timers: Hello 10 , Dead 40 , Poll 120 , Retransmit 5 , Transmit Delay 1
关于上面的Cost:1的理解
OSPF协议是使用的带宽来作为度量值的,100M除以接口得到的带宽,
这里试验中应该是100M/1G得到的应该是一个小数,但是度量值不可能是一个小数,最小就是1;
这样导致接口是10G、1G、100M,得出的度量值都是1,不能真正区分出链路的优劣!
解决办法:
1、更改参考带宽的值,即将100M改为10G,或者100G,然后用更改后的值来除以接口,
但是需要在自治系统里的所有设备上进行更改,工作量巨大;
2、现网中一般采取直接给接口配置cost值;
如:
interface GigabitEthernet 0/0/0
ospf cost 10
//流量从cost小的走
R5配置
一、接口IP
interface GigabitEthernet0/0/0
ip address 45.0.0.2 255.255.255.252
#
interface LoopBack0
ip address 5.5.5.5 255.255.255.255
#
二、OSPF配置,指定router id,发布网段
[r5]ospf 10 router-id 5.5.5.5
[r5-ospf-10]area 2
[r5-ospf-10-area-0.0.0.2]network 45.0.0.0 0.0.0.3
[r5-ospf-10-area-0.0.0.2]network 5.5.5.5 0.0.0.0
三、查看OSPF的邻接关系
[r5]display ospf peer brief //查看OSPF的邻接关系
OSPF Process 10 with Router ID 5.5.5.5
Peer Statistic Information
----------------------------------------------------------------------------
Area Id Interface Neighbor id State
0.0.0.2 GigabitEthernet0/0/0 4.4.4.4 Full
----------------------------------------------------------------------------
//可以看到R5的邻接关系只有一个4
四、查看路由表,都学习到了
<r4>dis ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
Destinations : 13 Routes : 13
Destination/Mask Proto Pre Cost Flags NextHop Interface
1.1.1.1/32 OSPF 10 3 D 34.0.0.1 GigabitEthernet 0/0/0
2.2.2.2/32 OSPF 10 2 D 34.0.0.1 GigabitEthernet 0/0/0
3.3.3.3/32 OSPF 10 1 D 34.0.0.1 GigabitEthernet 0/0/0
4.4.4.4/32 Direct 0 0 D 127.0.0.1 LoopBack0
5.5.5.5/32 OSPF 10 1 D 45.0.0.2 GigabitEthernet 0/0/1
12.0.0.0/30 OSPF 10 3 D 34.0.0.1 GigabitEthernet 0/0/0
23.0.0.0/30 OSPF 10 2 D 34.0.0.1 GigabitEthernet 0/0/0
34.0.0.0/30 Direct 0 0 D 34.0.0.2 GigabitEthernet 0/0/0
34.0.0.2/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/0
45.0.0.0/30 Direct 0 0 D 45.0.0.1 GigabitEthernet 0/0/1
45.0.0.1/32 Direct 0 0 D 127.0.0.1 GigabitEthernet 0/0/1
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
R6配置
一、启用RIP
[r6]rip
[r6-rip-1]version 2 //启用版本2
[r6-rip-1]undo summary //关闭自动汇总
[r6-rip-1]network 6.0.0.0 //宣告自己的网段,只能宣告有类网段
[r6-rip-1]network 16.0.0.0
以上是关于OSPF实验记录的主要内容,如果未能解决你的问题,请参考以下文章