1. 静态路由基础
① IP路由
什么是路由:
跨越从源主机到目标主机的一个互联网络来转发数据包的过程
网络畅通的条件:
数据包有去有回叫网络畅通
沿途的路由器必须知道到达目标网络的下一跳路由给谁
沿途的路由器必须知道回来的数据包下一跳路由给谁
② 静态路由配置命令
Router(config)#ip route network[mask]
{address | interface}[distance] [permanent]
2. 静态路由配置实验
(1)搭建实验环境
使用PT软件搭建实验环境,网络拓扑如图所示:
(2)配置过程:
在PC1上ping PC2 的iP地址
显示目标主机不可达哈,可以看出网络不通
配置静态路由,使得PC1可以ping通PC2:
在非直连的路由器上配置静态路由:
RA:
RA#configure terminal
RA(config)#ip route 192.168.1.0 255.255.255.0 172.16.0.2
RA#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
172.16.0.0/24 is subnetted, 1 subnets
C 172.16.0.0 is directly connected, Serial0/0
C 192.168.0.0/24 is directly connected, FastEthernet4/0
S 192.168.1.0/24 [1/0] via 172.16.0.2
RB:
RB#configure terminal
RB(config)#ip route 192.168.1.0 255.255.255.0 172.16.1.2
RB(config)#ip route 192.168.0.0 255.255.255.0 172.16.0.1
RB#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
172.16.0.0/24 is subnetted, 2 subnets
C 172.16.0.0 is directly connected, Serial1/0
C 172.16.1.0 is directly connected, Serial2/0
S 192.168.0.0/24 [1/0] via 172.16.0.1
S 192.168.1.0/24 [1/0] via 172.16.1.2
RC:
RC#configure terminal
RC(config)#ip route 192.168.1.0 255.255.255.0 172.16.2.2
RC(config)#ip route 192.168.0.0 255.255.255.0 172.16.1.1
RC#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
172.16.0.0/24 is subnetted, 2 subnets
C 172.16.1.0 is directly connected, Serial0/0
C 172.16.2.0 is directly connected, Serial1/0
S 192.168.0.0/24 [1/0] via 172.16.1.1
S 192.168.1.0/24 [1/0] via 172.16.2.2
RD:
RD#configure terminal
RD(config)#ip route 192.168.0.0 255.255.255.0 172.16.2.1
RD#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
172.16.0.0/24 is subnetted, 1 subnets
C 172.16.2.0 is directly connected, Serial2/0
S 192.168.0.0/24 [1/0] via 172.16.2.1
C 192.168.1.0/24 is directly connected, FastEthernet4/0
(3)验证配置过程:
在PC1上ping PC2的IP地址,结果如下图所示:
网络通了哈!看一下路由跟踪的过程:
现在来思考一个问题:
PC1能够ping通路由器RB的Se1/0接口(即ping 172.16.0.2)吗?我们来试试,结果如下图所示:
能ping通哈,为什么呢?因为路由器RB的Se1/0接口与路由器RA直连。
那PC1能ping通路由器RB的Se2/0接口(即ping 172.16.1.1)吗?我们再来试试,结果如下图所示:
显示目标主机不可达哈!那这又是为什么呢?既然我们在PC1上ping PC2都能通,那为什么ping 172.16.1.0网段就不通呢?那是因为路由器RA的路由表里有到192.168.1.0网段的条目(从路由器RB学习到),而没有到172.16.1.0网段的路由条目,所以它不知道到172.16.1.0网段该怎么走,于是就丢弃数据包并返回给PC1一个消息,告诉PC1目标主机不可达。RA的路由表如下图所示:
3. 默认路由
4. 路由汇总
5. windows系统上的默认路由和网关
6. 网络负载均衡
7. 总结
网络畅通的条件是数据包既能转发到目的地,还要能够返回;
网络排错最基本的原理就是逐一检查沿途的路由器是否有到达目标网络的路由,然后再逐一检查沿途的路由器是否有数据包返回所需的路由;
计算机的网关就是计算机的默认路由,网络排错应该检查计算机是否配置了正确的IP地址、网关以及子网掩码;
将IP地址连续的地址分配给物理位置连续的网络,这样便于路由汇总,减小路由器的路由表;
路由汇总的极限就是默认路由,默认路由优先级最低;
路由器是根据路由表转发数据的,网络管理员可以通过给路由器添加路由表来控制数据包传递的路径。