指定默认路由(last resort gateway)的指令供有3种,可以分成两类:
1、ip default-gateway当路由器上的ip routing无效时,使用它指定默认路由,用于RXBoot模式(no ip routing)下安装IOS等。或者关闭ip routing 让路由器当主机用,此时需要配置默认网关2、ip default-network和ip route 0.0.0.0 0.0.0.0两者都用于ip routing有效的路由器上,区别主要在于路由协议是否传播这条路由信息。比如:IGRP无法识别0.0.0.0,因此传播默认路由时必须用ip default-network。当用ip default-network指令设定多条默认路由时,administrative distance最短的成为最终的默认路由;如果有复数条路由distance值相等,那么在路由表(show ip route)中靠上的成为默认路由。同时使用ip default-network和ip route 0.0.0.0 0.0.0.0双方设定默认路由时,如果ip default-network设定的网络是直连(静态、且已知)的,那么它就成为默认路由;如果ip default-network指定的网络是由交换路由信息得来的,则ip route 0.0.0.0 0.0.0.0指定的表项成为默认路由。最后,如果使用多条ip route 0.0.0.0 0.0.0.0指令,则流量会自动在多条链路上负载均衡。例子:关闭ip routing 举例:myCisco(config)#no ip routingmyCisco(config)#ip default-gateway 192.168.0.1myCisco(config)#endmycisco#ping Type escape sequence to abort.Sending 5, 100-byte ICMP Echoes to 61.152.167.75, timeout is 2 seconds:!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max = 60/60/60 msmycisco#show ip routeDefault gateway is 192.168.0.1Host Gateway Last Use Total Uses InterfaceICMP redirect cache is emptymycisco#ip route例子:ip route 0.0.0.0 0.0.0.0 192.168.0.1mycisco#ping Type escape sequence to abort.Sending 5, 100-byte ICMP Echoes to 61.152.167.75, timeout is 2 seconds:!!!!!Success rate is 100 percent (5/5), round-trip min/avg/max = 56/56/60 msmycisco#show ip routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 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, * - candidate default U - per-user static routeGateway of last resort is 192.168.0.1 to network 0.0.0.0C 1.0.0.0/8 is directly connected, Loopback0C 192.168.0.0/24 is directly connected, Ethernet0S* 0.0.0.0/0 [1/0] via 192.168.0.1mycisco#ip default-network必须是在所到网络已经存在路由的情况下,否则执行无效.mycisco(config)#ip route 61.0.0.0 255.0.0.0 192.168.0.1mycisco#show ip routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 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, * - candidate default U - per-user static routeGateway of last resort is not setC 1.0.0.0/8 is directly connected, Loopback0S 61.0.0.0/8 [1/0] via 192.168.0.1C 192.168.0.0/24 is directly connected, Ethernet0接着我们执行:mycisco(config)#ip default-network 61.0.0.0再看路由表:mycisco#show ip routeCodes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area 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, * - candidate default U - per-user static routeGateway of last resort is 192.168.0.1 to network 61.0.0.0C 1.0.0.0/8 is directly connected, Loopback0S* 61.0.0.0/8 [1/0] via 192.168.0.1C 192.168.0.0/24 is directly connected, Ethernet0下面介绍怎么样去配置一个默认路由 ip default-gateway ip default-network ip route 0.0.0.0 0.0.0.01.ip default-gatewayip default-gateway这个命令与其他2个不同,他只能用在路由器ip routing 关闭的时候。就是说在ip rouing 启动时这条路由不会放到路由表中命令实例:ip default-gateway 192.168.0.12.ip default-network 与ip default-gateway 不同的是,他可以在ip routing环境下使用,当你配置了这条命令后,路由器将会把这条路由当成网关和最后一个条目开匹配。当在一个网络中用ip default-network 指定了一条可达的路径,这条路径将会在路由表中被标记为*号要注意的是,ip default-network命令是一个有类的命令(classfull),如果宣告的网络不是主类网,将不会被标记成*号
EX:(图见上)2513#configure terminal2513(config)#ip route 171.70.24.0 255.255.255.0 131.108.99.22513(config)#ip defaultnetwork 171.70.24.0路由表: 171.70.0.0/16 is variably subnetted, 2 subnets, 2 masksS 171.70.0.0/16 [1/0] via 171.70.24.0(没有*号)S 171.70.24.0/24 [1/0] via 131.108.99.2161.44.0.0/24 is subnetted, 1 subnetsC 161.44.192.0 is directly connected, Ethernet0131.108.0.0/24 is subnetted, 1 subnetsC 131.108.99.0 is directly connected, Serial0S* 198.10.1.0/24 [1/0] via 161.44.192.2如果想在路由表里标记路由就只有直接宣告主类网络2513(config)# ip defaultnetwork 171.70.0.0总结一下当我们用ip defaultnetwork宣告网络时,如果宣告的不是主类网络,路由表就不会标记为*。而是多出一条静态路由(RUN里面也有),如果宣告的是主类网络就会标记为*号。(这是没有路由协议的情况)在有路由协议的环境下:IGRP/EIGRP:ip default-network 宣告的网络必须是被EIGRP或IGRP或重分布进来的路由RIP:ip default-network 宣告的网络被标记为R*IS-IS/OSPF:不支持2.ip route 0.0.0.0 0.0.0.0创建一条静态路由到网络0.0.0.0 0.0.0.0是做默认路由的另一个方法,与ip default-network一样,ip route 0.0.0.0 0.0.0.0 同样不用依赖任何路由协议,但是ip routing必须打开。IGRP不能理解ip route 0.0.0.0 0.0.0.0这条命令,EIGRP可以用这条命令,但是这条命令如果来自一条静态路由,则必须将这条静态路由重发布进EIGRP中!在rip早期版本中,ip route 0.0.0.0 0.0.0.0会自动发布,但在CISCO IOS 12.0T之后,发布的路由必须是RIP所学到或重分布进来的,OSPF ISIS同样不支持,可以用defaultinformation originate来进行发布。