静态路由协议
交换机 :负责本网段内直接转发
路由器 :在不同网段内间接转发
静态路由 :手动输入到路由表,不占用网络带宽。不会随着网络的拓扑变化而变化,缺少灵活性
动态路由 :动态学习得到的路由,占用网络带宽和资源,会随着网络的拓扑变化而变化,非常灵活
clip_p_w_picpath002
我的简单实验拓扑图
其中ru1 为DTE段 配置时钟频率
Ru1 的s0/0连接ru2 的 s0/0 口
Ru1的f0/0 连接 pc1的快速以太网 接口
Ru2 的f0/0 连接 pc2的快速以太网接口
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int s0/0
Router(config-if)#ip add 192.168.1.1 255.255.255.0
Router(config-if)#clock rate 64000
Router(config-if)#no shut
%LINK-5-CHANGED: Interface Serial0/0, changed state to down
Router(config-if)#exit
Router(config)#int f0/0
Router(config-if)#ip add 172.16.1.1 255.255.255.0
Router(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#host ru1
ru1(config)#
ru1 上的基本配置
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host ru2
ru2(config)#int s0/0
ru2(config-if)#ip add 192.168.1.2 255.255.255.0
ru2(config-if)#no shut
%LINK-5-CHANGED: Interface Serial0/0, changed state to up
ru2(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/0, changed state to up
ru2(config-if)#exit
ru2(config)#int f0/0
ru2(config-if)#ip add 172.16.2.1 255.255.255.0
ru2(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
ru2(config-if)#exit
ru2(config)#
ru2上的基本配置
ru1(config)#ip route 172.16.2.0 255.255.255.0 192.168.1.2
#ru1 上配置静态路由
# 命令为ip route 目标网段 目标网段的子网掩码 下一跳ip
如果不用下一跳ip也可以用接口来表示
ru1(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ru1#sh ip route
Codes: C - connected, S - static, I - IGRP, 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 not set
172.16.0.0/24 is subnetted, 2 subnets
C 172.16.1.0 is directly connected, FastEthernet0/0
S 172.16.2.0 [1/0] via 192.168.1.2
C 192.168.1.0/24 is directly connected, Serial0/0
ru1#
ru2 上作配置如下
ru2(config)#ip route 172.16.1.0 255.255.255.0 192.168.1.1
ru2(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ru2#sh ip route
# 这里我们可以用 sh ip route 来查看路由表
Codes: C - connected, S - static, I - IGRP, 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 not set
172.16.0.0/24 is subnetted, 2 subnets
S 172.16.1.0 [1/0] via 192.168.1.1
C 172.16.2.0 is directly connected, FastEthernet0/0
C 192.168.1.0/24 is directly connected, Serial0/0
ru2#
# 表中显示S 为学到的路由信息 C为直链网段
下面我们 用ping命令测试一下连通性如何
ru2#ping 192.168.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/34/47 ms
# 我们ping ru1 的s0/0 接口
# 五个叹号显示是通的 五个…..的意思是不通
ru2#ping 172.16.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 172.16.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/34/47 ms
ru2#
我们在pc2上配好ip 之后ipconfig 显示一下
Ping一下 pc1的ip 172..16.1.2 看看连通性如何
clip_p_w_picpath004
选择ip配置
clip_p_w_picpath006
Packet Tracer PC Command Line 1.0
PC>ipconfig
IP Address......................: 172.16.2.2
Subnet Mask.....................: 255.255.0.0
Default Gateway.................: 172.16.2.1
PC>ping 172.16.1.2
Pinging 172.16.1.2 with 32 bytes of data:
Request timed out.
Reply from 172.16.1.2: bytes=32 time=125ms TTL=126
Reply from 172.16.1.2: bytes=32 time=94ms TTL=126
Reply from 172.16.1.2: bytes=32 time=93ms TTL=126
Ping statistics for 172.16.1.2:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 93ms, Maximum = 125ms, Average = 104ms
PC>
结果显示良好 全通
接下来我们考虑一个问题就是如果新增加一个路由的话路由表里面我们应该是如何进行配置
clip_p_w_picpath008
ru2>en
ru2#conft
Translating "conft"...domain server (255.255.255.255) % Name lookup aborted
ru2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
ru2(config)#int s0/1
ru2(config-if)#ip add 192.168.2.1 255.255.255.0
ru2(config-if)#clock rate 64000
ru2(config-if)#no shut
%LINK-5-CHANGED: Interface Serial0/1, changed state to up
ru2(config-if)#exit
ru2(config)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/1, changed state to up
ru2(config)#
ru3 上的配置
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#host ru3
ru3(config)#int s0/0
ru3(config-if)#ip add 192.168.2.2 255.255.255.0
ru3(config-if)#no shut
%LINK-5-CHANGED: Interface Serial0/0, changed state to down
ru3(config-if)#exit
ru3(config)#
ru3(config)#int f0/0
ru3(config-if)#ip add 172.16.3.1 255.255.255.0
ru3(config-if)#no shut
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
ru3(config-if)#exit
ru3(config)#
以上是ru3 上的基本配置
ru1>en
ru1#conf t
Enter configuration commands, one per line. End with CNTL/Z.
ru1(config)#ip route 172.16.3.0 255.255.255.0 192.168.1.2
ru1(config)#ip route 192.168.2.0 255.255.255.0 192.168.1.2
ru1(config)#
ru1(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ru1#sh ip route
Codes: C - connected, S - static, I - IGRP, 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 not set
172.16.0.0/24 is subnetted, 3 subnets
C 172.16.1.0 is directly connected, FastEthernet0/0
S 172.16.2.0 [1/0] via 192.168.1.2
S 172.16.3.0 [1/0] via 192.168.1.2
C 192.168.1.0/24 is directly connected, Serial0/0
S 192.168.2.0/24 [1/0] via 192.168.1.2
ru1#
ru2>
ru2>en
ru2#conf t
Enter configuration commands, one per line. End with CNTL/Z.
ru2(config)#ip route 172.16.3.0 255.255.255.0 192.168.2.2
ru2(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ru2#sh ip route
Codes: C - connected, S - static, I - IGRP, 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 not set
172.16.0.0/24 is subnetted, 3 subnets
S 172.16.1.0 [1/0] via 192.168.1.1
C 172.16.2.0 is directly connected, FastEthernet0/0
S 172.16.3.0 [1/0] via 192.168.2.2
C 192.168.1.0/24 is directly connected, Serial0/0
C 192.168.2.0/24 is directly connected, Serial0/1
ru2#
以上是ru2新添加的步骤
ru3>
ru3>
ru3>en
ru3#conf t
Enter configuration commands, one per line. End with CNTL/Z.
ru3(config)#ip route 172.16.2.0 255.255.255.0 192.168.2.1
ru3(config)#ip route 172.16.1.0 255.255.255.0 192.168.2.1
ru3(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
ru3(config)#exit
%SYS-5-CONFIG_I: Configured from console by console
ru3#sh ip route
Codes: C - connected, S - static, I - IGRP, 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 not set
172.16.0.0/24 is subnetted, 3 subnets
S 172.16.1.0 [1/0] via 192.168.2.1
S 172.16.2.0 [1/0] via 192.168.2.1
C 172.16.3.0 is directly connected, FastEthernet0/0
S 192.168.1.0/24 [1/0] via 192.168.2.1
C 192.168.2.0/24 is directly connected, Serial0/0
ru3#
ru3 上的具体配置
Packet Tracer PC Command Line 1.0
PC>ipconfig
IP Address......................: 172.16.3.2
Subnet Mask.....................: 255.255.0.0
Default Gateway.................: 172.16.3.1
PC>ping 172.16.2.2
Pinging 172.16.2.2 with 32 bytes of data:
Request timed out.
Reply from 172.16.2.2: bytes=32 time=109ms TTL=126
Reply from 172.16.2.2: bytes=32 time=63ms TTL=126
Reply from 172.16.2.2: bytes=32 time=47ms TTL=126
Ping statistics for 172.16.2.2:
Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
Minimum = 47ms, Maximum = 109ms, Average = 73ms
PC>ping 172.16.1.2
Pinging 172.16.1.2 with 32 bytes of data:
Reply from 172.16.1.2: bytes=32 time=188ms TTL=125
Reply from 172.16.1.2: bytes=32 time=125ms TTL=125
Reply from 172.16.1.2: bytes=32 time=110ms TTL=125
Reply from 172.16.1.2: bytes=32 time=125ms TTL=125
Ping statistics for 172.16.1.2:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 110ms, Maximum = 188ms, Average = 137ms
PC>
我在pc3 上ping其他两个pc的连通情况 结果都是通的
这里简单的说一下一个包为什么会超时 设计一个icmp协议与arp解析的问题 就是说我们一个包出去一个包回来 第一个出去的时候对方的相应时间非常短 所以返回的时候就会显示time out 即超时
静态路由就简单得介绍到这里