Cisco 交換機基本配置命令及學(xué)習(xí)心得

1:配置登錄用戶,口令等
Switch> //用戶直行模式提示符
Switch>enable //進入特權(quán)模式
Switch# //特權(quán)模式(配置密碼后必須輸入密碼才可進入特 權(quán)模式)
Switch#config terminal //進入全局配置模式
Switch(config)# //配置模式提示符
Switch(config)#hostname xxx //設(shè)置主機名成為xxx這里使用CISCO 2960G
CISCO 2960G(config)#enable password xxx //設(shè)置使能口令為明文顯示為xxx
CISCO 2960G(config)#enable secret xxx //設(shè)置使能口令為密文顯示為xxx
CISCO 2960G(config)#line vty 0 15 //設(shè)置虛擬終端線,通過telnet方式 登錄允許0-15個用戶同事登錄
CISCO 2960G(config-line)#login //設(shè)置遠程telnet遠程登錄驗證
CISCO 2960G(config-line)#password xxx //設(shè)置telnet登錄密碼
2:cisco2960 VLan設(shè)置
CISCO 2960G> enable //進入特權(quán)模式
CISCO 2960G#vlan database //進入vlan設(shè)置
CISCO 2960G(vlan)#vlan 2 name xxx //創(chuàng)建vlan 2,并給vlan命名
CISCO 2960G(vlan)#no vlan 2 v //刪除vlan 2
CISCO 2960G(vlan)#exit //回到特權(quán)模式下
端口設(shè)置命令:
CISCO 2960G(config)#interface fastethernet0/1 //進入網(wǎng)口1,簡化命令 int f0/1 ,0/1指的是第一個插槽上的第一個網(wǎng)口
CISCO 2960G(config-if)# //接口視圖模式
CISCO 2960G(config-if)#shutdown //關(guān)閉當(dāng)前端口
CISCO 2960G(config-if)#no shutdown //打開當(dāng)前端口
CISCO 2960G(config)#interface gigabyte0/1 //進入?yún)R聚千兆口1,簡化命令 int giga0/1指的是第一個插槽上的第一個匯聚網(wǎng)口
CISCO 2960G(config-if)#
CISCO 2960G(config-if)#duplex auto/full/half //設(shè)置端口工作模式為 自適應(yīng)/全雙通/半雙通
CISCO 2960G(config-if)#switchport mode trunk //設(shè)置當(dāng)前端口模式為匯聚口
CISCO 2960G(config-if)#switchport mode access //設(shè)置當(dāng)前端口模式為接入模式
CISCO 2960G(config-if)#switchport trunk allowed vlan 1,2 //設(shè)置當(dāng)前匯聚端口允許vlan1,2通過,vlan修剪,默認為all,全部允許
CISCO 2960G(config-if)#switchport trunk vlan 2 //設(shè)置當(dāng)前匯聚端口允許vlan 2通過,vlan修剪
CISCO 2960G(config-if)#switchport access vlan 2 //將當(dāng)前端口加入到vlan 2中
CISCO 2960G(config-if)#switchport trunk encap dot1q //設(shè)置vlan中繼
將端口加入vlan
CISCO 2960G(config)#interface fastethernet0/1
CISCO 2960G(config-if)#switchport mode access
CISCO 2960G(config-if)#switchport access vlan 2
將多個端口加入到VLAN中
CISCO 2960G(config)#interface range f0/1 - 10
CISCO 2960G(config-if-range)#switchport mode access
CISCO 2960G(config-if-range)#switchport access vlan 2
CISCO 2960G#show vlan brief //用于查看配置后結(jié)果
CISCO 2960G#show vlan //用于查看配置后結(jié)果
3:設(shè)置VTP cisco專有的vlan終極協(xié)議也成為局域網(wǎng)干道協(xié)議,作用是十幾臺交換機在企業(yè)網(wǎng)中,配置VLAN工作量大,可以使用VTP協(xié)議,把一臺交換機配置成VTP Server, 其余交換機配置成VTP Client,這樣他們可以自動學(xué)習(xí)到server 上的VLAN 信息
switch(config)#vtp domain xxxx //設(shè)置發(fā)vtp域名
switch(config)#vtp password xxxx //設(shè)置發(fā)vtp密碼
switch(config)#vtp mode server //設(shè)置發(fā)vtp模式為 vtp服務(wù)器
switch(config)#vtp mode client //設(shè)置發(fā)vtp模式為 vtp客戶端
4:交換機配置IP地址
switch(config)#interface vlan 1 //進入vlan 1
switch(config-if)#ip address 119.167.223.221 255.255.255.128 //設(shè)置交換機的管理ip地址
switch(config)#ip default-gateway 119.167.223.254 //設(shè)置交換機的默認網(wǎng)關(guān)
switch(config)#end //退出當(dāng)前模式
5: 交換機保存設(shè)置命令
switch#write //保存配置信息
switch#copy running-config startup-config //將當(dāng)前正在使用中的配置保存到交換機開機需要加載的配置文件里去。
6:交換機顯示命令
特權(quán)模式下:
switch#show vtp //顯示vtp配置信息
switch#show run //顯示當(dāng)前配置信息
switch#show running-config //顯示當(dāng)前正在使用的配置信息
switch#show startup-config //交換機開機是自動加載的 配置文件
switch#show vlan //顯示vlaner配置信息
switch#show interfaces //顯示端口配置信息
switch#show interfaces fastethernet 0/1 switchport //顯示二層端口狀態(tài),可以用來決定此口是否為二層或三層口
switch#show int f0/1 //查看指定端口配置信息 show interface fastethernet0/1
switch#show ip interface vlan100 //查看交換機vlan100的ip配置信息
switch#show version //查看交換機固件版本信息
7:基于端口的mac地址綁定
switch#config terminal //進入配置視圖模式
switch(config)#interface fasrethernet 0/1 //進入具體端口視圖模式下
switch(config-if)#switchport port-secruity //配置端口安全模式
switch(config-if)#switchport port-secruity mac-address MAC(主機的mac地址) //配置該端口要綁定的主機的MAC地址
switch(config-if)#no switchport port-secruity mac-address MAC(主機的mac地址) //刪除綁定主機的mac地址
8:配置交換機的snmp功能
switch(config)#snmp-server community xxx ro //xxx為自定義的共同體名稱,并且團體的權(quán)限為只讀。
switch(config)#snmp-server trap-source FastEthernet0/3/0 //設(shè)置snmp監(jiān)控的端口,此端口必須要配置IP地址才行
switch(config)#snmp-server trap-source vlan 100 /把vlan 100接口作為監(jiān)控端口
switch(config)#snmp-server host x.x.x.x(ip地址) xxx(團體名) //設(shè)置管理機x.x.x.x,同時允許該管理機以團體明xxx訪問。
switch(config)#snmp-server host 119.167.223.221 zy //例子
switch(config)#snmp-server enable traps //啟用snmp服務(wù)
9:交換機禁ping配置
switch(config)#access-list 110 deny icmp any any //配置訪問控制列表(Access Control List,ACL)110指的ICMP對應(yīng)ping。
switch(config)#access-list 110 permit ip any any //運行所有的IP協(xié)議的應(yīng)用
switch(config)#int vlan 1
switch(config-if)#ip access-group 110 in
switch(config)#int vlan 2
switch(config-if)#ip access-group 110 in
switch(config)#int vlan 3
switch(config-if)#ip access-group 110 in
switch(config)#int fasrethernet 0/X
switch(config-if)#ip access-group 110 in //端口X上禁ping
.
.
.
10:恢復(fù)交換機出廠設(shè)置
思科交換機分為兩種系統(tǒng),分別是IOS和CatOS,下面介紹IOS版本的操作,
Switch#write erase
Erasing the nvram filesystem will remove all files! Continue? [confirm]y[OK]
Erase of nvram: complete
Swtich# delete flash:vlan.dat ------------老版本需做此操作。
Delete filename [vlan.dat]?
Delete flash:vlan.dat? [confirm]y
Switch#reload
另一種方法是啟動的時候按Mode進入引導(dǎo)模式,執(zhí)行如下命令:
flash_init
rename flash:config.text flash:config.old
boot
11: 端口匯聚
console>enable
console#config
console(config)#interface gigaethernet 0/1
console(config-if)#speed 1000
console(config-if)#duplex full
console(config)#interface gigaethernet 0/2
console(config-if)#speed 1000
console(config-if)#duplex full
console(config-if)#exit
console(config)#interface range gigaethernet 0/1-0/2
console(config-if)#channel-group 1 mode on/auto
console(config-if)#switchport mode trunk
console(config-if)#switchport trunk allowed vlan all
console#show etherchannel summary //查看端口匯聚狀態(tài)。
另外一臺交換機的對應(yīng)匯聚端口務(wù)必要和這里兩個匯聚口的設(shè)置一樣。
R1#vlan database
R1(vlan)#vlan 2
R1(vlan)#exit
R1#configure terminal
R1(config)#int range fastethernet 0/1-4
R1(config-int-range)# switchport access vlan 2
R1(config-int-range)# channel-group 1 mode on
R2#vlan database
R2(vlan)#vlan 2
R2(vlan)#exit
R2#configure terminal
R2(config)#int range fastethernet 0/1-4
R2(config-int-range)# switchport access vlan 2
R2(config-int-range)# channel-group 1 mode on
同一個vlan里匯聚,端口使用access狀態(tài),多個VLAN之間匯聚端口才需要trunk狀態(tài)。
***心得***
這里對整個配置過程中需要注意的一些事項以及自己出錯的一些地方做一下總結(jié):
1:配置cisco 2960G禁ping的時候出現(xiàn)了一個錯誤,由于照搬了網(wǎng)上的命令行,實際使用發(fā)現(xiàn)無法實現(xiàn)禁ping的效果,最后悟出來原來是加入的ip access-group xx必須與在配置視圖里邊配置的access-list xx保持一直才能行。
例子:
switch(config)#access-list 110 deny icmp any any //配置訪問控制列表(Access Control List,ACL)110指的ICMP對應(yīng)ping。
switch(config)#access-list 110 permit ip any any //運行所有的IP協(xié)議的應(yīng)用
switch(config)#int vlan 1
switch(config-if)#ip access-group 110 in
2:在配置交換機的snmp-server的時候,(1)需要配置的團體名字和權(quán)限snmp-server community xxx ro,(2)還有最重要的指定需要監(jiān)視的端口號,這個端口號需要可以配置IP,所以對于二層交換機2960而言,只有指定管理vlan的接口了。switch(config)#snmp-server trap-source vlan 100,(3)指定管理機器的IP并授權(quán)管理局以xxx團體名進行管理監(jiān)視端口switch(config)#snmp-server host x.x.x.x(ip地址) xxx(團體名) //設(shè)置管理機x.x.x.x,同時允許該管理機以團體明xxx訪問。
switch(config)#snmp-server host 119.167.223.221 zy //例子 (4)最后是開啟交換機的snmp-server功能switch(config)#snmp-server enable traps //啟用snmp服務(wù)
完整的例子:
switch(config)#snmp-server community xxx ro //xxx為自定義的共同體名稱,并且團體的權(quán)限為只讀。
switch(config)#snmp-server trap-source FastEthernet0/3/0 //設(shè)置snmp監(jiān)控的端口,此端口必須要配置IP地址才行
switch(config)#snmp-server trap-source vlan 100 /把vlan 100接口作為監(jiān)控端口
switch(config)#snmp-server host x.x.x.x(ip地址) xxx(團體名) //設(shè)置管理機x.x.x.x,同時允許該管理機以團體明xxx訪問。
switch(config)#snmp-server host 119.167.223.221 zy //例子
switch(config)#snmp-server enable traps //啟用snmp服務(wù)。
相關(guān)文章
聯(lián)果LG510S-4T2XS怎么樣? 六口全萬兆輕網(wǎng)管交換機拆解
聯(lián)果LG510S4T2XS是一臺”4+2″的全萬兆網(wǎng)管交換機,即擁有四個10G電口和兩個10G光口,下面我們就來看看這款交換機的拆機測評2025-01-172.5G三層網(wǎng)管交換機! TPLINK TL-SE5420不完全拆機測評
TL-SE5420為TP-LINK全新開發(fā)推出的5系列2.5G三層網(wǎng)管交換機,采用新一代高性能硬件和軟件平臺,提供靈活的2.5G接入和高性價比的萬 兆上行端口,下面我們就來看看這款交換機2025-01-07最便宜的8口2.5G網(wǎng)管交換機! 水星SE109 Pro拆機測評
水星SE109 Pro價格很便宜,水星SE109 Pro,外觀、接口,和SE109一樣,區(qū)別Pro是網(wǎng)管型的,下面我們就來看看詳細拆機測評2025-01-032.5G交換機水星SE109值得購買嗎? 水星SE109開箱測評
由于廉價家用2.5G交換機大都采用的是公版方案,因此芯片性能上就不用再做過多比較,只需要考慮品牌和口碑,經(jīng)過多輪篩選最終選擇了水星SE109,下面我們就來看看開箱圖2025-01-03TP-LINK/水星和hasivo交換機怎么選? 三款網(wǎng)管交換機系統(tǒng)功能對比
今天選了三款都是”8+1″的2.5G網(wǎng)管交換機,分別是TP-LINK 水星和hasivo交換機,該怎么選呢?這些交換機功能上有什么區(qū)別?詳細請看下文介紹2025-01-03海思視訊hasivo S5800W-24GT-6SX-SE 網(wǎng)管交換機拆機測評
hasivo S5800W-24GT-6SX-SE 網(wǎng)管交換機拆機,它有24個2.5G口+6個萬兆口,這款交換機怎么樣呢?下面我們就來看看詳細測評2024-12-07交換機單線復(fù)用怎么設(shè)置? 弱電箱到客廳只有一根網(wǎng)線的解決方案
如何解決弱電箱到客廳只預(yù)埋一根線的尷尬局面?在有辦法再增加網(wǎng)線的情況下,就可以使用兮克輕管理交換機做單線復(fù)用,輕松解決弱電箱到客廳線路不夠的問題2024-11-18水星SE106 Pro值得購買嗎? 2.5G網(wǎng)管交換機水星SE106 Pro拆機測評
水星SE106Pro是一款高性能的交換機,搭載RTL8372N芯片,支持4個2.5G口和2個10G光口,這款交換機怎么樣呢?詳細請看下文測評2024-11-112.5G/萬兆交換機性價比清單推薦! 百元出頭就能搭建萬兆局域網(wǎng)
2.5G交換機價格降下來了,在選擇交換機和路由器的時候,很糾結(jié),我們搜集、推薦一下有哪些性價比2.5G/萬兆交換機,這些均在百元出頭,還帶萬兆口2024-08-26- 這款交換機現(xiàn)在價格是129元,很懂盆友不知道該不該購買,下面我們就來看看小米千兆交換機SW-108G詳細的拆機圖2024-07-26