交换机基本配置
一、思科命令行基础
1. 配置前准备
- 使用console口登录网络设备
- CONSOLE 端口一般为设备的控制端口,Console 端口使用配置专用连线直接连接至计算机的串口。
- Console端口的类型也有所不同,绝大多数交换机都采用 RJ-45 端口,但也有少数采用D B-9 串口端口或 DB-25 串口端口
- 物理连接(使用 console 线连接到设备的 console 口上)
- 软件连接(使用超级终端、secureCRT、putty、xshell等软件)
2. 命令行基础
- 命令行模式
- enable(用户模式进入特权模式,可简写为:en)
- configure terminal(特权模式进入全局配置模式,可简写为:conf t)
- interface “接口类型” “接口名称”(全局模式进入接口模式,举例:int f0/1)
- exit(返回上一模式)
- end(直接返回特权模式)
- 命令行帮助
可以使用 “?” 号显示命令、显示参数、命令列表
可以使用 “Tab” 键补齐命令、提示命令Switch>en? Exec commands: connect Open a terminal connection disable Turn off privileged commands disconnect Disconnect an existing network connection enable Turn on privileged commands exit Exit from the EXEC logout Exit from the EXEC ping Send echo messages resume Resume an active network connection show Show running system information telnet Open a telnet connection terminal Set terminal line parameters traceroute Trace route to destination
网络设备也支持命令缩写Switch>en Switch>enable
Switch>en Switch#
二、交换机基本配置
常见基本配置
- 配置主机名
Switch#conf t //进入全局配置模式 Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#hostname SW1 //配置主机名为SW1 SW1(config)#
- 查看交换机的MAC地址表
SW1#show mac-address-table Mac Address Table ------------------------------------------- Vlan Mac Address Type Ports ---- ----------- -------- ----- 1 0001.9715.299a DYNAMIC Fa0/2 1 0001.c903.a8cb DYNAMIC Fa0/1
- 指定接口双工模式
SW1#en SW1#conf t Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#int f0/1 SW1(config-if)#duplex ? auto Enable AUTO duplex configuration // 自协商 full Force full duplex operation // 全双工 half Force half-duplex operation // 半双工 SW1(config-if)#duplex auto
- 指定接口的通信速率
SW1>en SW1#conf t Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#int f0/1 SW1(config-if)#speed ? 10 Force 10 Mbps operation // 10Mbps 100 Force 100 Mbps operation // 100Mbps auto Enable AUTO speed configuration // 自协商 SW1(config-if)#speed auto
- 配置console口密码
SW1>en SW1#conf t Enter configuration commands, one per line. End with CNTL/Z. SW1(config)#line console 0 // 进入console 0 SW1(config-line)#password 123 // 设置密码 SW1(config-line)#login // 应用
- 配置特权模式密码
Switch>en Switch#conf t Enter configuration commands, one per line. End with CNTL/Z. Switch(config)#enable password 123 // 配置明文密码 Switch(config)#enable secret 456 // 配置密文密码 # 当为设备特权模式同时设置明文和密文密码时,密文密码生效
- 永久关闭地址解析
用思科模拟器做交换机/路由器的实验中,由于命令打错,就会出现地址解析,要等待一段时间才可以再进行配置,解决配置命令错误时的缓冲时间。Switch>en Switch#conf t Switch(config)#no ip domain-lookup
三、交换机配置远程登录
1. telnet 方式
Telnet 协议是 TCP/IP 协议族中的一员,是 Internet 远程登录服务的标准协议和主要方式(基于 TCP 的 23 号端口)。
#使用用户名、密码进行远程登录
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#ip default-gateway 192.168.1.254 // 配置网关
Switch(config)#int vlan 1 // 进入vlan 1,一般情况下vlan 1作为交换机的管理接口
Switch(config-if)#ip add 192.168.1.100 255.255.255.0 // 设置IP地址
Switch(config-if)#no shut // 开启接口
Switch(config-if)#exit
# telnet远程登录必须设置特权模式密码,如未设置,远程连接后无法进入特权模式
Switch(config)#enable secret 000 // 设置特权模式密文密码
Switch(config)#username chengdu secret 123 // 创建登录用户名和密文密码
Switch(config)#line vty 0 4 // 进入0-4虚拟终端
Switch(config-line)#login local // 使用用户名、密码登录
- 思科设备telnet连接认证方式
- no login:不认证
- login:直接使用密码登录
- login local:必须使用账号、密码进行登录
2. SSH 方式
SSH 为 Secure Shell 的缩写,由 IETF 的网络小组(Network Working Group)所制定;SSH 为建立在应用层基础上的安全协议。SSH 是较可靠,专为远程登录会话和其他网络服务提供安全性的协议。利用 SSH 协议可以有效防止远程管理过程中的信息泄露问题。(基于 TCP 的 22 号端口)
#使用用户名、密码进行远程登录
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#ip default-gateway 192.168.1.254 // 配置网关
Switch(config)#int vlan 1 //进入vlan 1,一般情况下vlan 1作为交换机的管理接口
Switch(config-if)#ip add 192.168.1.100 255.255.255.0 //设置IP地址
Switch(config-if)#no shut //开启接口
#远程登录必须设置特权模式密码,如未设置,远程连接后无法进入特权模式
Switch(config-if)#end
Switch#show ip ssh //查看设备是否支持ssh
Switch#conf t
Switch(config)#hostname SW //ssh创建密钥不能使用默认设备名,这里修改设备名称
SW(config)#ip domain-name woniu.com //配置域名
SW(config)#crypto key generate rsa //创建密钥对
The name for the keys will be: SW.woniu.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]: 2048 //密钥长度,默认512,这里修改为2048
% Generating 2048 bit RSA keys, keys will be non-exportable...[OK]
SW(config)#ip ssh time-out 30 //设置超时,单位秒
SW(config)#ip ssh authentication-retries 3 //设置认证次数
SW(config)#username zhangsan secret 123 //创建用户名和密文密码
SW(config)#line vty 0 4 // 进入0-4虚拟终端
SW(config-line)#transport input ssh //设置只允许SSH登录
SW(config-line)#login local
四、交换机其他配置
1. 设备管理
-
查看当前配置文件(存放在 RAM 当中,当设备重启后,里面的配置就没有了)
Switch#show running-config
-
查看保存配置文件( NVRAM )
Switch#show startup-config
-
保存当前配置文件
Switch#copy running-config startup-config Switch#write
-
删除保存配置文件
Switch#erase nvram:
2. 交换机密码恢复
让交换机在启动过程中不加载配置文件,将配置文件修改,从而就不会加载
- 拔掉交换机的插头,插上电源同时按住
MODE
键 - 出现
switch:
提示松开按键,初始化 Flashswitch:flash_init
- 将config.text文件改成config.old,完成后启动交换机
Switch:rename flash:config.text flash:config.old Switch:boot
- 重新启动后把配置文件的名字改回来
Switch# rename flash:config.old flash:config.text
- 手工加载配置文件
Switch# copy flash:config.text system:running-config
- 进入配置模式修改密码