静态路由

来源:互联网 发布:良辰好景知几何番外 编辑:程序博客网 时间:2024/04/29 07:56

1、静态路由与默认路由

直连路由:;路由器自动添加和自己直接连接的网络路由;

静态路由:管理员手动手动输入到路由表中的路由;

动态路由:由路由动态协议(Routing Protocol)动态建立的路由。

静态路由缺点是不能动态反映网络的拓扑,当网络拓扑变化时,管理员就必须手工改变路由表,这样对于大型网络的话就给我们带来很大不便了,然而静态路由却不会占用路由器的大量的CPU和RAM的资源了,也不会占用线路上的带宽。我们出于安全的考虑,可以在关键的路径上使用静态路由与动态路由相结合,例如出于安全的考虑想隐藏网络的某些或者我们想控制的数据转发路径,会经常使用静态路由。

配置静态路由的命令为“ip route”,格式如下:

Ip route 目的网络 掩码 {网关地址| 接口}

注意:

写静态路由时,如果链路是点到点的链路(如ppp 封装的链路),采用网关地址和接口都可以;但是如果链路为多路访问的链路(如以太网),则只能采用网关地址,而不能采用接口。

我们现在可以通过“show ip route”,来查看路由表:

R3#show ip route

Codes: 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

i - IS-IS, su - IS-IS summary, 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

R 1.0.0.0/8 [120/2] via 23.0.0.2, 00:00:00, Serial2/2

R 2.0.0.0/8 [120/1] via 23.0.0.2, 00:00:00, Serial2/2

3.0.0.0/24 is subnetted, 1 subnets

C 3.3.3.0 is directly connected, Loopback0

23.0.0.0/24 is subnetted, 1 subnets

C 23.0.0.0 is directly connected, Serial2/2

R 12.0.0.0/8 [120/1] via 23.0.0.2, 00:00:00, Serial2/2

R3#

在输出的列表中,我们可以就看到显示各种类型的简写。“C”为直连网络,“S”为静态网络,“B、D、O”分别表示采用了BGP、EIGRP、OSPF协议等。如下面:

R 1.0.0.0/8 [120/2] via 23.0.0.2, 00:00:00, Serial2/2

其中1.0.0.0/8表示目标网络,“via 23.0.0.2”它的下一跳为23.0.0.2,而Serial2/2则表示前往下一跳出去的端口,“[120/2]”是管理距离(Administrative Distance,AD)/度量值(Metric)。

技术要点

ü 管理距离(AD):表示路由的可信度,不同路径获取的路由可能采取不同路径到达

目的网络,所以我们为了区分不同的路由协议的可信度,采用管理距离加以表示。

路由协议的默认管理距离

路由协议

管理距离

直连路由

0

静态路由

1

外部BGP

20

内部EIGRP

90

IGRP

100

OSPF

110

RIP

120

外部EIGRP

170

内部BGP

200

ü 度量值(Metric):是由路由协议辨别到达目的网络的最佳路径的方法。但一个路

由器有多条路径到达同一目标网络时,路由协议必须判断其中哪一条是最佳前往目标网络并将其放入路由表中,而此时的路由协议会将每一条路径算出一个数,这个数就是我们称的度量值,无单位。度量值越小,表明这条路径越佳。

2、 默认路由

所谓的默认路由,就是指路由器中路由表中如果找不到前往目标网络的具体路径,最后会采用的路由。默认路由通常会在末梢网络中(Stub Network,即只有一个出口的网络)中使用。命令为:ip route 0.0.0.0 0.0.0.0 {网管地址|接口}。

在路由表中是否采用默认条目,还取决于路由器是否执行了“ip classless”,如果执行了,则路由器存在默认路由时,所有在路由表中查找不到的具体路由条目时,将会通过默认路由发送。但是如果执行了“no ip classless”命令,但路由器中存在一主类网络的某一子网路由时,路由器将会认为自己知道了该主类网络的全部子网的路由,这是即使存在默认路由,到达该主类任一子网的数据包是不会通过默认路由发送的。

静态路由

实验目的:

1、 路由表的概念

2、 Ip route 命令的使用

3、 根据要求正确配置静态路由

实验拓扑:

11

实验步骤:

1、 在各个路由器上配置IP地址,并保证直连链路的连通性(这个火星人都知道)

2、 在R1、R2、R3上分别配置静态路由

R1(config)#ip route 3.3.3.0 255.255.255.0 12.0.0.2 //目标网络3.3.3.0

R1(config)#ip route 2.2.2.2 255.255.255.255 12.0.0.2 //目标主机3.3.3.3,注意掩码

3、 在R1、R2、R3查看路由表

R1#show ip route

Codes: 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

i - IS-IS, su - IS-IS summary, 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

1.0.0.0/24 is subnetted, 1 subnets

C 1.1.1.0 is directly connected, Loopback0

2.0.0.0/32 is subnetted, 1 subnets

S 2.2.2.2 [1/0] via 12.0.0.2

3.0.0.0/24 is subnetted, 1 subnets

S 3.3.3.0 [1/0] via 12.0.0.2

12.0.0.0/24 is subnetted, 1 subnets

C 12.0.0.0 is directly connected, Serial2/1

R1#

R2#show ip route

Codes: 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

i - IS-IS, su - IS-IS summary, 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

1.0.0.0/24 is subnetted, 1 subnets

S 1.1.1.0 [1/0] via 12.0.0.1

2.0.0.0/24 is subnetted, 1 subnets

C 2.2.2.0 is directly connected, Loopback0

3.0.0.0/24 is subnetted, 1 subnets

S 3.3.3.0 [1/0] via 23.0.0.3

23.0.0.0/24 is subnetted, 1 subnets

C 23.0.0.0 is directly connected, Serial2/1

12.0.0.0/24 is subnetted, 1 subnets

C 12.0.0.0 is directly connected, Serial2/2

R2#

R3#show ip route

Codes: 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

i - IS-IS, su - IS-IS summary, 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

1.0.0.0/24 is subnetted, 1 subnets

S 1.1.1.0 [1/0] via 23.0.0.2

2.0.0.0/24 is subnetted, 1 subnets

S 2.2.2.0 [1/0] via 23.0.0.2

3.0.0.0/24 is subnetted, 1 subnets

C 3.3.3.0 is directly connected, Loopback0

23.0.0.0/24 is subnetted, 1 subnets

C 23.0.0.0 is directly connected, Serial2/2

R3#

4、 实验调试

R1#ping

Protocol [ip]:

Target IP address: 2.2.2.2 //目标ip地址

Repeat count [5]: //发送的ping次数

Datagram size [100]: //ping包的大小

Timeout in seconds [2]: //超时时间

Extended commands [n]: y //是否进一步扩展命令

Source address or interface: 1.1.1.1 //源IP地址

Type of service [0]:

Set DF bit in IP header? [no]:

Validate reply data? [no]:

Data pattern [0xABCD]:

Loose, Strict, Record, Timestamp, Verbose[none]:

Sweep range of sizes [n]:

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:

Packet sent with a source address of 1.1.1.1

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 4/42/88 ms

R1#

//从R1上的loopback0可以ping通R2上的loopbacl0,我们也可以直接使用以下命令:

R1#ping 2.2.2.2 source 1.1.1.1

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 2.2.2.2, timeout is 2 seconds:

Packet sent with a source address of 1.1.1.1

!!!!!

Success rate is 100 percent (5/5), round-trip min/avg/max = 8/30/44 ms

R1#

其他同理,需要指明源接口,虽然我们从R1的loopback0可以ping通R3上的loopback0,数据包需要经过23.0.0.0/24的路由。路由器转发数据包时完全根据路由表进行转发。但是当R1的loopback0口ping R3的loopback0时,IP数据包的源IP为1.1.1.1,目标IP为3.3.3.3.R1路由器首先查找路由表,数据包被发送到R2(12.0.0.2),R2路由器也进行路由表查询发现存在(3.3.3.0/24)路由条目,那么数据报被发送到了R3上,R3知道3.3.3.0/24为直连路由,那么R3就开始响应R1的数据包,进行的过程类似。

那么我们不添加源IP或接口会是什么现象呢?

R1#debug ip packet detail

IP packet debugging is on (detailed)

R1#ping 3.3.3.3

Type escape sequence to abort.

Sending 5, 100-byte ICMP Echos to 3.3.3.3, timeout is 2 seconds:

*Jul 23 13:41:34.727: IP: tableid=0, s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), routed via FIB

*Jul 23 13:41:34.731: IP: s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), len 100, sending

*Jul 23 13:41:34.735: ICMP type=8, code=0.

*Jul 23 13:41:36.727: IP: tableid=0, s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), routed via FIB

*Jul 23 13:41:36.731: IP: s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), len 100, sending

*Jul 23 13:41:36.731: ICMP type=8, code=0.

*Jul 23 13:41:38.727: IP: tableid=0, s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), routed via FIB

*Jul 23 13:41:38.731: IP: s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), len 100, sending

*Jul 23 13:41:38.731: ICMP type=8, code=0.

*Jul 23 13:41:40.735: IP: tableid=0, s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), routed via FIB

*Jul 23 13:41:40.739: IP: s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), len 100, sending

*Jul 23 13:41:40.743: ICMP type=8, code=0.

*Jul 23 13:41:42.747: IP: tableid=0, s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), routed via FIB

*Jul 23 13:41:42.751: IP: s=12.0.0.1 (local), d=3.3.3.3 (Serial2/1), len 100, sending

*Jul 23 13:41:42.755: ICMP type=8, code=0.

Success rate is 0 percent (0/5)

R1#u all

显示数据包发送出去没有响应,这是为什么呢?我们再次根据转发数据完全是根据路由表进行转发的。以上ping不同的原因是什么呢?在于我们使用ping命令时,如果不指明源接口的话,则R1路由器使用Serial2/1接口的IP地址(12.0.0.1)作为IP数据包的源IP地址。但是在R3上的路由表中不存在12.0.0.0/24的路由条目,所以在R3响应R1数据包时,数据包时无法发送回去!即:数据包从R1到了R3后,就无法回到R1了。

原创粉丝点击