ip default-network和ip route 0.0.0.0 0.0.0.0默认路由的区别
指定默认路由(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 routing
mycisco(config)# ip default-gateway 192.168.0.1
mycisco(config)#end
mycisco#ping [url]www.flashku.com[/url]
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-tr ip min/avg/max = 60/60/60 ms
mycisco#show ip route
Default gateway is 192.168.0.1
Host Gateway Last Use Total Uses Interface
ICMP redirect cache is empty
mycisco#
ip route例子:
ip route 0.0.0.0 0.0.0.0 192.168.0.1
mycisco#ping [url]www.flashku.com[/url]
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-tr ip min/avg/max = 56/56/60 ms
mycisco#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
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 route
Gateway of last resort is 192.168.0.1 to network 0.0.0.0
C 1.0.0.0/8 is directly connected, Loopback0
C 192.168.0.0/24 is directly connected, Ethernet0
S* 0.0.0.0/0 [1/0] via 192.168.0.1
mycisco#
ip default-network 必须是在所到网络已经存在路由的情况下,否则执行无效.
mycisco(config)# ip route 61.0.0.0 255.0.0.0 192.168.0.1
mycisco#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
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 route
Gateway of last resort is not set
C 1.0.0.0/8 is directly connected, Loopback0
S 61.0.0.0/8 [1/0] via 192.168.0.1
C 192.168.0.0/24 is directly connected, Ethernet0
接着我们执行:
mycisco(config)# ip default-network 61.0.0.0
再看路由表:
mycisco#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
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 route
Gateway of last resort is 192.168.0.1 to network 61.0.0.0
C 1.0.0.0/8 is directly connected, Loopback0
S* 61.0.0.0/8 [1/0] via 192.168.0.1
C 192.168.0.0/24 is directly connected, Ethernet0
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 routing
mycisco(config)# ip default-gateway 192.168.0.1
mycisco(config)#end
mycisco#ping [url]www.flashku.com[/url]
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-tr ip min/avg/max = 60/60/60 ms
mycisco#show ip route
Default gateway is 192.168.0.1
Host Gateway Last Use Total Uses Interface
ICMP redirect cache is empty
mycisco#
ip route例子:
ip route 0.0.0.0 0.0.0.0 192.168.0.1
mycisco#ping [url]www.flashku.com[/url]
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-tr ip min/avg/max = 56/56/60 ms
mycisco#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
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 route
Gateway of last resort is 192.168.0.1 to network 0.0.0.0
C 1.0.0.0/8 is directly connected, Loopback0
C 192.168.0.0/24 is directly connected, Ethernet0
S* 0.0.0.0/0 [1/0] via 192.168.0.1
mycisco#
ip default-network 必须是在所到网络已经存在路由的情况下,否则执行无效.
mycisco(config)# ip route 61.0.0.0 255.0.0.0 192.168.0.1
mycisco#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
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 route
Gateway of last resort is not set
C 1.0.0.0/8 is directly connected, Loopback0
S 61.0.0.0/8 [1/0] via 192.168.0.1
C 192.168.0.0/24 is directly connected, Ethernet0
接着我们执行:
mycisco(config)# ip default-network 61.0.0.0
再看路由表:
mycisco#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
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 route
Gateway of last resort is 192.168.0.1 to network 61.0.0.0
C 1.0.0.0/8 is directly connected, Loopback0
S* 61.0.0.0/8 [1/0] via 192.168.0.1
C 192.168.0.0/24 is directly connected, Ethernet0
转载于:https://blog.51cto.com/yuxin/267414