1)静态路由介绍
静态路由是指由网络管理员手工配置的路由信息。当网络的拓扑结构或链路的状态发生变化时,网络管理员需要手工去修改路由表中相关的静态路由信息。静态路由信息在缺省情况下是私有的,不会传递给其他的路由器。当然,网管员也可以通过对路由器进行设置使之成为共享的。静态路由一般适用于比较简单的网络环境,在这样的环境中,网络管理员易于清楚地了解网络的拓扑结构,便于设置正确的路由信息。
静态路由的 IP 环境最适合小型、单路径、静态 IP 网际网络: 
 小型网际网络的定义是 2 到 10 个网络。
 单路径表示网际网络上的任意两个终点之间只有一条路径用于传送数据包。
 静态表示网际网络的拓扑结构不随时间的变化而更改。
适合使用静态路由的环境包括:
 小公司。
 家庭办公室 IP 网际网络。
 使用单个网络的分支机构。
与在通常是低带宽 WAN 链接上运行路由协议不同,分支机构路由器上的单个默认路由可以确保将所有未指定到分支机构网络计算机上的通信都路由到总部。
静态路由的优点:
◎不需要动态路由选择协议,减少了路由器的日常开销
◎在小型互连网络上很容易配置
◎可以控制路由选择
静态路由的缺点是:
◎不能容错
如果路由器或链接宕机,静态路由器不能感知故障并将故障通知到其他路由器。这事关大型的公司网际网络,而小型办公室(在 LAN 链接基础上的两个路由器和三个网络)不会经常宕机,也不用因此而配置多路径拓扑和路由协议。
◎管理开销
如果对网际网络添加或删除一个网络,则必须手动添加或删除与该网络连通的路由。如果添加新路由器,则必须针对网际网络的路由对其进行正确配置。
关于管理距离AD
用来表示路由的可信度,路由器可能从多种途径获得同一路由,例如,一个路由器要获得“10.1.1.0/24””网络的路由,可以来自RIP,也可以是静态路由。不同途径获得的路由可能采取不同的路径到达目的网路,为了区分不同路由协议的可信度,用管理距离表示。静态路由的默认管理距离是1,直连接口是0.
关于度量值Metric
某一个路由协议判别到达目的网络的最佳路径的方法。当一个路由器有多条路径到达某一目的网络时,路由协议必须判断其中哪一条是最佳的并把它放到路由表中,路由协议会给每一条路径计算一个数,这个数就是度量值。度量值越小,这条路径越佳。
2)默认路由
所谓默认路由,是指路由器在路由表中如果找不到到达目的网络的具体路由时,最后会采用的路由。默认路由通常会在Stub Network中使用。 1
图中左边的网络到Internet上只有一个出口,因此可以在R2上配置默认路由,命令是:
ip router 0.0.0.0 0.0.0.0{ 网关地址 | 接口 }
例子:ip router 0.0.0.0 0.0.0.0 10.10.10.10
      ip router 0.0.0.0 0.0.0.0 S0/0
3)静态路由(Ipv4)配置
Router1
改名
Router>
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname router1
配置端口f0/0
router1(config)#int f0/0
router1(config-if)#ip address 172.16.1.1 255.255.255.0
router1(config-if)#no shutdown
%LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
配置端口s0
router1(config-if)#int s0
router1(config-if)#ip address 172.16.2.1 255.255.255.0
router1(config-if)#no shutdown
%LINK-3-UPDOWN: Interface Serial0, changed state to up
%LINK-3-UPDOWN: Interface Serial0, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0, changed state to down
配置时钟频率
router1(config-if)#clock rate 64000
router1(config-if)#no shutdown
router1(config-if)#exit
设置静态路由
router1(config)#ip route 172.16.3.0 255.255.255.0 172.16.2.2
router1(config)#end
show一下
router1#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
               172.16.0.0/24 is subnetted, 2 subnets
C            172.16.1.0 is directly connected, FastEthernet0/0
S            172.16.3.0 [1/0] via 172.16.2.2
%LINK-3-UPDOWN: Interface Serial0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0, changed state to up
Router2
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#hostname router2
router2(config)#int f0/0
router2(config-if)#ip address 172.16.3.2 255.255.255.0
router2(config-if)#no shutdown
%LINK-3-UPDOWN: Interface FastEthernet0/0, changed state to up
router2(config-if)#int s0
router2(config-if)#ip address 172.16.2.2 255.255.255.0
router2(config-if)#no shutdown
%LINK-3-UPDOWN: Interface Serial0, changed state to up
router2(config-if)#exit
router2(config)#ip route 172.16.1.0 255.255.255.0 172.16.2.1
router2(config)#end
router2#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
       172.16.0.0/24 is subnetted, 3 subnets
C       172.16.3.0 is directly connected, FastEthernet0/0
C       172.16.2.0 is directly connected, Serial0
S       172.16.1.0 [1/0] via 172.16.2.1
PC1
ip:172.16.1.11   255.255.255.0
dg:172.16.1.1
PC2
ip:172.16.3.22    255.255.255.0
dg:172.16.3.2
PC1 ping的结果
C:>ping 172.16.3.22
Pinging 172.16.3.22 with 32 bytes of data:
Reply from 172.16.3.22: bytes=32 time=60ms TTL=241
Reply from 172.16.3.22: bytes=32 time=60ms TTL=241
Reply from 172.16.3.22: bytes=32 time=60ms TTL=241
Reply from 172.16.3.22: bytes=32 time=60ms TTL=241
Reply from 172.16.3.22: bytes=32 time=60ms TTL=241
Ping statistics for 172.16.3.22:     Packets: Sent = 5, Received = 5, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
      Minimum = 50ms, Maximum = 60ms, Average = 55ms
PC2 ping的结果
C:>ping 172.16.1.11
Pinging 172.16.1.11 with 32 bytes of data:
Reply from 172.16.1.11: bytes=32 time=60ms TTL=241
Reply from 172.16.1.11: bytes=32 time=60ms TTL=241
Reply from 172.16.1.11: bytes=32 time=60ms TTL=241
Reply from 172.16.1.11: bytes=32 time=60ms TTL=241
Reply from 172.16.1.11: bytes=32 time=60ms TTL=241
Ping statistics for 172.16.1.11:      Packets: Sent = 5, Received = 5, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
       Minimum = 50ms, Maximum = 60ms, Average = 55ms
4)浮动静态路由配置

1.预配置
r1(config-if)#int s1/2
r1(config-if)#ip ad 12.1.1.1 255.255.255.0
r1(config-if)#no sh
r1(config-if)#int lo0
r1(config-if)#ip ad 1.1.1.1 255.255.255.0
r1(config-if)#int s1/3
r1(config-if)#ip ad 13.1.1.1 255.255.255.0
r1(config-if)#no sh
r1(config-if)#router rip
r1(config-router)#net 1.1.1.0
r1(config-router)#net 12.1.1.0
r1(config-router)#no auto-summary
r1(config-router)#ver 2
不把13.1.1.0/24 的网段宣告进来,为了做静态路由。
r1(config)#ip route 3.3.3.0 255.255.255.0 13.1.1.3 150 设静态路由的管理距离为150
r2(config)#int s2/1
r2(config-if)#ip ad 12.1.1.2 255.255.255.0
r2(config-if)#no sh
r2(config-if)#int s2/3
r2(config-if)#ip ad 23.1.1.2 225.255.255.0
r2(config-if)#no sh
r2(config-if)#
r2(config-if)#router rip
r2(config-router)#net 12.1.1.0
r2(config-router)#net 23.1.1.0
?
r2(config-router)#no au
r2(config-router)#ver 2
r3(config)#int s3/2
r3(config-if)#ip ad 23.1.1.3 255.255.255.0
r3(config-if)#no sh
r3(config-if)#int s3/1
r3(config-if)#ip ad 13.1.1.3 255.255.255.0
r3(config-if)#no sh
r3(config-if)#router rip
r3(config-router)#net 3.3.3.0
r3(config-router)#net 23.1.1.0
r3(config-router)#no au
r3(config-router)#ver 2
不把13.1.1.0/24 的网段宣告进来,为了做静态路由。
r3(config)#ip route 1.1.1.0 255.255.255.0 13.1.1.1 150
2.查看
r1#sho 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, * - candidate default
       U - per-user static route, o - ODR

Gateway of last resort is not set
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     3.0.0.0/24 is subnetted, 1 subnets     可以看到用RIP学到路由3.3.3.0/24,因为RIP的管理距离是120,小于静态路由的管理距离150,所以静态路由出于备份的地位。
R       3.3.3.0/24 is possibly down,
          routing via 12.1.1.2, Serial1/2
     13.0.0.0/24 is subnetted, 1 subnets
C       13.1.1.0 is directly connected, Serial1/3
     23.0.0.0/24 is subnetted, 1 subnets
R       23.1.1.0/24 is possibly down,
          routing via 12.1.1.2, Serial1/2
3.把S1/2 关闭,再看路由表
r1#sho 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, * - candidate default
       U - per-user static route, o - ODR
Gateway of last resort is not set
     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     3.0.0.0/24 is subnetted, 1 subnets
S       3.3.3.0 [150/0] via 13.1.1.3通过静态路由学到3.3.3.0/24的网络
     13.0.0.0/24 is subnetted, 1 subnets
C       13.1.1.0 is directly connected, Serial1/3
4.把S1/2打开看路由表
r1#sho 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, * - candidate default
       U - per-user static route, o - ODR
Gateway of last resort is not set

     1.0.0.0/24 is subnetted, 1 subnets
C       1.1.1.0 is directly connected, Loopback0
     3.0.0.0/24 is subnetted, 1 subnets
R       3.3.3.0 [120/2] via 12.1.1.2, 00:00:10, Serial1/2
     12.0.0.0/24 is subnetted, 1 subnets
C       12.1.1.0 is directly connected, Serial1/2
     13.0.0.0/24 is subnetted, 1 subnets
C       13.1.1.0 is directly connected, Serial1/3
     23.0.0.0/24 is subnetted, 1 subnets
R       23.1.1.0 [120/1] via 12.1.1.2, 00:00:10, Serial1/2
     现在可以见到静态路由又处于备份的地位。

5)IP classless
ip classless开启无类别路由
当ip classless命令关闭时,路由器在查询路由时只看路由表中的主类条目。
Cisco早期的IOS是缺省关闭该命令的,这也是为什么cisco路由器的路由表中一直会有诸如以下条目出现的原因
     0.0.0/32 is subnetted, 1 subnets
C    1.1.1.1 is directly connected, Loopback0
     72.30.0.0/24 is subnetted, 1 subnets
C    172.30.1.0 is directly connected, Ethernet0
其实不管是否开启ip classless,Cisco路由表一直会有类似于““172.30.0.0/24 is subnetted, 1 subnets””的主类条目,它显示该网络被24位的掩码进行子网划分(然后再列出具体的子网),这是因为Cisco软件早期是将IPv4子网分类别对待的(那个时候,查询路由只看主类号,不看具体子网号)。
后来开启ip classless,cisco路由器才将IPv4视为无类别的,在查找路由时,会比较子网号。
 
IPv6静态路由待续…………