第一次配置网络设备,需要使用console线,电脑端使用“超级终端”或其他软件。

工作模式:

  1. 用户模式:

    1. Switch>

    可以查看交换机的基本简单信息,不能做任何修改配置!

  2. 特权模式:

    1. Switch>enable
    2. Switch#

    可以查看所有配置,不能修改配置,但是可以做测试、保存、初始化等操作!

  3. 全局配置模式

    1. Switch#configure terminal
    2. Switch(config)#

    默认不能查看配置,可以修改配置且全局生效!

  4. 接口配置模式

    1. Switch(config)#interface f0/1
    2. Switch(config-if)#

    默认不能查看配置,可以修改配置且该接口生效!

  5. console口/线配置模式:

    1. Switch(config)#line console 0
    2. Switch(config-line)#

    默认不能查看配置,可以修改配置且console有效!

    基本命令:

    ```clojure exit #退回到上一级模式 end #一次性退回到特权模式 Switch(config)#hostname sw1 #修改交换机名 Switch(config-line)#password 12345678 Switch(config-line)#login #设置密码并在登录console接口配置模式时要求验证密码

支持命令缩写 tab补全

  1. 快捷键:
  2. ```clojure
  3. ctrl+u #快速删除光标前所有字符
  4. ctrl+a #快速定位光标到行首
  5. ctrl+e #快速定位光标到行尾

交换机配置:
在内存中存在一个文件:running-config
第一次开机或被初始化之后,系统会在内存中自动创建一个干净的running-config文件。
如何保存修改的配置:

  1. Switch#copy running-config startup-config
  2. Switch#write
  3. Switch#write memory

running-config在内存中,startup-config在硬盘中,再次开机会将startup-config复制为running-config
交换机开机动作:
先去硬盘中查找startup-config文件是否存在,如果不存在,则在内存中创建新的running-config,如果存在,则复制到内存中并改名为running-config。

  1. Switch#show running-config
  2. Switch#sh run
  1. Switch#show startup-config
  1. Switch#reload
  1. Switch(config)#enable password 密码 #在running-config中是明文
  2. Switch(config)#enable secret 密码 #在running-config中是密文
  3. 当两个密码同时配置时,明文的就失效了
  1. Switch#erase startup-config
  1. Switch#show mac-address-table
  1. Switch#show ip interface brief
  2. Switch#sh ip int b

交换机的端口为二层端口,默认出厂为开启状态,插上网线就能写上速率。
接口状态有两个状态,

  1. 第一个状态是物理状态:
    1. down是人为开启,但是没有连接网线
    2. administratively是管理员手动down,插上网线也不会开启
  2. 第二个状态是协商状态:

    1. down是网线两端协商(速率或单双共)不成功
      1. Switch(config-if)#shutdown
      1. Switch(config-if)#no shutdown
      2. no +命令是删除命令
      1. Switch(config-if)#do show 查看的内容
      删除配置:
  3. 在哪配置的,就在哪删

  4. 命令前加no空格
  5. 原命令中参数,并且参数具有唯一性,则删除时不需要加参数
    1. Switch(config-if)#hostname sw1
    2. Switch(config-if)#no hostname

    路由器基本命令

    1. Router(config-if)#ip 10.1.1.254 255.255.255.0
    2. Router(config-if)#no shutdown
    1. Router(config-if)#line vty 0 4
    2. Router(config-line)#password 123456
    3. Router(config-line)#login
    在PC上登录路由器远程控制:
    image.png ```clojure Router(config)#line vty 0 Router(config-line)#transport input ? all All protocols none No protocols ssh TCP/IP SSH protocol telnet TCP/IP Telnet protocol Router(config-line)#transport input ssh Router(config-line)#exit Router(config)#hostname r1 Router(config)#ip domain-name aa.fx.com r1(config)#crypto key generate rsa The name for the keys will be: r1.aa.fx.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]

  1. SSH密码与Telnet密码相同,开启SSH必须设置域名和主机名,不能使用默认。<br />在PCSSH远程登录:<br />![image.png](https://cdn.nlark.com/yuque/0/2022/png/26621316/1656819474943-41d477e0-6db3-4563-baea-dbf389c028fd.png#clientId=u0ec630ac-4de8-4&crop=0&crop=0&crop=1&crop=1&from=paste&height=393&id=u51c31c47&margin=%5Bobject%20Object%5D&name=image.png&originHeight=589&originWidth=551&originalType=binary&ratio=1&rotation=0&showTitle=false&size=25631&status=done&style=none&taskId=ua1ff49d5-9d0c-40fc-84ff-f3a4e7e323e&title=&width=367.3333333333333)<br />设置不同用户账号登录路由器:
  2. ```clojure
  3. r1(config)#line vty 0 4
  4. r1(config-line)#no password
  5. r1(config-line)#no login
  6. r1(config-line)#login local #使用本地数据库的用户名密码来登录
  7. r1(config-line)#exit
  8. r1(config)#username fx password fx.123
  9. r1(config)#username ll password ll.com

在PC中验证SSH登录:
image.png

  1. Switch(config)#interface vlan 1
  2. Switch(config-if)#ip address 10.1.1.253 255.255.255.0
  3. Switch(config-if)#no shutdown
  4. Switch(config)#line vty 0 4
  5. Switch(config-line)#login local
  1. Switch(config)#ip default-gateway 20.1.1.254
  2. 目的是为了能够让交换机被跨网段管理
  1. Router(config)#no ip domain-lookup
  2. 目的是输入错误的命令后无需等待

image.png