交换机基本命令


1 案例1:交换机基本命令模式

1.1 问题

本例要求熟练掌握交换机每个模式的配置命令

对于思科交换机来说,主要有2种配置途径:其一,使用交换机自带的Console线缆连接到计算机的COM口,然后利用计算机的超级终端软件直接配置,首次配置通常使用这种方式;其二,通过telnet方式远程访问、配置交换机,这种方式要求此交换机已配置有IP地址且已接入计算机网络,后续课程会学习此访问方式。

1)通过超级终端访问交换机

2)交换机工作模式的进入与退出

真实设备环境,如图-1所示。

图-1

1.2 方案

本例中的配置练习可采用思科模拟器 —— Cisco Packet Tracer 6.2来实现。

1)安装Packet Tracer 6.2

双击安装包执行默认安装,然后将中文语言文件Chinese.ptl解压到安装目录下的多语言文件夹,比如C:\Program Files (x86)\Cisco Packet Tracer 6.0\languages。

双击桌面的Cisco Packet Tracer快捷方式以启动程序,打开菜单“Options”-->“Preferences”-->切换到“Interface”选项卡-->选择下方的Chinese.ptl-->单击右下角“Change Language”按钮,弹出提示时单击“OK”,如图-2所示。

图-2

关闭当前Packet Tracer程序,然后再重新启动此程序,可发现已经变成中文语言界面了(当前汉化的还不完整),如图-3所示。

图-3

2)建立实验网络拓扑

在Packet Tracer程序主窗口中,添加一台Cisco 2960交换机、一台普通PC机,并添加Console连接、直通网线连接,如图-4所示,确认完毕后将当前拓扑结构保存为c2960-pc.pkt文件。

图-4

其中,连接细节如下:

  • 交换机的Console口 <--> PC机的RS 232串口。
  • 交换机的FastEthernet0/24接口 <--> PC机的FastEthernet0网卡。

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:通过超级终端访问交换机。

1)配置并打开超级终端

在此前建立的Packet Tracer实验拓扑环境中,单击PC机以打开此设备,确认电源已启动(机箱示意图上的指示灯为黄绿色),切换到“桌面选项卡”,如图-5所示,找到其中的“终端”并单击打开。

图-5

在弹出的终端配置窗口中,如图-6所示,单击“确定”以接受默认值。

图-6

接下来就可以看到“终端”窗口了,其中显示了通过Console线连接的交换机初始化信息,回车后可进入交换机的“Switch>”配置系统,如图-7所示。

图-7

提示:在Packet Tracer环境中,可直接单击交换机图标,然后切换到“命令行”选项卡,也可以进入IOS配置环境。

步骤二:交换机工作模式的进入与退出

1) 交换机工作模式的进入如下:

  1. Switch>enable //切换为特权模式
  2. Switch# configure terminal     //进入全局配置模式
  3. Enter configuration commands, one per line. End with CNTL/Z.
  4. Switch(config)#interface fastEthernet 0/1 //进入接口模式
  5. Switch(config-if)#

2)交换机工作模式的退出下:

  1. Switch(config-if)#exit //接口模式退到全局配置模式
  2. Switch(config)#exit //全局配置模式退到特权模式
  3. Switch#exit //特权模式退到用户模式
  4. Switch>

注:exit 返回上一模式

end 从接口或者特全局配置模式回到特权模式,快捷键Ctrl+z同等效果

思科设备命令行不区分大小写,与Linux命令行不同

命令输入错误卡住时同时按键盘ctrl+shift+6这三个键即可

2 案例2:交换机命令行基本配置

2.1 问题

修改及查看交换机配置

1)修改交换机主机名

2)查看交换机配置信息

3)查看IOS名称以及版本信息

2.2 方案

在Packet Tracer程序主窗口中,添加一台Cisco 2960交换机,进入交换机,输入相关命令进行配置和查看交换机

2.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:修改交换机主机名

进入全局配置模式后,使用hostname指令可以为交换机设置主机名。例如,以下操作可以将主机名设置为s1:

  1. Switch(config)# hostname s1                     //配置主机名
  2. s1(config)#    

步骤二:查看交换机配置信息

查看交换机当前的运行配置:

  1. 查看交换机当前的运行配置(或write terminal):
  2. s1# show running-config                 //查看当前的运行配置
  3. Building configuration...
  4. Current configuration : 1052 bytes
  5. !
  6. version 12.2
  7. no service timestamps log datetime msec
  8. no service timestamps debug datetime msec
  9. no service password-encryption
  10. !
  11. hostname sw1                         //已配置主机名
  12. !
  13. !
  14. !
  15. !
  16. spanning-tree mode pvst
  17. !
  18. interface FastEthernet0/1
  19. !
  20. interface FastEthernet0/2
  21. !
  22. interface FastEthernet0/3
  23. !
  24. interface FastEthernet0/4
  25. !
  26. interface FastEthernet0/5
  27. !
  28. interface FastEthernet0/6
  29. !
  30. interface FastEthernet0/7
  31. !
  32. interface FastEthernet0/8
  33. !
  34. interface FastEthernet0/9
  35. !
  36. interface FastEthernet0/10
  37. !
  38. interface FastEthernet0/11
  39. !
  40. interface FastEthernet0/12
  41. !
  42. interface FastEthernet0/13
  43. !
  44. interface FastEthernet0/14
  45. !
  46. interface FastEthernet0/15
  47. !
  48. interface FastEthernet0/16
  49. !
  50. interface FastEthernet0/17
  51. !
  52. interface FastEthernet0/18
  53. !
  54. interface FastEthernet0/19
  55. !
  56. interface FastEthernet0/20
  57. !
  58. interface FastEthernet0/21
  59. !
  60. interface FastEthernet0/22
  61. !
  62. interface FastEthernet0/23
  63. !
  64. interface FastEthernet0/24
  65. !
  66. interface GigabitEthernet1/1
  67. !
  68. interface GigabitEthernet1/2
  69. !
  70. interface Vlan1
  71. no ip address
  72. shutdown
  73. !
  74. !
  75. line con 0
  76. !
  77. line vty 0 4
  78. login
  79. line vty 5 15
  80. login
  81. !
  82. !
  83. end
  84. sw1#

步骤三:查看IOS名称以及版本信息

查看ios名称及版本信息

  1. s1#show version
  2. Cisco Internetwork Operating System Software
  3. IOS (tm) C2950 Software (C2950-I6Q4L2-M), Version 12.1(22)EA4, RELEASE SOFTWARE(fc1)
  4. Copyright (c) 1986-2005 by cisco Systems, Inc.
  5. Compiled Wed 18-May-05 22:31 by jharirba
  6. Image text-base: 0x80010000, data-base: 0x80562000
  7. ROM: Bootstrap program is is C2950 boot loader
  8. Switch uptime is 1 minutes, 39 seconds
  9. System returned to ROM by power-on
  10. Cisco WS-C2950-24 (RC32300) processor (revision C0) with 21039K bytes of memory.
  11. Processor board ID FHK0610Z0WC
  12. Last reset from system-reset
  13. Running Standard Image
  14. 24 FastEthernet/IEEE 802.3 interface(s)
  15. 63488K bytes of flash-simulated non-volatile configuration memory.
  16. Base ethernet MAC Address: 00E0.B026.B88C
  17. Motherboard assembly number: 73-5781-09
  18. Power supply part number: 34-0965-01
  19. Motherboard serial number: FOC061004SZ
  20. Power supply serial number: DAB0609127D
  21. Model revision number: C0
  22. Motherboard revision number: A0
  23. Model number: WS-C2950-24
  24. System serial number: FHK0610Z0WC
  25. Configuration register is 0xF

3 案例3:交换机密码设置

3.1 问题

配置交换机的访问口令

1)配置用户进入特权模式的明文密码为123

2)配置用户进入特权模式的密文密码为456

3)配置conslole口令为789

3.2 方案

配置交换机访问口令

实现此案例需要按照如下步骤进行。

3.3 步骤

步骤一:交换机密码配置

1)设置特权模式口令

包括两种典型的方法:

方法1(明文):enable password 密码字串

方法2(加密):enable secret 密码字串

比如,以下操作将明文口令设为123、加密口令设置为456:

  1. sw2960(config)# enable password 123
  2. sw2960(config)# enable secret 456

返回特权模式,查看运行配置可观察两种口令设置的差异:

  1. sw2960(config)# end     //返回特权模式
  2. sw2960#
  3. %SYS-5-CONFIG_I: Configured from console by console
  4. sw2960# show running-config     //查看当前的运行配置
  5. .. ..
  6. !
  7. hostname sw2960
  8. !
  9. enable secret 5 $1$mERr$pUBB1obEqpmMUtC1rBieD1         //加密口令设置
  10. enable password 123    //非加密的口令设置
  11. !
  12. !
  13. .. ..

执行disable切换到用户模式,再执行enable切换到特权模式,此时会要求输入正确的口令才允许进入(如果明文/密文口令都设置了,则密文口令起作用):

  1. sw2960> enable
  2. Password:     //尝试明文口令123无效
  3. Password: //输入密文口令456验证成功
  4. sw2960#

步骤二:设置console口令

以下操作配置交换机console口令

  1. Sw2960(config)#line console 0
  2. Sw2960(config-line)#password 789 //设置consol口令
  3. Sw2960(config-line)#login

切换到用户模式,提示输入conslole口令才能再次进入到用户模式:

  1. Sw2960(config-line)#end
  2. Sw2960#
  3. %SYS-5-CONFIG_I: Configured from console by console
  4. Sw2960#exit
  5. Sw2960 con0 is now available
  6. Press RETURN to get started.
  7. User Access Verification
  8. Password:

步骤三:清空设备配置

  1. Switch(config)#exit
  2. Switch#write
  3. Switch#erase startup-config
  4. Erasing the nvram filesystem will remove all configuration files! Continue? [confirm] //此时系统询问是否确定删除,按回车即可
  5. [OK]
  6. Erase of nvram: complete

步骤四:重启设备检测配置状况

  1. Switch#reload
  2. Proceed with reload? [confirm] //此时系统询问是否确定重启,按回车即可

猜你喜欢

转载自www.cnblogs.com/tiki/p/10778723.html