一、配置本地用戶認證
全局配置模式下
configure terminal
創建用戶,配置用戶名為test用戶,密碼為test,權限為15級
username test privilege 15 password 0 test
打開本地認證方式
authentication line vty login local
配置特權密碼testpassword
enable password level 15 testpassword
配置示例:
Switch>enable
Switch#configure terminal
Switch(config)#username test privilege 15 password 0 test
Switch(config)#authentication line vty login local
Switch(config)#enable password level 15 testpassword
二、配置VLAN
全局配置模式下,創建vlan 10
Vlan 10
添加描述信息
name Bangong
配置示例:
Switch(config)#vlan 10
Switch(config-vlan10)#name bangong
三、端口加入VLAN
配置access類型端口
全局模式下進入端口配置模式
進入G0/1
interface gigabitethernet0/1
配置端口類型為access
switchport mode access
配置端口所屬vlan
switchport access vlan 10
打開端口(如果端口關閉)
no shutdown
配置示例:
Switch#configure terminal
Switch(config)#interface gigabitethernet 0/1
Switch(config-if-gigabitethernet0/1)#switchport mode access
Switch(config-if-gigabitethernet0/1)#switchport access vlan 10
Switch(config-if-gigabitethernet0/1)#no shutdown
Switch(config-if-gigabitethernet0/1)#exit
Switch(config)#exit
Switch#
配置trunk類型端口(trunk類型端口適用于交換機接交換機)
全局模式下進入端口配置模式
進入G0/48
interface gigabitethernet0/48
配置端口模式為trunk模式
switchport mode trunk
配置端口允許通過的VLAN
switchport trunk allowed vlan all
配置默認的pvid,不配置的情況下默認pvid為1
switchport trunk pvid vlan 1
配置示例:
Switch#configure terminal
Switch(config)#interface gigabitethernet 0/48
Switch(config-if-gigabitethernet0/48)#switchport mode trunk
Switch(config-if-gigabitethernet0/48)#switchport trunk allowed vlan all
Switch(config-if-gigabitethernet0/48)#switchport trunk pvid vlan 1
Switch(config-if-gigabitethernet0/48)#no shutdown
Switch(config-if-gigabitethernet0/48)#exit
Switch(config)#exit
Switch#
三、配置接口 VLAN IP
全局模式下進入vlanif接口配置模式
進入vlan10 三層接口
interface vlan 10
配置IP地址 192.168.1.1 掩碼255.255.255.0
ip address 192.168.1.1 255.255.255.0
配置示例:
Switch#configure terminal
Switch(config)#interface vlan 10
Switch(config-if-vlan10)#ip address 192.168.1.1 255.255.255.0
Switch(config-if-vlan10)#exit
Switch(config)#exit
Switch#
四、配置靜態默認路由
全局配置模式下,配置默認路由的下一跳為192.168.1.2
ip route 0.0.0.0 0.0.0.0 192.168.1.2
靜態路由配置和默認路由配置命令一樣,命令中前0.0.0.0 代表網絡號,后面一個0.0.0.0代表掩碼。這8個0則能代表所有網段。代碼一個24未掩碼的網段表示:192.168.2.0 255.255.255.0
配置靜態路由:
ip route 192.168.2.0 255.255.255.0 192.168.1.2
配置示例:
Switch(config)#ip route 0.0.0.0 0.0.0.0 192.168.1.2
五、配置生成樹選項
生成樹配置需要結合當地網絡進行配置,要所有運行在一個拓撲能開啟生成樹功能的交換機,生成樹配置一樣。如果不知道在運行的生成樹實例的情況下,建議暫時不配置生成樹,避免生成樹造成沖突。
全局模式下開啟生成樹功能
spanning-tree enable
全局模式下關閉生成樹功能
no spanning-tree enable
配置生成樹模式為mstp
spanning-tree mode mstp
進入多實例生成樹MSTP配置
spanning-tree mst configuration
配置生成樹域名test
region-name test
配置實例1包含vlan10
instance 1 vlan 10
配置實例2包含vlan20
instance 2 vlan 20
激活生成樹配置
active configuration pending
不包含實例中的vlan,全部屬于默認實例0,如vlan1默認屬于實例0
配置示例:
Switch#configure terminal
(config)#spanning-tree enable
Switch(config)#spanning-tree mode mstp
Switch(config)#spanning-tree mst configuration
Switch(config-mst)#region-name test
Switch(config-mst)#instance 1 vlan 10
Switch(config-mst)#instance 2 vlan 20
Switch(config-mst)#active configuration pending
Switch(config-mst)#exit
Switch(config)#
六、配置ACL訪問控制策略
進入acl配置模式
ip access-list standard 100 #數字可配置1-1000,基礎ACL配置,供電網絡中采用基礎acl#
配置一條允許23.50.0.99主機
10 permit host 23.50.6.99
配置一條允許23.50.6.0網段
20 permit 23.50.6.0 255.255.255.0
剩余的全部禁止
30 deny any
配置acl注意匹配規則是從上往下匹配,比如deny any已經拒絕了除10,20匹配到的,剩余的都是禁止。這時候40 permit 23.50.7.0 0.0.0.255,則該策略不生效,23.50.7.0網段還是被全部禁止。
配置示例:
Switch(config)#ip access-list standard 100
Switch(config-std-nacl)#10 permit host 23.50.6.99
Switch(config-std-nacl)#20 permit 23.50.6.0 255.255.255.0
Switch(config-std-nacl)#30 deny any
七、配置SSH遠程登陸
全局開啟ssh服務
ip ssh server
進入配置交換機的vty接口模式下,下面相當于可以同時5個人登陸這臺交換機
user-interface vty 0 4
配置遠程登陸的認證模式為AAA,即為本地用戶認證
login local
設置超時5分鐘自動斷開回話
exec-timeout 5 0
配置只允許ssh方式登陸交換機
Protocol input ssh
配置示例:
Switch(config)#line vty 0 4
Switch(config-line)#login local
Switch(config-line)#exec-timeout 5 0
Switch(config-line)#protocol input ssh
Switch(config-line)#privilege level 0
Switch(config-line)#exit
Switch(config)#
八、配置時鐘同步和時區
全局模式下配置時區為北京時區(加8小時)
clock timezone beijin 8
全局模式下配置時鐘服務器10.109.192.5為第一個時鐘服務器
ntp server 10.109.192.5
全局模式下配置時鐘服務器10.109.192.43為備用時鐘服務器
ntp server 10.109.192.43
配置示例:
Switch#configure terminal
Switch(config)#clock timezone beijin 8
Switch(config)#ntp server 10.109.192.5
Switch(config)#ntp server 10.109.192.5
九、備份和還原IOS
特權配置模式下進入文件操作管理
filesystem
交換機用戶模式下通過tftp備份iso固件到23.50.6.99服務器
格式:copy file-system 本地固件文件名 tftp 服務器IP 遠程文件名
copy file-system web-Spl-1.1.235.rom tftp 23.50.6.99 123.rom
交換機用戶模式下通過tftp服務器還原IOS到交換機中
格式:copy tftp 服務器IP 遠程文件名file-system 本地固件文件名
copy tftp 23.50.6.99 234 file-system 234
使用dir命令,查看交換機固件的文件名稱
配置示例:
Switch#filesystem
Switch(config-fs)#dir
Switch(config-fs)#copy file-system sp4-g-6.6.4.1.18(C).pck tftp 23.50.6.99 123.pck
Switch(config-fs)#copy tftp 23.50.6.99 123.pck file-system sp4-g-6.6.4.1.18(C).pck
Tftp服務器可以下載軟件3CDaemon在電腦上運行即可。
十一、交換機常規巡檢命令
查看三層接口Ip地址
show ip interface brief
查看二層接口狀態信息
show interface switchport brief
查看交換機的mac地址表
show mac-address all
查看交換機的arp表
show arp
查看交換機的生成樹狀態
show spanning-tree
查看交換機版本
show version
查看交換機系統時間
show clock
查看交換機電源狀態
show power
查看交換機cpu使用狀態
show cpu monitor
查看交換機內存使用狀態
show memory