交换机的基本配置(用户和密码)(思科、华为)

在这里插入图片描述

#交换设备

交换机的基本配置

目标

  • 掌握思科设备的命令行基础
  • 会对交换机进行基本配置
  • 会通过telent和ssh对交换机进行远程管理

一、思科设备命令基础

1.进入设备的命令行界面

  • 设备支持命令行
    • 去查看设备上的接口,是否有console
  • 需要有console线
  • 需要超级终端软件进行连接
    • putty
    • secret CRT
    • xshell

2.命令行基础

  • 思科设备上的命令模式

  • 如何进入
    • 用户模式:查看统计信息(用的非常少),用“>"表示

      • 用户模式切换到特权模式

      • enable
        en     #命令可以简写
        
        
    • 特权模式:查看并修改设备的配置(查看居多),用“#”表示

      • 特权模式却换到全局模式

      • configure terminal
        conf t  #简写
        
    • 全局模式:针对设备的整体配置参数,用“(config)#”表示

      • 切换到接口(某一个)模式:(用模拟器,将鼠标移动到交换机的地方不动,就会显示)

      • intrface fastethernet0/1  #进入0/1接口
        int f0/1 #简写
        
        
    • 接口模式:针对设备的接口修改配置,用“(config-if)#"表示

  • 进入对应模式,只能逐级进入

  • 如何返回
    • 返回对应模式,一级一级返回,使用exit,
  • 如果想要快速返回到特权模式,则使用end

当命令输错时

Switch#ded
Translating "ded"...domain server (255.255.255.255)  #系统会进行域名解析

快速中止按 Ctrl+shift+6
#永久不进行域名解析,按一下操作
Switch(config)#no if domain-lookup

3.常见配置

  • 给交换机配置一个主机名(进入全局模式,输入hostname空格加主机名)
Switch>en          #进入特权模式
Switch#conf t      #进入全局模式
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#hostname SW1   #将交换机主机名设置为“SW1”
SW1(config)#
  • 查看交换机内部的mac表

    • 在特权模式下查看(show mac-address-table)
    SW1#show mac-address-table
              Mac Address Table
    -------------------------------------------
    
    Vlan    Mac Address       Type        Ports
    ----    -----------       --------    -----
    
       1    00d0.bc48.17a3    DYNAMIC     Fa0/2
       1    00e0.b094.24ed    DYNAMIC     Fa0/1
  • 交换机学习的是信息的源mac地址,首次使用,当主机A发送数据后,交换机记录主机A的mac地址和端口,而后广播出去,当B接受到并回应时,交换机又记录了B的mac地址和对应端口号

  • 配置交换机的双工模式(全局模式–接口模式)

      SW1#conf t                            进入全局模式
      Enter configuration commands, one per line.  End with CNTL/Z.
      SW1(config)#int f0/1                  进入0/1接口
      SW1(config-if)#duplex ?               显示该语法的使用方式
        auto  Enable AUTO duplex configuration        #自适应
        full  Force full duplex operation             #全双工
        half  Force half-duplex operation             #半双工
      SW1(config-if)#duplex half                      #配置为半双工
      
      SW1#show int f0/1 sw                            #查看端口
      SW1#show int f0/1 switchport                    #这不是简写
      SW1#show int f0/1                               #查看端口
      FastEthernet0/1 is up, line protocol is up (connected)
        Hardware is Lance, address is 0005.5e12.7701 (bia 0005.5e12.7701)
       BW 100000 Kbit, DLY 1000 usec,
           reliability 255/255, txload 1/255, rxload 1/255
        Encapsulation ARPA, loopback not set
        Keepalive set (10 sec)
        Half-duplex, 100Mb/s                #这里显示了当前端口的模式,half:半双工模式
        input flow-control is off, output flow-control is off
        ARP type: ARPA, ARP Timeout 04:00:00
        Last input 00:00:08, output 00:00:05, output hang never
    
  • 设置接口速率
      SW1#conf t
      Enter configuration commands, one per line.  End with CNTL/Z.
      SW1(config)#int f0/1
      SW1(config-if)#speed 10        #设置接口速率为10m
    
    • 如果两个主机对应的接口速率不同则网络会出现延迟
  • 配置console接口的密码
      SW1#conf t
      Enter configuration commands, one per line.  End with CNTL/Z.
      SW1(config)#line console 0                 #进入console 0接口
      SW1(config-line)#password ?
        7     Specifies a HIDDEN password will follow
        LINE  The UNENCRYPTED (cleartext) line password
      SW1(config-line)#password 1234             #设置console口的密码为1234
      SW1(config-line)#login                     #应用当前设置
    
  • 查看当前配置文件
      SW1#show running-config
    
  • 查看保存配置文件(NVRAM)
      SW1#show startup-config   #是查看保存了的配置文件,不是当前已经生效的配置文件
    
  • 保存当前配置文件
  SW1#copy running-config startup-config
  SW1#write     #保存当前配置文件
  • 删除保存配置文件
      SW1#erase nvram
    

4.交换机密码恢复

在这里插入图片描述

  • 拔掉交换机插头,插上电源同时按住MODE建

  • 出现“swith”界面提示后,松开按键,初始化Flash

      Switch:flash_init  #初始化flash
    
  • 将config.text文件改成config.old,完成后启动交换机

    • Switch:rename flash:config.text flash:config.old
      Switch:boot         #重新启动
      
  • 重新启动后,把配置文件的名字改回来

      Switch# rename flash:config.old flash:config.text
    
    • 该完名字后,使用使用命令即可查看这个保存的配置文件内容,可以看到之前的密码

        Switch#show startup-config
      
      • 在这一步,我们已经饶过了原来设置的密码,进入了交换机,而且知道了原来的密码内容
  • 手动加载配置文件(将保存的配置文件复制到当前的配置文件中去)

    • 如果想要之前配置的一些内容就需要这一步
      Switch#copy flash:config.text system:running-config #将保存配置文件复制到当前运行的配置文件
    
  • 进入全局模式配置密码

在这里插入图片描述

二、通过远程管理方式连接交换机(telnet ssh)

1.telnet

  • 是应用层协议,基于传输层TCP,默认端口号23,采用明文密码传输
  • 不是太安全,一般用于内网管理
思路
  • 1.1既然是通过网路的方式管理设备,设备就必须配置IP地址,由于交换机上的接口都是交换接口,是不允许配置IP地址的,直接为交换机的虚接口配置IP地址:(vlan1)接口

      #配置IP地址
      Switch>en
      Switch#conf t
      Enter configuration commands, one per line.  End with CNTL/Z.
      Switch(config)#hostname SW1          #设定交换机的主机名
      SW1(config)#int vlan 1                #进入vlan1虚接口
      SW1(config-if)#ip address 192.168.100.100 255.255.255.0 #为当前vlan1接口配置IP地址和子网掩码
      SW1(config-if)#no shutdown               #打开这个虚接口
    
  • 1.2配置设备的连接终端,并设置密码

      #配置设备的连接终端
      SW1#conf t                                                     #进入全局模式
      Enter configuration commands, one per line.  End with CNTL/Z.
      SW1(config)#line vty 0?                                 #查看vty接口一共有几个可用
      <0-15>                                                  #一共有16个接口可用
      SW1(config)#line vty 0 4                                       #进入0-4的终端接口
      SW1(config-line)#password 1234                                 #设置密码为1234
      SW1(config-line)#login                                         #应用
    

解释

  • 这里的vty,代表交换机的虚拟终端接口,交换机上一共有5个vty口,所以line是进入,vty 0 4 进入这5个口,进一步设置,有些交换机只有这5条线路可用,还有的交换机产品有很多这样的接口

最后使用pc,打开桌面的telnet,输入交换机的IP地址,点击连接

连接成功,输入密码,进入用户模式

当进入特权模式时,显示没有设置密码,则先要在交换机设置特权模式密码

  • 2.创建用户名和密码,配置设备的连接密码并应用(第二种方法)

      SW1#conf t
      Enter configuration commands, one per line.  End with CNTL/Z.
      SW1(config)#username heheda password 1234
      SW1(config)#line vty 0 4	
      SW1(config-line)#login local   #表示使用用户名密码登录,前面已经设置过密码了
    
    • login:表示直接使用密码登录

    • login local:使用账号密码登录

设置特权模式密码(当同时设置明文和密文密码,则只有密文密码生效)
  • 设置特权模式密码(必须设置,不然主机不能进入到交换机的特权模式)
  SW1(config)#enable password 123                 #设置明文密码
  SW1(config)#enable secret 456          #设置密文密码,现在只有这个会生效,因为更安全
  SW1(config)#enable password secret 456          #查看当前配置文件

2.ssh

  • 是应用层协议,基于传输层TCP,,默认端口22,采用密文密码方式
  • 相对来讲比较安全,常用跨越互联网管理、远程管理Linux操作系统
步骤:
  Switch#conf t                                               #进入特权模式
  Enter configuration commands, one per line.  End with CNTL/Z.
  Switch(config)#int vlan 1                                   #进入vlan接口
  Switch(config-if)#ip add 192.168.100.100 255.255.255.0      #设置IP地址和子网掩码
  Switch(config-if)#no shutdown                               #应用
  ……
  Switch#   #返回特权模式
  Switch(config)#hostname SW1                                #设置主机名为SW1
  必须创建主机名,因为创建域名的时候不允许使用默认的主机名
  SW1(config)#ip domain-name heheda.com                      #创建域名
  SW1(config)#crypto key generate rsa                        #创建密钥对
  The name for the keys will be: SW1.heheda
  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.                                           #创建的密钥长度在360~2048之间
  
  How many bits in the modulus [512]: 2048                  #默认的长度为512,输入2048更安全
  % Generating 2048 bit RSA keys, keys will be non-exportable...[OK]
  
  SW1(config)#ip ssh time-out 120                           #配置超时的时间
  *Mar 1 0:6:47.166: %SSH-5-ENABLED: SSH 1.99 has been enabled
  SW1(config)#ip ssh authentication-retries 5                #配置认证的次数
  
  
  SW1(config)#username heheda2 password 123                  #创建用户名密码
  SW1(config)#line vty 0 4
  SW1(config-line)#login local                               #设置用户名密码登录
  
  
  SW1(config-line)#exit                                      #退出到全局模式
  SW1(config)#enable secret 123                              #设置特权模式密码(密文)
  SW1(config)#show running-config                            #检查当前配置文件

通过主机的SSH协议访问并设置交换机

三、华为设备配置登录密码

1.用户界面的概念(VTY Console)

  • 我认为用户界面的概念类似于用户组的概念:如果某用户属于VTY0 4,我在VTY0 4内设置了某种权限,那么所有属于VTY0 4的用户的权限都一样

在这里插入图片描述

在这里插入图片描述

2.配置telnet

  • 以华为路由器为例,设置telnet登录方式,密码为huawei
1. password模式
  • 只需要输入密码即可(不安全)
<Huawei>sys     #进入系统视图
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname AR3     #设置设备名称
[AR3]user-interface vty 0 4   # 进入用户界面准备设置认证模式
[AR3-ui-vty0-4]authentication-mode password   #设置认证方式,
Please configure the login password (maximum length 16):huawei  #设置密码
[AR3-ui-vty0-4]user privilege level 1  #设置用户权限等级,只有用户等级大于3才可以进入系统视图
2. AAA模式

在这里插入图片描述

  • 需要同时输入用户名和密码
    • 配置具有aaa模式的用户
    • 设置用户名、密码、权限等级
    • 用户视图设置aaa认证模式
[AR3]aaa   #进入aaa视图,注册aaa模式的用户
[AR3-aaa]local-user admin password cipher huawei privilege level 3 #设置 用户名 密码 权限
[AR3-aaa]local-user admin service-type telnet  #设置用户的登录类型
[AR3]q
[AR3]user-interface vty 0 4  # 进入前5个用户界面准备设置认证模式
[AR3-ui-vty0-4]authentication-mode aaa     #设置这属于这5个用户界面的用户。认证模式为aaa

3.配置console口密码

  • 配置串口密码,以防止黑客通过串口直连的方式违规接入交换机
1.配置password认证方式
[Huawei]user-interface console 0  #进入console接口
[Huawei-ui-console0]set authentication username huawei password cipher admin123  #以密文的方式存储密码
2.配置aaa认证方式
[Huawei]user-interface console 0   # 进入console视图
[Huawei-ui-console0]authentication-mode aaa  #设置aaa模式认证
[Huawei-ui-console0]q
[Huawei]aaa           #进入aaa视图
[Huawei-aaa]local-user admin password cipher admin123	 #设置一个用户
[Huawei-aaa]local-user admin service-type terminal       #用户的登录类型为console

4.配置思路

在这里插入图片描述

四、通过stelnet远程管理设备(华为)

  • 由于telnet使用明文传输,用户在登录时,其用户名密码都是以明文传输,并不安全,因此可以使用stelnet
  • stelnet是基于ssh协议进行通讯

配置步骤

1.配置生成本地RSA密钥对
rsa local-key-pair create
dis rsa local-key-pair public  #查看本地密钥对中的公钥信息
2.配置用户的验证方式为AAA
user-interface vty 0 4
authentication-mode aaa
protocol inbound ssh      #指定vty界面支持ssh协议,设备自动禁止telnet功能
3.在aaa界面设置用户信息,新建用户
aaa
local-user huawei1 password cipher 123456    #进入aaa界面,添加用户
local-user huawei1 service-type ssh  #设置该用户的接入类型为ssh
local-user huawei1 privilege level 3    #配置用户权限
4.新建ssh用户、设置认证方式
ssh user huawei1 authentication-type password  #新建ssh用户,名为huawei1,指定认证方式为密码
stelnet server enable   #开启ssh服务
dis ssh user-information huawei1     #查看huawei1的用户信息
dis ssh server status   #查看ssh服务状态
5.在用户端,配置用户端ssh首次登录认证
  • 因为用户在第一次登录的时候没有公钥信息,所以会登录失败,所以在用户端将ssh首次认证功能开启,首次登录时不对用户端的公钥进行检查
sys
ssh client frist-time enable
  • 33
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值