zoukankan      html  css  js  c++  java
  • 思科交换机配置笔记

    交换机(Switch)是一种用于电信号转发的网络设备,它可以为接入交换机的任意两个网络节点提供独享的电信号通路,最常见的交换机是以太网交换机,其他常见的还有电话语音交换机、光纤交换机等,交换机是集线器的升级替代产品,理论上讲交换机就是按照通信两端传输信息的需求,将需要的信息发送到目标设备上的网络组件.

    文字描述,摘抄自《网络设备配置与管理》精简内容,部分内容来自华为(HCIP认证》课程笔记,适合学习面试,其中的架构图,与搭建流程为自己规划并实验的。

    交换机是一种交换式集线器,其基于MAC地址识别,能完成封装转发数据包功能的网络设备.交换机可以学习MAC地址,并把其存放在内部地址表中,通过在数据帧的始发者和目标接收者之间建立临时的交换路径,使数据帧直接由源地址到达目的地址.

    交换机内部拥有一条很高带宽的背板总线和内部交换矩阵所有的端口都挂接在这条背板总线上控制电路收到数据包以后,处理端口会查找内存中的地址对照表以确定目的MAC地址的网卡NIC挂接在哪个端口上,通过内部交换矩阵迅速将数据包传送到目的端口目的MAC若不存在才广播到所有的端口,接收端口回应后交换机会学习新的地址,并把它添加入内部MAC地址表中.

    关于交换机的分类:

    1.根据网络覆盖范围划分交换机:广域网交换机和局域网交换机
    2.根据交换机端口结构划分交换机:固定端口交换机和模块化交换机
    3.根据工作协议层划分交换机:二层交换机、三层交换机、四层交换机
    4.根据支持网管功能划分交换机:网管型交换机和非网管理型交换机
    5.根据传输介质划分交换机:以太网交换机、快速以太网交换机、ATM交换机、FDDI交换机、令牌环交换机
    6.根据应用网络层次划分交换机:企业级交换机、校园网交换机、部门级交换机、工作组交换机、桌机交换机

    关于二层交换机:

    二层交换机是对应于OSI/RM的第二协议层来定义的,因为它只能工作在OSI/RM开放体系模型的第二层,即数据链路层.二层交换机依赖于链路层中的信息(如MAC地址)完成不同端口数据间的线速交换,一般应用于小型企业或中型以上企业网络的桌面层次.

    关于三层交换机:

    三层交换机是对应于OSI/RM开放体系模型的第三层,即网络层来定义的,也就是说这类交换机可以工作在网络层,它比第二层交换机更加高档,功能更加强.当网络规模较大时,可以根据特殊应用需求划分为小面独立的VLAN网段,以减小广播所造成的影响,通常这类交换机是采用模块化结构,以适应灵活配置的需要.


    ## 交换机的初始化

    下面的命令方式将对交换机的基本配置,包括配置交换机主机名,特权模式密码,管理接口,IP地址等.

    1.首先登陆思科交换机,并进入特权模式,并配置好主机名称,此处交换机名称配置为lyshark.

    Switch> enable                        // 进入特权模式
    Switch# configure terminal            // 使用全局配置模式
    Switch(config)# hostname lyshark      // 配置交换机名称
    lyshark(config)#
    

    2.开启0号模块下的1-3号接口,配置交换机端口速率并启用指定端口.

    lyshark(config)# interface range fa0/1-3     // 选择配置端口
    lyshark(config-if-range)# speed 100          // 配置所选端口的速率
    lyshark(config-if-range)# no shutdown        // 开启所选端口
    lyshark(config-if-range)# exit               // 退出所选端口
    

    3.配置交换机虚拟管理接口的名称,IP地址和子网掩码,并开启管理接口,方便远程维护.

    lyshark(config)# interface vlan 1                          // 创建虚拟接口vlan1并进入
    lyshark(config-if)# ip address 192.168.1.10 255.255.255.0  // 配置IP和子网掩码
    lyshark(config-if)# no shutdown                            // 开启端口
    lyshark(config-if)# exit
    

    4.配置好虚拟终端以及密码,并允许远程Telnet登陆.

    lyshark(config)# line vty 0 2              // 配置序号为0-2的3个虚拟终端
    lyshark(config-line)# password admin       // 配置虚拟终端登陆密码为admin
    lyshark(config-line)# login                // 开启登陆,允许远程登陆
    lyshark(config-line)# exit
    

    若要关闭虚拟终端登陆功能,则需要执行以下命令,取消虚拟终端的登陆.

    lyshark(config)# line vty 0 2              // 选择序号为0-2的3个虚拟终端
    lyshark(config-line)# no password          // 取消登陆密码
    lyshark(config-line)# no login             // 设置为不允许远程登陆 
    lyshark(config-line)# exit
    

    5.在全局模式下配置特权密码,如果明文与密文密码同时配置,则默认使用密文密码为准.

    lyshark(config)# enable password 123123    // 配置明文密码
    lyshark(config)# enable secret 123321      // 配置密文密码
    lyshark(config)# exit
    

    6.全部配置完成以后,可以使用running-config(查看内存配置数据),也可startup-config(查看RAM存储器配置).

    lyshark# show running-config              // 查看临时配置数据
    lyshark# show startup-config              // 查看RAM永久配置数据
    
    Building configuration...
    Current configuration : 1201 bytes
    !
    version 12.2                                     // 交换机版本
    hostname lyshark                                 // 主机名称
    !
    enable secret 5 $1$mERr$vPfXBroDs2s.F.9FQ1Le20   // 密文密码
    enable password 123123                           // 明文密码
    !
    interface Vlan1                                  // Vlan1 接口信息
     ip address 192.168.1.10 255.255.255.0           // Vlan1 的管理接口地址
    !
    line con 0
    !
    line vty 0 2                                    // 远程管理终端
     password admin                                 // 终端密码
     login
     end
    

    7.以上配置内容,当交换机断电后数据也将会清空,我们可以使用以下命令对配置数据永久存储起来.

    lyshark# write                                 // 写入配置文件
    lyshark# erase startup-config                  // 清空配置文件
    lyshark# reload                                // 重新加载配置文件
    

    8.通过telnet客户端,连接192.168.1.10输入密码即可登陆交换机.

    Trying 192.168.1.10 ...Open
    User Access Verification
    
    Password: 
    lyshark>
    lyshark>enable
    Password: 
    lyshark#
    

    ## 交换机常用参数

    常用查询命令:

    lyshark# show hosts                  // 查询主机表
    lyshark# show ip interface           // 查看端口IP配置信息
    lyshark# show history                // 查看历史记录
    lyshark# show terminal               // 查看终端记录大小
    lyshark# show version                // 查询交换机版本
    lyshark# show running-config         // 显示所有的配置
    lyshark# show interface              // 查询所有接口
    

    端口选择命令:

    lyshark# configure terminal                  // 进入终端配置模式
    lyshark(config)#
    lyshark(config)# interface fa0/1             // 选择0号模块的1号端口
    lyshark(config-if)#
    lyshark(config-if)# exit
    lyshark(config)# interface range fa0/1-5     // 选择0号模块的1-5号端口
    lyshark(config-if-range)#
    

    配置端口描述:

    lyshark(config)# interface range fa0/1-5
    lyshark(config-if-range)# description MyInterface
    

    开启配置端口:

    lyshark# configure terminal                        // 进入命令配置页面
    lyshark(config)# interface range fa0/1-5           // 选择配置的端口
    lyshark(config-if-range)# switchport mode access   // 设置为通用模式
    lyshark(config-if-range)# speed 100                // 设置端口速率
    lyshark(config-if-range)# duplex auto              // 设置工作模式
    lyshark(config-if-range)# exit
    

    配置端口模式:

    lyshark# configure terminal
    lyshark(config)# interface fa0/1
    lyshark(config-if)# switchport mode access          // 设置为通用模式
    lyshark(config-if)# switchport mode multi           // 该模式很少用
    lyshark(config-if)# switchport mode trunk           // 设置为交换机模式
    

    启用/禁用端口:

    lyshark# configure terminal                    // 进入命令配置模式
    lyshark(config)# interface range fa0/1-24      // 选择1-24口
    lyshark(config-if-range)# shutdown             // 关闭所有端口
    lyshark(config-if-range)# exit
    
    lyshark(config)# interface range Gig0/1-2      // 选择高速通信端口
    lyshark(config-if-range)# shutdown             // 关闭所有端口
    lyshark(config-if-range)# no shutdown          // 开启所有端口
    

    ## 交换机实现VLAN

    VLAN(Virtual Local Area Network),中文名为虚拟局域网,是一种使用交换机将局域网内的设备在逻辑上划分成一个个网段的技术,即在物理网络上进一步划分逻辑网络,VLAN可以突破地理位置的限制,完全基于实际管理需要来划分网络,例如在单个交换机内划分为不同的区域,不同区域之间无法互相通信,来实现相互隔离.

    VLAN具有与普通局域网相同的属性,第二层的单播,多播和广播帧只能在相同的VLAN内转发,扩散,而不会直接进入其他VLAN中,因此同一个VLAN内的主机即使位于不同的交换机上,也可以互相访问,而不是同一VLAN的主机,即使连接在同一交换机上,也无法通过数据链路层互相访问.如果一个VLAN内的主机想访问另一个VLAN内的主机,必须通过一个三层设备,如路由器或三层交换机实现通信.

    ◆单交换机实现VLAN◆

    如前所述,基于端口的VLAN属于静态VLAN,它是划分网络最简单,最有效和最常用的方法,下面将在单台交换机上配置静态VLAN,来实现两个网段的数据隔离,以下实验是一种网络拓扑中最简单的拓扑结构图,适合于小型办公网络,其实验拓扑图如下.

    初始化配置: 初始化交换机,开启5个交换口,其他交换口关闭保证安全性.

    Switch> enable
    Switch# configure terminal
    
    Switch(config)# hostname switch0                 // 配置主机名称
    Switch0(config)# interface range fa0/1-5         // 选择1-5号端口
    Switch0(config-if-range)# speed 100              // 设置端口速率
    Switch0(config-if-range)# no shutdown            // 开启端口
    Switch0(config-if-range)# exit
    

    创建VLAN区域: 创建两个VLAN区域,分别命名为vlan10为CaiWu部和vlan20为XiaoShou部两个部门,命令如下.

    Switch0> enable
    Switch0# configure terminal
    
    Switch0(config)# vlan 10                   // 将VLAN 10配置为CaiWu部门
    Switch0(config-vlan)# name CaiWu
    Switch0(config-vlan)# exit
    
    Switch0(config)# vlan 20                   // 将VLAN 20配置为XiaoShou部门
    Switch0(config-vlan)# name XiaoShou
    Switch0(config-vlan)# exit
    

    添加VLAN端口: 指定端口加入到新创建的VLAN中,将fa0/1-3号端口放到CaiWu,fa0/4-5号端口放到XiaoShou里.

    Switch0(config)# interface range fa0/1-3                // 选择1-3号端口
    Switch0(config-if-range)# switchport mode access        // 开启端口
    Switch0(config-if-range)# switchport access vlan 10     // 指定将1-3号端口加入到vlan10
    Switch0(config-if-range)# exit
    
    Switch0(config)# interface range fa0/4-5
    Switch0(config-if-range)# switchport mode access
    Switch0(config-if-range)# switchport access vlan 20    // 指定将4-5号端口加入到vlan20
    Switch0(config-if-range)# exit
    

    测试环节: 最后分别给五台设备配置好IP地址,并通过ping命令测试联通性.

    #----设置客户主机IP地址+网关-------------------------
    
    [主机名]         [主机IP]           [网关]
    PC0           192.168.10.1     192.168.10.254
    PC1           192.168.10.2     192.168.10.254
    PC2           192.168.10.3     192.168.10.254
    PC3           192.168.20.1     192.168.20.254
    PC4           192.168.20.2     192.168.20.254
    
    #----设置好后测试网络连通性-------------------------
    C:>ping 192.168.10.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    C:>ping 192.168.10.2
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    C:>ping 192.168.10.3
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    

    ◆跨交换机实现VLAN◆

    在实际的工作环境中,只在一台交换机上实现VLAN是远远不够的,通常需要跨越多台交换机实现VLAN划分网段,思科交换机通过使用Trunk干道端口的方式实现多台交换机数据共享,并实现跨交换机上的同一个VLAN之间的数据通信,其拓扑结构图如下.

    配置两台交换机: 分别初始化两台交换机,重命名两个交换机名字,并分别在两台交换机上开启3个端口.

    #----配置switch0---------------------------------------------
    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch0               // 指定交换机1为switch0
    switch0(config)# interface range fa0/1-3       // 开启0模块上面的1-3号端口
    switch0(config-if-range)# speed auto           // 配置为自动模式
    switch0(config-if-range)# no shutdown          // 开启端口
    switch0(config-if-range)# exit
    
    #----配置switch1---------------------------------------------
    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch1
    switch1(config)# interface range fa0/1-3
    switch1(config-if-range)# speed auto
    switch1(config-if-range)# no shutdown
    switch1(config-if-range)# exit
    

    配置交换机Trunk: 配置Trunk干道通信,也就是将两台交换机互相连接,此处配置fa0/1接口为干道网络接口.

    #----配置switch0---------------------------------------------
    switch0> enable
    switch0# configure terminal
    switch0(config)#
    switch0(config)# interface fa0/1               // 选择Fa0/1端口
    switch0(config-if)# switchport mode trunk      // 将1号端口设置为trunk模式
    switch0(config-if)# exit
    
    #----配置switch1---------------------------------------------
    switch1> enable
    switch1# configure terminal
    switch1(config)#
    switch1(config)# interface fa0/1
    switch1(config-if)# switchport mode trunk
    switch1(config-if)# exit
    

    配置Switch0: 配置switch0交换机,创建Vlan10和Vlan20,并分别将两个主机PC0加入Vlan10PC1加入到Vlan20.

    switch0> enable
    switch0# configure terminal
    
    #----创建接口信息---------------------------------------------
    switch0(config)#
    switch0(config)# vlan 10                         // 创建vlan11
    switch0(config-vlan)# exit
    switch0(config)# vlan 20                         // 创建vlan20
    switch0(config-vlan)# exit
    
    #----配置接口信息---------------------------------------------
    switch0(config)# interface fa0/2                // 将fa0/2号接口加入到vlan10
    switch0(config-if)# switchport mode access
    switch0(config-if)# switchport access vlan 10
    switch0(config-if)# exit
    
    switch0(config)# interface fa0/3                // 将fa0/3号接口加入到vlan20
    switch0(config-if)# switchport mode access
    switch0(config-if)# switchport access vlan 20
    switch0(config-if)# exit
    

    配置Switch1: 配置switch1交换机,创建Vlan10和Vlan20,并分别将两个主机PC2加入Vlan10PC3加入到Vlan20.

    switch1> enable
    switch1# configure terminal
    
    #----创建接口信息---------------------------------------------
    switch1(config)# vlan 10
    switch1(config-vlan)# exit
    
    switch1(config)# vlan 20
    switch1(config-vlan)# exit
    
    #----配置接口信息---------------------------------------------
    switch1(config)# interface fa0/2
    switch1(config-if)# switchport mode access
    switch1(config-if)# switchport access vlan 10
    switch1(config-if)# exit
    
    switch1(config)# interface fa0/3
    switch1(config-if)# switchport mode access
    switch1(config-if)# switchport access vlan 20
    switch1(config-if)# exit
    

    测试环节: 最后分别给五台设备配置好IP地址,并通过ping命令测试联通性.

    #----设置客户主机IP地址+网关-------------------------
    
    [主机名]         [主机IP]           [网关]
    PC0           192.168.10.1     192.168.10.254
    PC1           192.168.20.1     192.168.20.254
    PC2           192.168.10.2     192.168.10.254
    PC3           192.168.20.2     192.168.20.254
    
    #----设置好后测试网络连通性-------------------------
    
    C:>ping 192.168.10.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    C:>ping 192.168.20.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    

    ◆通过VTP管理VLAN◆

    如果网络中有多台交换机,每台交换机上有多个VLAN,此时采用传统方法在每台交换机上一个个配置VLAN不仅效率低而且增加了管理难度,为此思科开发了VTP技术来实现交换机之间自动实现数据的同步.

    VTP它是VLAN中继协议,被称为VLAN链路聚集协议,它可以实现属于同一VTP域的交换机之间自动同步和传播VLAN信息,这样只需要在Server服务端添加VLAN信息,那么客户端将会自动同步,但需要注意的是同步时只能同步VLAN分组,至于端口的添加还得需要手动在每台交换机上添加,因为每一种交换机的接口数量都不太相同,故很难实现统一.

    配置两台交换机: 分别初始化两台交换机,重命名两个交换机名字,并分别在两台交换机上开启3个端口.

    #----配置switch0---------------------------------------------
    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch0               // 配置交换机名称
    switch0(config)# interface range fa0/1-3       // 开启1-3号端口
    switch0(config-if-range)# speed auto           // 设置端口速率为自动模式
    switch0(config-if-range)# no shutdown          // 开启状态
    switch0(config-if-range)# exit
    
    #----配置switch1---------------------------------------------
    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch1
    switch1(config)# interface range fa0/1-3
    switch1(config-if-range)# speed auto
    switch1(config-if-range)# no shutdown
    switch1(config-if-range)# exit
    

    配置交换机Trunk: 将两台交换机的fa0/1端口,配置成Trunk通信模式,同步数据使用.

    #----配置switch0---------------------------------------------
    switch0> enable
    switch0# configure terminal
    switch0(config)# interface fa0/1                  // 选择1号端口
    switch0(config-if)# switchport mode trunk         // 将端口设置成trunk模式
    switch0(config-if)# exit
    
    #----配置switch1---------------------------------------------
    switch1> enable
    switch1# configure terminal
    switch1(config)# interface fa0/1
    switch1(config-if)# switchport mode trunk
    switch1(config-if)# exit
    

    配置Switch0:switch0上创建VTP管理域,设置名称为manage,密码为123123配置命令如下.

    switch0> enable
    switch0# configure terminal
    switch0(config)# vtp domain manage             // 创建名为manage的管理域
    switch0(config)# vtp mode server               // 将本交换机设置为server模式
    switch0(config)# vtp password 123123           // 设置VTP同步密码为123123
    switch0(config)# exit
    
    #----查看VTP状态---------------------------------------------
    switch0# show vtp status                       // 查看VTP同步状态
    VTP Version                     : 2            // VTP的版本
    Configuration Revision          : 0            // 此处为非0说明同步成功
    Maximum VLANs supported locally : 255
    Number of existing VLANs        : 5
    VTP Operating Mode              : Server      // 指定是server模式
    VTP Domain Name                 : manage      // 同步名称为manage
    VTP Pruning Mode                : Disabled
    VTP V2 Mode                     : Disabled
    VTP Traps Generation            : Disabled
    MD5 digest                      : 0x65 0x6A 0x3C 0x35 0x8B 0xF5 0x0D 0xC0 
    Configuration last modified by 0.0.0.0 at 0-0-00 00:00:00
    Local updater ID is 0.0.0.0 (no valid interface found)
    

    配置Switch1:switch1上创建VTP同步域,设置模式为client,密码为123123,配置命令如下.

    switch1> enable
    switch1# configure terminal
    switch1(config)# vtp domain manage             // 设置同步域名称
    switch1(config)# vtp mode client               // 设置成客户端模式
    switch1(config)# vtp password 123123           // 指定同步密码
    switch1(config)#exit
    
    #----查看VTP状态---------------------------------------------
    switch1# show vtp status                       // 查询状态
    VTP Version                     : 2
    Configuration Revision          : 0            // 此处为非0说明同步成功
    Maximum VLANs supported locally : 255
    Number of existing VLANs        : 5
    VTP Operating Mode              : Client
    VTP Domain Name                 : manage
    VTP Pruning Mode                : Disabled
    VTP V2 Mode                     : Disabled
    VTP Traps Generation            : Disabled
    MD5 digest                      : 0x65 0x6A 0x3C 0x35 0x8B 0xF5 0x0D 0xC0 
    Configuration last modified by 0.0.0.0 at 0-0-00 00:00:00
    

    创建VLAN配置: 在·Server端创建一些VLAN列表,并在Client客户端执行同步命令,即可实现同步数据.

    #----配置switch0---------------------------------------------
    switch0> enable
    switch0# configure terminal
    
    switch0(config)# vlan 10
    switch0(config-vlan)# exit
    
    switch0(config)# vlan 20
    switch0(config-vlan)# exit
    
    #----配置switch1---------------------------------------------
    switch1> enable
    switch1# copy run start           // 开始同步数据
    

    测试环节: 最后分别给五台设备配置好IP地址,并通过ping命令测试联通性.

    #----设置客户主机IP地址+网关-------------------------
    
    [主机名]         [主机IP]           [网关]
    PC0           192.168.10.1     192.168.10.254
    PC1           192.168.20.1     192.168.20.254
    PC2           192.168.10.2     192.168.10.254
    PC3           192.168.20.2     192.168.20.254
    
    #----设置好后测试网络连通性-------------------------
    
    C:>ping 192.168.10.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    C:>ping 192.168.20.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    

    ◆三层交换实现VLAN◆

    如果要在不同的VLAN之间进行数据通信,则必须利用一个具有三层(网络层)功能的设备来实现,目前常用的设备有三层交换机和路由器,在组建大型网络时出于安全考虑,必须把局域网按照功能划分为一个个小的局域网,来保证安全性,这就使得VLAN技术得以运用,但有时候我们还需要实现跨网段通信,则三层交换机可以实现我们的需求.

    虽然路由器可以完成不同网段之间跨网段通信,但是由于路由器端口数量有限,且路由速度慢,因此三层交换机就诞生了,三层交换机是指具有路由功能的交换机,也就是实现了二层的转发和三层的交换,其价格便宜性价比高,目前是组网的绝佳选择,以下是一个三层交换机组网小案例,不仅实现了VLAN的隔离,还可以实现跨网段通信.

    配置二层交换(两台): 首先配置2个二层交换机,将fa0/1配成trunk,fa0/2配成vlan10,fa0/3配成vlan20.

    #----初始化---------------------------------------------
    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch0              // 配置交换机名称(两次配置不能相同)
    switch(config)# interface range fa0/1-3       // 开启1-3号端口
    switch(config-if-range)# speed auto           // 设置端口速率为自动模式
    switch(config-if-range)# no shutdown          // 开启状态
    switch(config-if-range)# exit
    
    #----配置trunk-------------------------------------------
    Switch(config)# interface fa0/1               // 将此通道配置成trunk模式
    Switch(config-if)# switchport mode trunk      // 配置成trunk模式
    Switch(config-if)# switchport trunk allowed vlan all
    Switch(config-if)# no shutdown                // 开启端口
    Switch(config-if)# exit
    
    #----配置VLAN--------------------------------------------
    switch0(config)# vlan 10                       // 创建vlan10
    switch0(config-vlan)# exit
    switch0(config)# vlan 20                       // 创建vlan20
    switch0(config-vlan)# exit
    
    #----加入VLAN组------------------------------------------
    switch(config)# interface range fa0/2         // 将fa0/2端口加入vlan10
    switch(config-if-range)# switchport mode access
    switch(config-if-range)# switchport access vlan 10
    switch(config-if-range)# exit
    
    #----加入VLAN组------------------------------------------
    switch(config)# interface range fa0/3         // 将fa0/3端口加入vlan20
    switch(config-if-range)# switchport mode access
    switch(config-if-range)# switchport access vlan 20
    switch(config-if-range)# exit
    

    配置三层交换机: 配置三层交换机,添加vlan10,vlan20 端口,并将fa0/1-2设置为trunk,供二层交换数据.

    Switch> enable
    Switch# configure terminal
    
    #----配置VLAN--------------------------------------------
    Switch(config)# vlan 10
    Switch(config-vlan)# exit
    Switch(config)# vlan 20
    Switch(config-vlan)# exit
    
    #----配置端口--------------------------------------------
    Switch(config)# interface range f0/1-2                    // 选择1-2号端口
    Switch(config-if)# switchport mode trunk                  // 将端口设置为trunk模式
    Switch(config-if)# no shutdown
    Switch(config-if)# exit
    

    配置三层交换网关: 在三层交换机上,分别为每个虚拟子接口vlan10,vlan20配置一个网关地址.

    Switch> enable
    Switch# configure terminal
    
    #----配置网关--------------------------------------------
    Switch# interface vlan 10                         // 选择Vlan10
    Switch# ip address 192.168.10.254 255.255.255.0   // 给Vlan10配置网关
    Switch# no shutdown                               // 启动端口
    Switch# exit
    
    #----配置网关--------------------------------------------
    Switch# interface vlan 20                          // 选择Vlan20
    Switch# ip address 192.168.20.254 255.255.255.0    // 给Vlan20配置网关
    Switch# no shutdown
    Switch# exit
    
    #----开启路由--------------------------------------------
    Switch(config)# ip routing                         // 开启路由
    Switch(config)# exit
    
    #----查看路由--------------------------------------------
    Switch# show ip route                              // 显示路由结果
    Gateway of last resort is not set
    C    192.168.10.0/24 is directly connected, Vlan10
    C    192.168.20.0/24 is directly connected, Vlan20
    

    客户机配置网关: 给每个客户机配置好IP地址和网关参数,并测试连通性,成功后则四个IP都能PING通.

    #----设置客户主机IP地址+网关-------------------------
    
    [主机名]         [主机IP]           [网关]
    PC0           192.168.10.1     192.168.10.254
    PC1           192.168.20.1     192.168.20.254
    PC2           192.168.10.2     192.168.10.254
    PC3           192.168.20.2     192.168.20.254
    
    #----设置好后测试网络连通性-------------------------
    
    C:>ping 192.168.10.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    C:>ping 192.168.20.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    

    ◆单臂路由实现VLAN◆

    单臂路由是指在路由器的一个物理接口上通过配置子接口的方式,实现原来相互隔离的不同VLAN之间的通信,子接口是在物理接口上衍生出来的逻辑接口,一个物理接口可以衍生出许多的逻辑接口.

    一般路由器的物理接口数量有限,如果每个VLAN都使用一个物理接口进行连接,在网络中VLAN数量较多的情况下需要使用多台路由器才能实现VLAN之间的通信,而通过使用子接口可以在一个物理接口上容纳更多的VLAN,从而很好的解决了此问题.

    配置交换机: 在交换机上创建虚拟局域网vlan10和vlan20,并将fa0/2-3端口加入到vlan10和vlan20中.

    Switch> enable
    Switch# configure terminal
    
    #----开启交换机端口--------------------------------------------
    Switch(config)# hostname switch0               // 配置交换机名称
    switch0(config)# interface range fa0/1-3       // 开启1-3号端口
    switch0(config-if-range)# speed auto           // 设置端口速率为自动模式
    switch0(config-if-range)# no shutdown          // 开启状态
    switch0(config-if-range)# exit
    
    #----创建vlan10和vlan20---------------------------------------
    switch0(config)# vlan 10
    switch0(config-vlan)# exit
    switch0(config)#
    switch0(config)# vlan 20
    switch0(config-vlan)# exit
    
    #----将fa0/2端口加入到vlan10中---------------------------------
    switch0(config)# interface fa0/2
    switch0(config-if-range)# switchport mode access
    switch0(config-if-range)# switchport access vlan 10
    switch0(config-if-range)# exit
    
    #----将fa0/3端口加入到vlan20中---------------------------------
    switch0(config)# interface fa0/3
    switch0(config-if-range)# switchport mode access
    switch0(config-if-range)# switchport access vlan 20
    switch0(config-if-range)# exit
    

    设置Trunk模式: 将交换机与路由器相连的端口设置为Trunk模式,此处设置交换机的fa0/1口为Trunk.

    Switch0> enable
    Switch0# configure terminal
    
    Switch0(config)# interface f0/1                      // 选择1号端口
    Switch0(config-if)# switchport mode trunk            // 将端口设置为trunk模式
    Switch0(config-if)# no shutdown
    Switch0(config-if)# exit
    

    配置路由器: 在路由器的Fa0/0以太网接口上创建逻辑接口,并使用IEEE802.1Q协议封装.

    Router> enable
    Router# configure terminal
    
    #----开启路由器的以太网物理接口fa0/0---------------------------
    Router(config)# interface fa0/0
    Router(config-if)# no shutdown
    Router(config-if)# exit
    
    #----在以太网接口上创建fa0/0.10子接口--------------------------
    Router(config)# interface fa0/0.10                              // 指定子接口名称
    Router(config-subif)# encapsulation dot1q 10                    // 使用IEEE协议封装
    Router(config-subif)# ip address 192.168.10.254 255.255.255.0   // 设置子接口IP参数
    Router(config-subif)# no shutdown
    Router(config-subif)# exit
    
    #----在以太网接口上创建fa0/0.20子接口--------------------------
    Router(config)# interface fa0/0.20
    Router(config-subif)# encapsulation dot1q 20
    Router(config-subif)# ip address 192.168.20.254 255.255.255.0
    Router(config-subif)# no shutdown
    Router(config-subif)# exit
    
    #----开启路由功能,并查看路由状态-------------------------------
    Router(config)# ip routing
    Router(config)# exit
    
    Router# show ip route
    Gateway of last resort is not set
    C    192.168.0.0/24 is directly connected, FastEthernet0/0.20
    C    192.168.10.0/24 is directly connected, FastEthernet0/0.10
    

    客户机配置网关: 给每个客户机配置好IP地址和网关参数,并测试连通性,成功后则四个IP都能PING通.

    #----设置客户主机IP地址+网关-------------------------
    
    [主机名]         [主机IP]           [网关]
    PC0           192.168.10.1     192.168.10.254
    PC1           192.168.20.1     192.168.20.254
    
    #----设置好后测试网络连通性-------------------------
    
    C:>ping 192.168.10.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    C:>ping 192.168.20.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    

    ## 实战:构建小型局域网

    接下来将通过模拟器组件一个中小型网络拓扑结构,总共划分为4个区域,分别是办公区域(Vlan10),宿舍区域(Vlan20)这两个区域分别使用一台交换机来连接,剩下的管理区域(Vlan30),客户区域(Vlan40)放在一个交换机里,通过VLAN技术将其隔离开来,最后开启三层交换的路由转发功能,并实现跨区域通信,接下来看一下实验拓扑图.

    配置核心交换机: 首先配置三层核心交换机 switch,创建VTP管理域以及创建VLAN.

    Switch> enable
    Switch# configure terminal
    
    #----配置VTP管理端-------------------------------
    Switch(config)# vtp domain lyshark    // 创建VTP域并命名为lyshark
    Switch(config)# vtp mode server       // 设置VTP域模式为server
    Switch(config)# vtp password 123123   // 设置VTP密码为123123
    
    #----接着创建VLAN--------------------------------
    Switch(config)# vlan 10
    Switch(config-vlan)# exit
    Switch(config)# vlan 20
    Switch(config-vlan)# exit
    Switch(config)# vlan 30
    Switch(config-vlan)# exit
    Switch(config)# vlan 40
    Switch(config-vlan)# exit
    
    #----开启三层交换机trunk端口----------------------
    Switch(config)# interface range fa0/1-3
    Switch(config-if)#
    Switch(config-if)# switchport trunk encapsulation dot1q
    Switch(config-if)# switchport mode trunk
    

    配置办公区: 接着配置二层交换机 switch0,配置成VTP客户端,并将fa0/1端口配置成trunk模式.

    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch0
    
    #----配置VTP客户端-------------------------------
    switch0(config)# vtp domain lyshark           // 配置VTP客户端,名称
    switch0(config)# vtp mode client              // 配置成client客户端模式
    switch0(config)# vtp password 123123          // 配置密码
    
    #----开启二层交换机trunk端口----------------------
    switch0(config)# interface fa0/1
    switch0(config-if)# switchport mode trunk
    switch0(config-if)# exit
    switch0(config)# exit
    
    #----查看数据同步是否生效-------------------------
    switch0# show vlan brief
    
    10   VLAN0010                         active    
    20   VLAN0020                         active    
    30   VLAN0030                         active    
    40   VLAN0040                         active    
    1002 fddi-default                     active    
    1003 token-ring-default               active    
    1004 fddinet-default                  active    
    1005 trnet-default                    active    
    
    #----最后将剩下的端口全部添加到VLAN10-------------
    switch0(config)# interface range fa0/2-24
    switch0(config-if-range)# switchport mode access
    switch0(config-if-range)# switchport access vlan 10
    switch0(config-if-range)# exit
    

    配置宿舍区: 接着配置二层交换机 switch1,配置成VTP客户端,并将fa0/1端口配置成trunk模式.

    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch1
    
    #----配置VTP客户端-------------------------------
    switch1(config)# vtp domain lyshark           // 配置VTP客户端,名称
    switch1(config)# vtp mode client              // 配置成client客户端模式
    switch1(config)# vtp password 123123          // 配置密码
    
    #----开启二层交换机trunk端口----------------------
    switch1(config)# interface fa0/1
    switch1(config-if)# switchport mode trunk
    switch1(config-if)# exit
    switch1(config)# exit
    
    #----查看数据同步是否生效-------------------------
    switch1# show vlan brief
    
    10   VLAN0010                         active    
    20   VLAN0020                         active    
    30   VLAN0030                         active    
    40   VLAN0040                         active    
    1002 fddi-default                     active    
    1003 token-ring-default               active    
    1004 fddinet-default                  active    
    1005 trnet-default                    active    
    
    #----最后将剩下的端口全部添加到VLAN20-------------
    switch1(config)# interface range fa0/2-24
    switch1(config-if-range)# switchport mode access
    switch1(config-if-range)# switchport access vlan 20
    switch1(config-if-range)# exit
    

    配置管理/客户区: 接着配置二层交换机 switch2,配置成VTP客户端,并将fa0/1端口配置成trunk模式.

    Switch> enable
    Switch# configure terminal
    Switch(config)# hostname switch2
    
    #----配置VTP客户端-------------------------------
    switch2(config)# vtp domain lyshark           // 配置VTP客户端,名称
    switch2(config)# vtp mode client              // 配置成client客户端模式
    switch2(config)# vtp password 123123          // 配置密码
    
    #----开启二层交换机trunk端口----------------------
    switch2(config)# interface fa0/1
    switch2(config-if)# switchport mode trunk
    switch2(config-if)# exit
    switch2(config)# exit
    
    #----查看数据同步是否生效-------------------------
    switch2# show vlan brief
    
    10   VLAN0010                         active    
    20   VLAN0020                         active    
    30   VLAN0030                         active    
    40   VLAN0040                         active    
    1002 fddi-default                     active    
    1003 token-ring-default               active    
    1004 fddinet-default                  active    
    1005 trnet-default                    active    
    
    #----将fa0/2-3两台,添加到VLAN30-----------------
    switch2(config)# interface range fa0/2-3
    switch2(config-if-range)# switchport mode access
    switch2(config-if-range)# switchport access vlan 30
    switch2(config-if-range)# exit
    
    #----将fa0/4-5两台,添加到VLAN30-----------------
    switch2(config)# interface range fa0/4-5
    switch2(config-if-range)# switchport mode access
    switch2(config-if-range)# switchport access vlan 40
    switch2(config-if-range)# exit
    

    开启三层路由: 最后配置核心交换机Switch,并开启路由功能,分别为每个网段指定一个网关.

    Switch> enable
    Switch# configure terminal
    Switch(config)# ip routing             // 开启三层路由功能
    
    #----给Vlan10添加一个网关-----------------
    Switch(config)# interface vlan 10
    Switch(config-if)# ip address 192.168.10.254 255.255.255.0
    Switch(config-if)# no shutdown
    Switch(config-if)# exit
    
    #----给Vlan20添加一个网关-----------------
    Switch(config)# interface vlan 20
    Switch(config-if)# ip address 192.168.20.254 255.255.255.0
    Switch(config-if)# no shutdown
    Switch(config-if)# exit
    
    #----给Vlan30添加一个网关-----------------
    Switch(config)# interface vlan 30
    Switch(config-if)# ip address 192.168.30.254 255.255.255.0
    Switch(config-if)# no shutdown
    Switch(config-if)# exit
    
    #----给Vlan40添加一个网关-----------------
    Switch(config)# interface vlan 40
    Switch(config-if)# ip address 192.168.40.254 255.255.255.0
    Switch(config-if)# no shutdown
    Switch(config-if)# exit
    

    客户机配置网段: 给每个客户机配置好IP地址和网关参数,并测试连通性,成功后则IP都能PING通.

    #----设置客户主机IP地址+网关-------------------------
    
    [主机名]         [主机IP]           [网关]
    PC0           192.168.10.1     192.168.10.254
    PC1           192.168.10.2     192.168.10.254
    
    PC2           192.168.20.1     192.168.20.254
    PC3           192.168.20.2     192.168.20.254
    
    PC4           192.168.30.1     192.168.30.254
    PC5           192.168.30.2     192.168.30.254
    
    PC6           192.168.40.1     192.168.40.254
    PC7           192.168.40.2     192.168.40.254
    
    #----设置好后测试网络连通性-------------------------
    C:>ping 192.168.10.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    C:>ping 192.168.20.1
    Reply from 192.168.20.1: bytes=32 time=1ms TTL=127
    

  • 相关阅读:
    关于ADO.NET连接池
    The Cost of GUIDs as Primary Keys
    数据库反规范设计
    如何快速的呈现我们的网页(转)
    小议数据库主键选取策略(转自吕震宇老师博文)
    javascript 单元测试 (Jsunit应用) 转
    sqlserver版本降级方法
    算术运算表达式正则及分析
    sql STUFF用法
    Flex DashBoard功能
  • 原文地址:https://www.cnblogs.com/LyShark/p/11199499.html
Copyright © 2011-2022 走看看