交换机的基本配置


第 1 部分: 检验默认交换机配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Switch> enable  
//进入特权模式
Switch#
//特权模式提示符

Switch# show running-config
//检查当前的运行配置文件。

Switch# show startup-config
//检查 NVRAM 中的启动配置文件
(startup-config is not present:启动配置文件不存在)


Switch# show interface vlan1
//检查 VLAN 1 上 SVI 的特征(可查看 ip 地址, mac 地址)


Switch# show version
//检查交换机的 Cisco IOS 版本信息


Switch# show interface f0/6
//检查 PC-A 使用的 FastEthernet 接口的默认属性(可查看接口状态, mac 地址, 速率和双工设置)


Switch# show vlan
//检查交换机的默认 VLAN 设置(查看有哪些 vlan, 以及 vlan 有哪些接口)

第 2 部分: 配置基本网络设备设置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
//进入全局配置模式。
Switch> enable
Switch#
Switch# configure terminal

//分配交换机主机名。
Switch(config)# hostname S1

//配置密码加密。
S1(config)# service password-encryption

//指定 class 作为特权 EXEC 模式访问的加密密码。
S1(config)# enable secret class

//防止不必要的 DNS 查找。
S1(config)# no ip domain-lookup

//配置 MOTD 标语。
S1(config)# banner motd #Unauthorized access is strictly prohibited. #
//设置MOTD标语在交换机启动的时候会看到。
1
2
3
4
5
6
7
8
9
S1# configure terminal
S1(config)# vlan 99 //创建 vlan
S1(config-vlan)# exit
S1(config)# interface vlan99 //进入 vlan
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan99, changed state to down
S1(config-if)# ip address 192.168.1.2 255.255.255.0 //设置 ip 和子网掩码
S1(config-if)# no shutdown //更改 vlan 状态
S1(config-if)# exit
S1(config)#
1
2
3
4
5
//将所有用户端口分配到 VLAN 99。
S1(config)# interface range f0/1 – 24,g0/1 - 2
S1(config-if-range)# switchport access vlan 99
S1(config-if-range)# exit
S1(config)#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//检验所有用户端口都处于 VLAN 99 中
S1# show vlan brief

//设置交换机的默认网关
S1(config)# ip default-gateway 192.168.1.1

//设置远程 telnet 连接的时候需要密码
S1(config)# line con 0
S1(config-line)# password cisco
S1(config-line)# login
S1(config-line)# logging synchronous


//配置 vty 密码,否则无法通过 telnet 连接
S1(config)# line vty 0 15
S1(config-line)# password cisco
S1(config-line)# login
S1(config-line)# end

第 3 部分: 检验并测试网络连接

用命令行 telnet 192.168.1.2 连接交换机

1
2
3
4
5
//保存配置。
S1# copy running-config startup-config //保存配置信息,与write命令功能相同
Destination filename [startup-config]? [Enter]
Building configuration...
[OK]

第 4 部分: 管理 MAC 地址表

查看主机的 MAC 地址:
在 PC-A 的命令提示符下,发出 ipconfig /all 命令确定并记录 PC NIC 的第 2 层(物理)地址

1
2
3
4
5
6
7
8
//显示交换机的 MAC 地址表
S1# show mac address-table

//只显示动态获知的 MAC 地址
S1# show mac address-table dynamic

//清除动态 MAC 地址
S1# clear mac address-table dynamic
1
2
3
4
5
//设置静态 MAC 地址
S1(config)# mac address-table static 0050.56BE.6C89 vlan 99 interface fastethernet 0/6

//清除静态 MAC 地址
S1(config)# no mac address-table static 0050.56BE.6C89 vlan 99 interface fastethernet 0/6

第五部分

1
2
3
4
5
6
7
8
//为交换机配置特权模式访问密码
S1(config)#enable password 123

//检查交换机 NVRAM 中的启动配置文件命令
S1#show startup-config

//检查交换机当前的运行配置文件命令
S1#show running-config