思科实验16.网络层:OSPF路由协议(上)

  • Post author:
  • Post category:其他




基础知识

OSPF路由协议是一种典型的链路状态(Link-state)的路由协议,一般用于同一个路由域内。在这里,路由域是指一个自治系统(Autonomous System),即AS,它是指一组通过统一的路由政策或路由协议互相交换路由信息的网络。在这个AS中,所有的OSPF路由器都维护一个相同的描述这个AS结构的数据库,该数据库中存放的是路由域中相应链路的状态信息,OSPF路由器正是通过这个数据库计算出其OSPF路由表的。

作为一种链路状态的路由协议,OSPF将链路状态组播数据LSA(Link State Advertisement)传送给在某一区域内的所有路由器,这一点与距离矢量路由协议不同。运行距离矢量路由协议的路由器是将部分或全部的路由表传递给与其相邻的路由器。—百度百科



常用命令

命令格式 含义
route ospf 进程号 进入ospf配置模式
network 网络地址 反掩码 area 区域号 通告直连网络区域
show ip route 查看路由表信息



实验流程

:root { --mermaid-font-family: "trebuchet ms", verdana, arial;}

开始

设计拓扑

配置主机IP地址

配置路由器各端口IP地址

封装OSPF协议

验证主机连通

在这里插入图片描述



1.配置主机IP地址

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述



2.配置路由器各端口IP地址

因为操作比较复杂,一步一步来,首先目的把各端口给上ip地址并把端口打开,使得网络在物理上连通,具体要封装的协议接下来再进行操作。



配置路由器0

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip address 192.168.10.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#exit
Router(config)#int g0/1
Router(config-if)#ip address 192.168.20.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#int s0/3/0
Router(config-if)#ip address 192.168.50.1 255.255.255.0
Router(config-if)#no shut



配置路由器1

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip address 192.168.30.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#exit
Router(config)#int g0/1
Router(config-if)#ip address 192.168.40.1 255.255.255.0
Router(config-if)#no shut
Router(config-if)#exit
Router(config)#int s0/3/0
Router(config-if)#ip address 192.168.60.1 255.255.255.0
Router(config-if)#no shut



配置路由器2

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip address 192.168.190.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#int g0/1
Router(config-if)#ip address 192.168.90.1 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#int s0/2/0
Router(config-if)#ip address 192.168.50.2 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#int s0/2/1
Router(config-if)#ip address 192.168.60.2 255.255.255.0
Router(config-if)#no shutdown



配置路由器3

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip address 192.168.190.2 255.255.255.0
Router(config-if)#no shutdown
Router(config-if)#exit
Router(config)#int g0/1
Router(config-if)#ip address 192.168.200.1 255.255.255.0
Router(config-if)#no shutdown



配置路由器4

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int g0/0
Router(config-if)#ip address 192.168.90.2 255.255.255.0
Router(config-if)#no shut
Router(config-if)#int g0/1
Router(config-if)#ip address 192.168.100.1 255.255.255.0
Router(config-if)#no shut

此时看起来已经通了,但是还没封装协议,所以是不能进行通信的,这里封装OSPF开放式最短路径优先协议。

在这里插入图片描述



3.封装OSPF协议



路由器0

Router(config)#route ospf ?
  <1-65535>  Process ID
Router(config)#route ospf 1
Router(config-router)#network 192.168.10.0 0.0.0.255 area 0
Router(config-router)#network 192.168.20.0 0.0.0.255 area 0
Router(config-router)#network 192.168.50.0 0.0.0.255 area 0



路由器1

Router(config)#route ospf 1
Router(config-router)#network 192.168.30.0 0.0.0.255 area 0
Router(config-router)#network 192.168.40.0 0.0.0.255 area 0
Router(config-router)#network 192.168.60.0 0.0.0.255 area 0



路由器2

Router(config)#route ospf 1
Router(config-router)#network 192.168.50.0 0.0.0.255 area 0
Router(config-router)#network 192.168.60.0 0.0.0.255 area 0
Router(config-router)#network 192.168.90.0 0.0.0.255 area 0
Router(config-router)#network 192.168.190.0 0.0.0.255 area 0

OK,OSPF协议封装完成,尝试一下

使用主机PC0ping主机PC1,2,5,6

C:\>ping 192.168.20.11

Pinging 192.168.20.11 with 32 bytes of data:

Request timed out.
Reply from 192.168.20.11: bytes=32 time<1ms TTL=127
Reply from 192.168.20.11: bytes=32 time<1ms TTL=127
Reply from 192.168.20.11: bytes=32 time<1ms TTL=127

Ping statistics for 192.168.20.11:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 0ms, Average = 0ms

C:\>ping 192.168.100.11

Pinging 192.168.100.11 with 32 bytes of data:

Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.

Ping statistics for 192.168.100.11:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

C:\>ping 192.168.200.11

Pinging 192.168.200.11 with 32 bytes of data:

Reply from 192.168.10.1: Destination host unreachable.
Request timed out.
Reply from 192.168.10.1: Destination host unreachable.
Reply from 192.168.10.1: Destination host unreachable.

Ping statistics for 192.168.200.11:
    Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

C:\>

可以看出在area区域内是可以连通的,之所以主机PC5和6无法连通,还要在路由器2设置默认路由

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ip route 0.0.0.0 0.0.0.0 192.168.90.2
Router(config)#ip route 0.0.0.0 0.0.0.0 192.168.190.2

查看一下路由器2的路由表

Router#show ip route
Codes: L - local, C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is 192.168.90.2 to network 0.0.0.0

O    192.168.10.0/24 [110/65] via 192.168.50.1, 00:15:35, Serial0/2/0
O    192.168.20.0/24 [110/65] via 192.168.50.1, 00:15:35, Serial0/2/0
O    192.168.30.0/24 [110/65] via 192.168.60.1, 00:15:25, Serial0/2/1
O    192.168.40.0/24 [110/65] via 192.168.60.1, 00:15:25, Serial0/2/1
     192.168.50.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.50.0/24 is directly connected, Serial0/2/0
L       192.168.50.2/32 is directly connected, Serial0/2/0
     192.168.60.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.60.0/24 is directly connected, Serial0/2/1
L       192.168.60.2/32 is directly connected, Serial0/2/1
     192.168.90.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.90.0/24 is directly connected, GigabitEthernet0/1
L       192.168.90.1/32 is directly connected, GigabitEthernet0/1
     192.168.190.0/24 is variably subnetted, 2 subnets, 2 masks
C       192.168.190.0/24 is directly connected, GigabitEthernet0/0
L       192.168.190.1/32 is directly connected, GigabitEthernet0/0
S*   0.0.0.0/0 [1/0] via 192.168.90.2
               [1/0] via 192.168.190.2

最后两行路由表就是默认路由

然后下发缺省路由

路由器2

Router(config)#route ospf 1
Router(config-router)#default-information originate 

然后再配置两个静态路由

路由器4

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ip route 192.168.0.0 255.255.0.0 192.168.90.1

路由器3

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#ip route 192.168.0.0 255.255.0.0 192.168.190.1



4.验证主机连通

OK,此刻就可以连通了,尝试一下

主机PC0ping主机PC5,4

C:\>ping 192.168.200.11

Pinging 192.168.200.11 with 32 bytes of data:

Reply from 192.168.200.11: bytes=32 time=1ms TTL=125
Reply from 192.168.200.11: bytes=32 time=1ms TTL=125
Reply from 192.168.200.11: bytes=32 time=3ms TTL=125
Reply from 192.168.200.11: bytes=32 time=3ms TTL=125

Ping statistics for 192.168.200.11:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 3ms, Average = 2ms

C:\>ping 192.168.100.11

Pinging 192.168.100.11 with 32 bytes of data:

Request timed out.
Reply from 192.168.100.11: bytes=32 time=3ms TTL=125
Reply from 192.168.100.11: bytes=32 time=4ms TTL=125
Reply from 192.168.100.11: bytes=32 time=7ms TTL=125

Ping statistics for 192.168.100.11:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 3ms, Maximum = 7ms, Average = 4ms

C:\>

可以连通了



版权声明:本文为qq_44862120原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。