网络层的功能
-定义了基于IP协议的逻辑地址
-链接不同的媒介类型
-选择数据通过网络的最佳路径
路由原理及配置
什么是路由
-将数据包从一个网络发送到另一个网络
-需要依靠路由器来完成
-路由器只关心网络的状态,决定最佳路径
路由器如何工作
-只要完成下列事情
-识别数据包目标IP地址
-识别数据包源IP地址
-在路由表中发现最可能的路径
-选择路由表中到达目标地址的最佳路径
-维护和检查路由表
-根据路由表选择最佳路径
-每个路由器都维护着一张路由表,这是路由器转发数据关键
-每条路由表记录了到达某个子网或者主机应从路由器的那个物理接口发送,通过此端口可到达该路径的下一个路由器的地址
如何获得路由表
-静态、缺省路由
-有管理员手工在路由器上指定
-适合分支机构、家具办公
-动态路由
-根据网络拓扑或流量变化,由路由器通过路由协议自动设置
-适合ISP服务商、广域网、园区网等大型网络
静态路由
-由管理员手动设置为单向条目
-通信双方的边缘路由器都需要指定,否则会导致数据包有去无回
配置静态路由
-使用IP route 命令
-指定到达IP目的网络
-基本格式
-router(config)#ip router 目标网络ID 子网掩码 吓一跳地址
缺省路由
什么是缺省路由
-缺省路由是一种特殊的静态路由,对于末梢网络的主机来说,也被称为“默认网关”
-缺省路由的目标网络为0.0.0.0 0.0.0.0 可匹配任何目标地址
-只有当路由表中找不到任何明确匹配的路由条目时,才会使用缺省路由。
三层交换机的配置
-使用三层交换技术实现VLAN间通讯
-三层交换机=二层交换机+三层转发
虚接口的概述
-在三层交换机上配置的VLAN接口为虚接口
-使用SVI(交换机虚接口)实现VLAN间的路由
三层交换接的配置
-确定哪些VLAN需要配置网关
-如果三层交换机上没有该VLAN则创建它
-为每个VLAN创建SVI
-给每个SVI配置IP地址
-启用SVI端口
-启用三层交换机的IP路由功能
-如果需要配置三层交换机的动态或静态路由
三层交换机的配置
-在三层交换机启用路由功能
-switch(config)#ip routing
-配置虚接口的IP
-switch(config)#interface vlan vlan-id
-switch(config-if)#ip address ip-address netmask
-switch(config-if)#no shutdown
案例1:静态路由
问题1
按照图1拓扑结构配置IP地址,并通过静态路由实现全网互通
-router>enable
-router#configur terminal
-router(config)#interface gigabitethernet 0/0
-router(config-if)#ip address 192.168.1.254 255.255.255.0
-router(config-if)#no shutdown
-router(config-if)#exit
-router(config)#interface gigabitethernet 0/1
-router(config-if)#ip address 192.168.2.1 255.255.255.0
-router(config-if)#no shutdown
-router(config-if)#exit
-router(config)#ip route 192.168.3.0 255.255.255.0 192.168.2.2
R2配置
-router#configur terminal
-router(config)#interface gigabitethernet 0/0
-router(config-if)#ip address 192.168.3.254 255.255.255.0
-router(config-if)#no shutdown
-router(config-if)#exit
-router(config)#interface gigabitethernet 0/1
-router(config-if)#ip address 192.168.2.2 255.255.255.0
-router(config-if)#no shutdown
-router(config-if)#exit
router(config)#ip route 192.168.1.0 255.255.255.0 192.168.2.1
案例3多网段静态路由
问题2
按照图2拓扑结构配置IP地址,并通过静态路由实现全网互通
R1: ip route 192.168.3.0 24 192.168.2.2
ip route 192.168.5.0 24 192.168.2.2
ip route 192.168.4.0 24 192.168.2.2
R2: ip route 192.168.1.0 24 192.168.2.1
ip router 192.168.5.0 24 192.168.4.2
R3: ip router 192.168.1.0 24 192.168.4.1
ip router 192.168.2.0 24 192.168.4.1
ip router 192.168.3.0 24 192.168.4.1
问题3
按照图3拓扑结构配置IP地址,并通过默认路由实现全网互通
先将静态路由去掉
R1
router(router)#no ip route 192.168.3.0 255.255.255.0 192.168.2.2
router(router)#no ip router 192.168.4.0 255.255.255.0 192.168.2.2
router(router)#no ip router 192.168.5.0 255.255.255.0 192.168.2.2
router(config)#ip route 0.0.0.0 0.0.0.0 192.168.2.2
R3
router(router)#no ip route 192.168.1.0 255.255.255.0 192.168.4.1
router(router)#no ip router 192.168.3.0 255.255.255.0 192.168.4.1
router(router)#no ip router 192.168.2.0 255.255.255.0 192.168.4.1
router(config)#ip route 0.0.0.0 0.0.0.0 192.168.4.1