2024年6月13日发(作者:)

静态路由和默认路由

默认路由是一种特殊的静态路由,指的是当路由表中与包的目的地址之间没有匹配的表

项时路由器能够做出的选择.如果没有默认路由,那么目的地址在路由表中没有匹配表项的包

将被丢弃. 默认路由在某些时候非常有效,当存在末梢网络时,默认路由会大大简化路由器的

配置,减轻管理员的工作负担,提高网络性能。

默认路由配置方法

R0

R2

R1

默认路由的命令:

Ip route 0.0.0.0 0.0.0.0 下一跳路由地址 其中0.0.0.0 0.0.0.0 表述任意网络地址

具体配置

R0:配置默认路由

Router>

Router>

Router>en

Router#conf t

Router(config)#hostname R0 //更改路由器的名字为R0

R0(config)#ip route 0.0.0.0 0.0.0.0 192.168.20.2 //配置静态路由

R0(config)#end

R0#

%SYS-5-CONFIG_I: Configured from console by console

R0#show 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 192.168.20.2 to network 0.0.0.0

C 192.168.10.0/24 is directly connected, FastEthernet0/0

C 192.168.20.0/24 is directly connected, FastEthernet0/1

S* 0.0.0.0/0 [1/0] via 192.168.20.2

R0#

R2上的具体配置命令

Router>en

Router#conf t

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

Router(config)#hostname R2

R2(config)#ip route 0.0.0.0 0.0.0.0 192.168.30.1

R2(config)#end

R2#

%SYS-5-CONFIG_I: Configured from console by console

R2#show 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 192.168.30.1 to network 0.0.0.0

C 192.168.30.0/24 is directly connected, FastEthernet0/0

C 192.168.40.0/24 is directly connected, FastEthernet0/1

S* 0.0.0.0/0 [1/0] via 192.168.30.1

R2#

R1上配置静态路由

Router>en

Router#conf t

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

Router(config)#hostname R1

R1(config)#ip route 192.168.10.0 255.255.255.0 192.168.20.1

R1(config)#ip route 192.168.40.0 255.255.255.0 192.168.30.2

R1(config)#

测试

在pc0 上ping 192.168.40.1,验证结果通。