静态路由
二、配置静态路由步骤
(1) 步骤 1:在各路由器上配置 IP 地址、保证直连链路的连通性
在各个物理口上配上IP地址,IP地址如上图所示,如:
R1(config)#interface fastEthernet 0/0
R1(config-if)#ip address 192.168.12.1 255.255.255.0
R1(config-if)#no shutdown
将所有物理口都配好IP地址后,测试直连链路的连通性,即ping同一个网段的IP地址,如上图所示,如Router 0去ping Router 1的Fa0/0口的IP地址:
R1#ping 192.168.12.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.12.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 31/31/32 ms
即证明连通,你也可以通过查看命令:
R1#show ip interface brief
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 192.168.12.1 YES manual up up
FastEthernet0/1 10.1.1.254 YES manual up up
当看到自己刚才配上去的IP地址的status和Protocol都是up,则说明连通。
(2) 步骤 2:配置静态路由
命令:ip route 目的网络 掩码 { 网关地址 | 接口 }
你可以选择下一跳的路由器地址,也可以选择本路由器的出接口
例子:ip route 192.168.1.0 255.255.255.0 s0/0
例子:ip route 192.168.1.0 255.255.255.0 12.12.12.2
注意:在写静态路由时,如果链路是点到点的链路(例如 PPP 封装的链路),采用网关地址和接口都是可以的;然而如果链路是多路访问的链路(例如以太网),则只能采用网关地址,即不能:ip route 192.168.1.0 255.255.255.0 f0/0 。
【提示】有的 IOS 版本中,采用ip route 192.168.1.0 255.255.255.0 f0/0时,路由器
也是正常工作的,然而这是代理 ARP 的功劳,建议不要采用该形式。
R1上的静态路由:
R1(config)#ip route 172.16.23.0 255.255.255.0 192.168.12.2(也可以是f0/0)
R1(config)#ip route 20.1.1.0 255.255.255.0 192.168.12.2(也可以是f0/0)
相似地配置R2和R3
配置时注意:
之所以要用静态路由,是因为当数据从PC发出到路由器上时,路由器需要查看路由器上的路由表有没有目的网段,如果没有静态路由,则路由器会因为找不到目的网段而将数据包丢弃,也就ping不通,所以需要手工添加路由上去,使路由器找到目的网段,然后就可以将数据包转发出去。
将静态路由配置好之后:
查看:
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
10.0.0.0/24 is subnetted, 1 subnets
C 10.1.1.0 is directly connected, FastEthernet0/1
20.0.0.0/24 is subnetted, 1 subnets
S 20.1.1.0 is directly connected, FastEthernet0/0
172.16.0.0/24 is subnetted, 1 subnets
S 172.16.23.0 [1/0] via 192.168.12.2
C 192.168.12.0/24 is directly connected, FastEthernet0/0
可以发现路由表中出现目的网段的路由,这时路由器就会将去往另一台PC的数据包从fastethernet 0/1转发出去。而且会看到静态路前面有S标志,可查看上表可知S代表静态,C代表直连路由。
查看R2和R3的路由表:
R2#sh 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
10.0.0.0/24 is subnetted, 1 subnets
S 10.1.1.0 is directly connected, FastEthernet0/0
20.0.0.0/24 is subnetted, 1 subnets
S 20.1.1.0 is directly connected, FastEthernet0/1
172.16.0.0/24 is subnetted, 1 subnets
C 172.16.23.0 is directly connected, FastEthernet0/1
C 192.168.12.0/24 is directly connected, FastEthernet0/0
R3#sh 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
10.0.0.0/24 is subnetted, 1 subnets
S 10.1.1.0 is directly connected, FastEthernet0/0
20.0.0.0/24 is subnetted, 1 subnets
C 20.1.1.0 is directly connected, FastEthernet0/1
172.16.0.0/24 is subnetted, 1 subnets
C 172.16.23.0 is directly connected, FastEthernet0/0
S 192.168.12.0/24 is directly connected, FastEthernet0/0
通过观察可以发现三台路由器上的路由表基本上是一样的,除了静态路由不同之外,也就是说实验可功的标志就是:三台路由器上的路由表的路由条目要一致,如果发现PC去ping另外一台PC时ping不通,可以查看一下三台路由器的路由表是否一致。
实验成功后:
实验配置参考:
R1#sh run
hostname R1
!
interface FastEthernet0/0
ip address 192.168.12.1 255.255.255.0
interface FastEthernet0/1
ip address 10.1.1.254 255.255.255.0
!
ip classless
ip route 172.16.23.0 255.255.255.0 192.168.12.2
ip route 20.1.1.0 255.255.255.0 FastEthernet0/0
R2#sh run
hostname R2
!
interface FastEthernet0/0
ip address 192.168.12.2 255.255.255.0
interface FastEthernet0/1
ip address 172.16.23.2 255.255.255.0
!
ip route 10.1.1.0 255.255.255.0 FastEthernet0/0
ip route 20.1.1.0 255.255.255.0 FastEthernet0/1
R3#sh run
hostname R3
!
interface FastEthernet0/0
ip address 172.16.23.3 255.255.255.0
interface FastEthernet0/1
ip address 20.1.1.254 255.255.255.0
!
ip route 192.168.12.0 255.255.255.0 FastEthernet0/0
ip route 10.1.1.0 255.255.255.0 FastEthernet0/0
来源:http://www.cnblogs.com/maomiyy/p/3762169.html