配置交换机安全功能

这次作业写了两次, 仍然不知所云.

一. 路由器的基本配置

  • 配置设备名称

    1
    Router(config)#hostname R1
  • 禁用 DNS 查找

    1
    R1(config)#no ip domain-lookup
  • 按照地址分配表所示配置接口 IP 地址

    1
    R1(config-if)#ip address 172.16.99.1 255.255.255.0
  • 指定 class 作为特权 EXEC 模式密码。

    1
    R1(config)#enable password class
  • 指定 cisco 作为控制台和 vty 密码并启用登录

    1
    2
    3
    4
    5
    6
    7
    8
    9
    R1(config)# line con 0
    R1(config-line)# password cisco
    R1(config-line)# login
    R1(config-line)# logging synchronous

    R1(config)# line vty 0 15
    R1(config-line)# password cisco
    R1(config-line)# login
    R1(config-line)# end
  • 加密明文密码。

    1
    R1(config)# service password-encryption
  • 将运行配置保存到启动配置。

    1
    R1#copy running-config startup-config

二. 交换机的基本配置

  • a. 配置设备名称。

  • b. 禁用 DNS 查找。

  • c. 指定 class 作为特权 EXEC 模式密码。

  • d. 指定 cisco 作为控制台和 vty 密码,然后启用登录。

  • e. 使用 R1 的 IP 地址配置 S1 的默认网关。

    1
    S1(config)#ip default-gateway 172.16.99.1
  • f. 加密明文密码

    1
    S1(config)# service password-encryption
  • g. 将运行配置保存到启动配置。

  • h. 在交换机上创建 VLAN 99 并将其命名为 Management。

    1
    2
    3
    4
    S1(config)# vlan 99//建立vlan99
    S1(config-vlan)# name Management//把vlan99命名为“Management”
    S1(config-vlan)# exit
    S1(config)#
  • i. 按照地址分配表所示,配置 VLAN 99 管理接口的 IP 地址,并启用接口。

    1
    2
    3
    4
    S1(config)# interface vlan 99
    S1(config-if)# ip address 172.16.99.11 255.255.255.0
    S1(config-if)# no shutdown
    S1(config-if)# end
  • j. 在交换机上,将端口 F0/5 和 F0/6 分配给 VLAN 99。

    1
    2
    3
    4
    5
    6
    7
    8
    S1# config t
    S1(config)# interface f0/5 //进入f0/5接口
    S1(config-if)# switchport mode access //把f0/5接口的模式设置为access
    S1(config-if)# switchport access vlan 99 //把端口f0/5划分到vlan 99
    S1(config-if)# interface f0/6
    S1(config-if)# switchport mode access
    S1(config-if)# switchport access vlan 99
    S1(config-if)# end

三. 配置交换机的 SSH 访问

第 1 步: 在 S1 上配置 SSH 访问。

  • a. 在 S1 上启用 SSH。在全局配置模式下,创建 CCNA-Lab.com 域名。

    1
    S1(config)# ip domain-name CCNA-Lab.com
  • b. 创建一个本地用户数据库条目,在通过 SSH连接交换机时使用。该用户应具有管理员级别的访问权限。
    注意:此处所用密码并不是一个强密码。它仅用于实验目的。

    1
    S1(config)# username admin privilege 15 secret sshadmin
  • c. 配置 vty 线路的 transport input,以便仅允许 SSH 连接,并使用本地数据库进行身份验证。

    1
    2
    3
    4
    S1(config)# line vty 0 15
    S1(config-line)# transport input ssh
    S1(config-line)# login local
    S1(config-line)# exit
  • d. 使用系数 1024 位,生成 RSA 加密密钥

    1
    2
    3
    4
    5
    6
    7
    8
    S1(config)#crypto key generate rsa 
    The name for the keys will be: S1.CCNA-Lab.com
    Choose the size of the key modulus in the range of 360 to 2048 for your
    General Purpose Keys. Choosing a key modulus greater than 512 may take
    a few minutes.
    How many bits in the modulus [512]: 1024
    % Generating 1024 bit RSA keys, keys will be non-exportable...[OK]
    S1(config)#
  • e. 检验 SSH 配置

    1
    S1# show ip ssh

第 2 步: 修改 S1 的 SSH 配置

  • .
    1
    2
    3
    S1# config  t
    S1(config)# ip ssh time-out 75 //超时设置
    S1(config)# ip ssh authentication-retries 2 //身份验证

第 3 步: 检验 S1 上的 SSH 配置。

  • a. 使用 PC-A 上的 SSH 客户端软件连接命令提示符下ssh连接的命令为:

    1
    C:\>ssh -l admin 172.16.99.11
  • b. 键入 exit 结束 S1 上的 SSH 会话。

四. 配置交换机安全功能

  • 查看交换机端口状态

    1
    S1# show ip interface brief

    查看哪些端口未使用

  • 关闭交换机上所有未使用的物理端口

    1
    2
    3
    4
    5
    6
    7
    S1(config)# interface range f0/1 – 4
    S1(config-if-range)# shutdown//关闭某个端口就是进入该端口,然后执行shutdown命令即可
    S1(config-if-range)# interface range f0/7 – 24
    S1(config-if-range)# shutdown
    S1(config-if-range)# interface range g0/1 – 2
    S1(config-if-range)# shutdown
    S1(config-if-range)# end
  • 记录路由器 G0/1 端口 MAC 地址

    1
    R1# show interface g0/1
  • 查看交换机 MAC 表

    1
    S1(config)# show mac address-table
  • 配置基本端口安全。(注意:通常会在交换机的所有接入端口上执行此步骤。此处的 F0/5 是一个示例。)

    • 1) 从 S1 的 CLI,进入与 R1 连接的端口的接口配置模式。

      1
      S1(config)# interface f0/5
    • 2) 关闭端口。

      1
      S1(config-if)# shutdown
    • 3) 在 F0/5 上启用端口安全。

      1
      S1(config-if)# switchport port-security
    • 4) 为第 2a 步中记录的 R1 G0/1 接口的 MAC 地址配置一个静态条目。

      1
      S1(config-if)# switchport port-security mac-address xxxx.xxxx.xxxx

      (xxxx.xxxx.xxxx 是路由器 G0/1 接口的实际 MAC 地址)

    • 5) 启用交换机端口。
      1
      2
      S1(config-if)# no shutdown
      S1(config-if)# end
  • 检查配置

    • 修改路由器 MAC 地址

      1
      2
      3
      4
      5
      6
      R1# config t
      R1(config)# interface g0/1
      R1(config-if)# shutdown
      //使用地址 aaaa.bbbb.cccc,为接口配置一个新的 MAC 地址。
      R1(config-if)# mac-address aaaa.bbbb.cccc
      R1(config-if)# no shutdown

      此时路由器就 ping 不通交换机了

    • 删除路由器的 MAC 地址

      1
      2
      3
      4
      5
      R1# config t
      R1(config)# interface g0/1
      R1(config-if)# shutdown
      R1(config-if)# no mac-address aaaa.bbbb.cccc
      R1(config-if)# no shutdown

      此时可能还是 ping 不通

    • 清除 S1 F0/5 的错误禁用状态。

      1
      2
      3
      4
      S1# config t
      S1(config)# interface f0/5
      S1(config-if)# shutdown
      S1(config-if)# no shutdown

      此时应该可以了

      我的理解是: 对于某个端口而言, 只允许指定的设备连接.