思科静态配置命令
静态路由的配置命令如下:
router(config)# ip route 目的网络 网络掩码 下一跳地址/出接口
默认路由的配置命令如下:
router(config)# ip route 0.0.0.0 0.0.0.0 下一跳地址/出接口
实验配置:
1、常规配置
R1
Router> enable
Router# configure terminal
Router(config)# hostname R1
R1(config-if)# interface fastethernet 0/0
R1(config-if)# ip address 192.168.1.254 255.255.255.0
R1(config-if)# no shutdown
R1(config)# interface serial 1/0
R1(config-if)# ip address 192.168.12.1 255.255.255.0
R1(config-if)# no shutdown
R2
Router> enable
Router# configure terminal
Router(config)# hostname R2
R2(config)# interface serial 1/1
R2(config-if)# clock rate 64000 //DCE端配置时钟频率
R2(config-if)# ip address 192.168.12.2 255.255.255.0
R2(config-if)# no shutdown
R2(config-if)# interface serial 1/2
R2(config-if)# clock rate 64000 //DCE端配置时钟频率
R2(config-if)# ip address 192.168.23.2 255.255.255.0
R2(config-if)# no shutdown
R3
Router> enable
Router# configure terminal
Router(config)# hostname R3
R3(config-if)# interface fastethernet 0/0
R3(config-if)# ip address 192.168.2.254 255.255.255.0
R3(config-if)# no shutdown
R3(config)# interface serial 1/0
R3(config-if)# ip address 192.168.23.3 255.255.255.0
R3(config-if)# no shutdown
PC0
PC1
测试 1:
查看各设备直连接口状态。
结论:
各设备通过命令 show ip intereface brief 检测到各接口状态和协议双 up。
思考:
若某接口的 Status up,Protocol down 是为什么?
测试 2:
查看路由器直连网段是否能 ping 通。
结论:
直链同网段都能通信
2、配置静态路由,使 PC 之间可以互相通信
R1
//R1 配置去往 192.168.23.0/24 及 192.168.2.0/24 网段的路由
R1(config)# ip route 192.168.2.0 255.255.255.0 192.168.12.2
R1(config)# ip route 192.168.23.0 255.255.255.0 192.168.12.2
R1#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 not set
C 192.168.1.0/24 is directly connected, FastEthernet0/0
S 192.168.2.0/24 [1/0] via 192.168.12.2
C 192.168.12.0/24 is directly connected, Serial1/0
S 192.168.23.0/24 [1/0] via 192.168.12.2
路由条目中C就是Static 即 静态路由
路由条目中的 [1/0] 意思是路由的 [管理距离/度量值]。
路由条目中的 via 192.168.12.2,是下一跳 IP 地址。
R2
R2(config)#ip route 192.168.1.0 255.255.255.0 192.168.12.1
R2(config)#ip route 192.168.2.0 255.255.255.0 192.168.23.3
R2(config)#end
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 not set
S 192.168.1.0/24 [1/0] via 192.168.12.1
S 192.168.2.0/24 [1/0] via 192.168.23.3
C 192.168.12.0/24 is directly connected, Serial1/1
C 192.168.23.0/24 is directly connected, Serial1/2
R2#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 80 percent (4/5), round-trip min/avg/max = 1/5/11 ms
R3
R3(config)#ip route 192.168.1.0 255.255.255.0 192.168.23.2
R3(config)#ip route 192.168.12.0 255.255.255.0 192.168.23.2
R3#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 not set
S 192.168.1.0/24 [1/0] via 192.168.23.2
C 192.168.2.0/24 is directly connected, FastEthernet0/0
S 192.168.12.0/24 [1/0] via 192.168.23.2
C 192.168.23.0/24 is directly connected, Serial1/0
R3#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 = 2/10/20 ms
3、将 R1、R3 的静态路由 no 掉,改为默认路由
配置命令
R1
R1(config)#no ip route 192.168.23.0 255.255.255.0 192.168.12.2
R1(config)#no ip route 192.168.2.0 255.255.255.0 192.168.12.2
R1(config)#ip route 0.0.0.0 0.0.0.0 192.168.12.2
R1#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.12.2 to network 0.0.0.0
C 192.168.1.0/24 is directly connected, FastEthernet0/0
C 192.168.12.0/24 is directly connected, Serial1/0
S* 0.0.0.0/0 [1/0] via 192.168.12.2
R3
R3(config)#no ip route 192.168.12.0 255.255.255.0 192.168.23.2
R3(config)#no ip route 192.168.1.0 255.255.255.0 192.168.23.2
R3(config)#ip route 0.0.0.0 0.0.0.0 192.168.23.2
R3#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.23.2 to network 0.0.0.0
C 192.168.2.0/24 is directly connected, FastEthernet0/0
C 192.168.23.0/24 is directly connected, Serial1/0
S* 0.0.0.0/0 [1/0] via 192.168.23.2
测试:PC0与PC1是否能通信
R3#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 = 8/14/23 ms
结论:
默认路由可以匹配任何目的地,通常用在网络的出口设备上
思考:
注意默认路由使用的场合以及在什么样的情况下才会选择默认路由转发数据?