Switch命令汇总
生活随笔
收集整理的這篇文章主要介紹了
Switch命令汇总
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Part1.Smartports宏 ? Smartports宏是預先訂制的配置腳本,可用于絕大多數(shù)的Cisco交換機上。通過使用這些腳本,不僅可以建立更穩(wěn)定的端口配置,甚至可能防止未來出現(xiàn)問題。默認狀態(tài)下,Cisco交換機提供的宏覆蓋了下述這些種類的設備: Cisco-desktop,Cisco-phone,Cisco-switch,Cisco-router和Cisco-wireless。每個宏對應的命令如下:
1)針對終端PC的宏cisco-desktop switchport mode access????????????????????????? switchport port-security switchport port-security aging time 2 switchport port-security violation restrict switchport port-security aging type inactivity macro de.ion cisco-desktop spanning-tree portfast spanning-tree bpduguard enable?
? 2)針對SW的宏cisco-switch switchport trunk encapsulation dot1q?????????? switchport mode trunk macro de.ion cisco-switch auto qos voip trust spanning-tree link-type point-to-point
3)針對Router的宏cisco-router switchport trunk encapsulation dot1q??????????? switchport mode trunk mls qos trust dscp macro de.ion cisco-router auto qos voip trust spanning-tree portfast trunk spanning-tree bpduguard enable
4)針對IP Phone的宏cisco-phone switchport mode access???????????????????????? switchport voice vlan 1 switchport port-security switchport port-security maximum 3 switchport port-security aging time 2 switchport port-security violation restrict switchport port-security aging type inactivity macro de.ion cisco-phone auto qos voip cisco-phone spanning-tree portfast spanning-tree bpduguard enable
5)針對無線AP的宏cisco-wireless switchport trunk encapsulation dot1q switchport mode trunk switchport nonegotiate mls qos trust cos macro de.ion cisco-wireless auto qos voip trust spanning-tree bpduguard enable
啟用Smartports的方式: Switch(config)# int fa0/19?? Switch(config-if)# macro apply cisco-desktop $access_vlan 1? //需要定義這個端口成為哪個VLAN的一部分 Switch(config-if)#show parser macro????????????????????????????????????????//這個命令會顯示每個宏所作的工作
當然,我們也可以自己定義一個宏: Switch(config)# macro name steven?????????????? switchport mode access spanning-tree portfast spanning-tree bpduguard enable switchport port-security maximum 1????????????????????????? //定義可以連接的設備的數(shù)量上限 switchport access vlan 1???????????????????????????????????????????? ?//將該端口歸入vlan1 @???????????????????????????????????????????????????????????????????????????????? //通過@符號結束宏 Switch(config)# interface gigabitethernet1/0/2??????????? //接口下啟用宏 Switch(config-if)# macro apply steven???
Part2.Switch基本配置 ? Switch(config)#hostname HostName??????????????????????? ?//配置主機名 Switch#show running-config????????????????????????????????????? //查看配置信息(RAM) Switch(config)#enable password password????????????? ?//配置明文口令 Switch(config)#enable secret password???????????????????? //配置加密口令
??????????
Switch(config)#ip default-gateway ip-address????????? ?//配置網(wǎng)關 Switch#show mac-address-table??????????????????????????????? //查看CAM表 ? Switch(config)#interface vlan1????????????????????????????????? //定義一個三層虛接口 Switch(config)#ip address ip-address mask??????????????//配置IP地址 Switch(config-if)#no shutdown????????????????????????????? ?? //開啟端口 ? Switch#copy running-config startup-config????????????? //保存與刪除交換機配置 Switch#write???????????????????????????????????????????????????????????? ?//同上 Switch#erase startup-config????????????????????????????????????? //恢復交換機出廠配置 ? switch(config-if)# de.ion de.ion-string?? ?? //端口描述 switch(config-if)# speed {10|100|auto}????????????? ????? //設置端口速率 switch(config-if)# duplex {auto|full|half}????????????? ?? //設置雙工模式 Switch#show logging??????????????????????????????????????????? ? ? //顯示系統(tǒng)日志
Part3.Vlan配置 ? Switch(config)#vlan vlan-id? &? Switch(config)#name vlan-name????????? ?//創(chuàng)建Vlan Method1 Switch#vlan database? &? Switch(vlan)#vlan vlan-id name vlan-name??? //創(chuàng)建Vlan Method2 ? Switch(config or vlan)#no vlan vlan-id?????????????????????????????????????????????????? ?//刪除Vlan ? Switch(config-if)#Switchport mode access???????????????????????????????????????????? //定義接入端口step1 Switch(config-if)#Switch access vlan vlan-id??????????????????????????????????????? ??//定義接入端口step2 ? Switch(config-if-range)# switchport host????????????????????????????????????????????? ?//該組端口為Access & 啟用PortFast & No Channel????????????? ??????? Switch#show vlan brief???????????????????????????????????????????????? ?//查看VLAN信息????????? Switch#show vlan id vlan-id????????????????????????????????????????? //查看某個VLAN的信息??? Switch#show running-config interface interface-id????????//驗證端口的VLAN號????? Switch#show interface interface-id Switch port??????????? //驗證端口的管理模式和VLAN的情況
????
switch(config-if)# switchport mode trunk???????????????????????????????????????? ?//定義中繼鏈路 switch(config-if)# switchport trunk encapsulation {isl|dotlq}?????????? //選擇中繼封裝類型 ? switch(config-if)# switchport trunk allowed vlan remove vlan-list??? //刪除允許通過此中繼鏈路的Vlan switch(config-if)# switchport trunk allowed vlan add vlan-list???????? ?//添加允許通過此中繼鏈路的Vlan ? switch(config-if)# switchport nonegotiate???????????????????????????????????????? //關閉DTP協(xié)商
Part4.VTP配置 ? switch# vlan database switch(vlan)# vtp domain domain-name???????????? //定義一個VTP域 switch(vlan)# vtp {sever|cilent|transparent}????? //定義SW在域中角色 switch(vlan)# vtp password password????????????? //設置VTP密碼 switch(vlan)# vtp v2-mode?????????????????????????????? ?//設置VTP版本 switch(vlan)# vtp pruning??????????????????????????????? ? //啟用VTP剪裁 switch#show vtp domain /statistics?????????????????? //顯示管理域的VTP參數(shù).
Part5.STP配置 ? switch(config-if)# spanning-tree vlan vlan-id?root primary?????//指定根網(wǎng)橋???????? switch(config-if)# spanning-tree vlan vlan-id cost num????????? //定義Vlan生成樹端口開銷? switch(config-if)# spanning-tree vlan vlan-id priority num?????//定義Vlan的網(wǎng)橋優(yōu)先級(推薦) ? switch(config)# spanning-tree uplinkfast??????????????????????????????? //配置UplinkFast switch(config)# spanning-tree backbonefast???????????????????????? ? //配置BackboneFast????????
???
switch(config-if)# spanning-tree guard root????????????????????? //配置根防御 switch(config-if)# spanning-tree guard loop???????????????????? //配置環(huán)防御 switch(config)# interface range fa2/1 - 2/28?????????????????? ? ?//配置快速端口 switch(config-if or -range)# spanning-tree portfast???????? ?//全局配置or端口配置or局部端口 Switch(config)# spanning-tree portfast default????????????????//設置所有access port為PortFast ? switch# show spanning-tree vlan vlan-id???????????????????????? //顯示STP信息 switch# show spanning-tree vlan vlan-id detail????????????????//顯示STP詳細信息 switch# debug spanning-tree events????????????????????????????????//調試STP
?
switch(config)# spanning-tree [vlan vlan-list] hello-time seconds switch(config)# spanning-tree [vlan vlan-list] forward-time seconds switch(config)# spanning-tree [vlan vlan-list] max-age seconds
Part6.Feature配置 ? switch(config)# cdp run????????????????????????????? //全局下啟用CDP switch(config-if)# cdp enable????????????????????? //接口下啟用CDP Switch#show cdp??????????????????????????????????????? //查看CDP全局配置信息 Switch#show cdp interface f0/19????????????????//顯示f0/19接口的CDP配置信息 Switch#show cdp traffic???????????????????????????? //顯示有關CDP包的統(tǒng)計信息 Switch#show cdp neighbors???????????????????????//以簡潔的形式列出與本設備相鄰的Cisco設備 Switch#show cdp neighbors detail?????????????//顯示相鄰Cisco設備的詳細信息
switch(config-if)# udld port aggressive??????????? //啟用UDLD積極模式 switch# show udld GigabitEthernet 0/1?????????? //查看UDLD積極模式
switch(config-if)# channel-group port-channel-number mode desirable? //將EtherChannel分配到EtherChannel組中(PAgP) switch(config-if)# channel-protocol lacp?????????????????????????????????????????? ?//指定采用LACP協(xié)議 switch(config-if)# channel-group group-number mode active??????????? //將端口分配給LACP EtherChannel ?
1)針對終端PC的宏cisco-desktop switchport mode access????????????????????????? switchport port-security switchport port-security aging time 2 switchport port-security violation restrict switchport port-security aging type inactivity macro de.ion cisco-desktop spanning-tree portfast spanning-tree bpduguard enable?
? 2)針對SW的宏cisco-switch switchport trunk encapsulation dot1q?????????? switchport mode trunk macro de.ion cisco-switch auto qos voip trust spanning-tree link-type point-to-point
3)針對Router的宏cisco-router switchport trunk encapsulation dot1q??????????? switchport mode trunk mls qos trust dscp macro de.ion cisco-router auto qos voip trust spanning-tree portfast trunk spanning-tree bpduguard enable
4)針對IP Phone的宏cisco-phone switchport mode access???????????????????????? switchport voice vlan 1 switchport port-security switchport port-security maximum 3 switchport port-security aging time 2 switchport port-security violation restrict switchport port-security aging type inactivity macro de.ion cisco-phone auto qos voip cisco-phone spanning-tree portfast spanning-tree bpduguard enable
5)針對無線AP的宏cisco-wireless switchport trunk encapsulation dot1q switchport mode trunk switchport nonegotiate mls qos trust cos macro de.ion cisco-wireless auto qos voip trust spanning-tree bpduguard enable
啟用Smartports的方式: Switch(config)# int fa0/19?? Switch(config-if)# macro apply cisco-desktop $access_vlan 1? //需要定義這個端口成為哪個VLAN的一部分 Switch(config-if)#show parser macro????????????????????????????????????????//這個命令會顯示每個宏所作的工作
當然,我們也可以自己定義一個宏: Switch(config)# macro name steven?????????????? switchport mode access spanning-tree portfast spanning-tree bpduguard enable switchport port-security maximum 1????????????????????????? //定義可以連接的設備的數(shù)量上限 switchport access vlan 1???????????????????????????????????????????? ?//將該端口歸入vlan1 @???????????????????????????????????????????????????????????????????????????????? //通過@符號結束宏 Switch(config)# interface gigabitethernet1/0/2??????????? //接口下啟用宏 Switch(config-if)# macro apply steven???
Part2.Switch基本配置 ? Switch(config)#hostname HostName??????????????????????? ?//配置主機名 Switch#show running-config????????????????????????????????????? //查看配置信息(RAM) Switch(config)#enable password password????????????? ?//配置明文口令 Switch(config)#enable secret password???????????????????? //配置加密口令
??????????
Switch(config)#ip default-gateway ip-address????????? ?//配置網(wǎng)關 Switch#show mac-address-table??????????????????????????????? //查看CAM表 ? Switch(config)#interface vlan1????????????????????????????????? //定義一個三層虛接口 Switch(config)#ip address ip-address mask??????????????//配置IP地址 Switch(config-if)#no shutdown????????????????????????????? ?? //開啟端口 ? Switch#copy running-config startup-config????????????? //保存與刪除交換機配置 Switch#write???????????????????????????????????????????????????????????? ?//同上 Switch#erase startup-config????????????????????????????????????? //恢復交換機出廠配置 ? switch(config-if)# de.ion de.ion-string?? ?? //端口描述 switch(config-if)# speed {10|100|auto}????????????? ????? //設置端口速率 switch(config-if)# duplex {auto|full|half}????????????? ?? //設置雙工模式 Switch#show logging??????????????????????????????????????????? ? ? //顯示系統(tǒng)日志
Part3.Vlan配置 ? Switch(config)#vlan vlan-id? &? Switch(config)#name vlan-name????????? ?//創(chuàng)建Vlan Method1 Switch#vlan database? &? Switch(vlan)#vlan vlan-id name vlan-name??? //創(chuàng)建Vlan Method2 ? Switch(config or vlan)#no vlan vlan-id?????????????????????????????????????????????????? ?//刪除Vlan ? Switch(config-if)#Switchport mode access???????????????????????????????????????????? //定義接入端口step1 Switch(config-if)#Switch access vlan vlan-id??????????????????????????????????????? ??//定義接入端口step2 ? Switch(config-if-range)# switchport host????????????????????????????????????????????? ?//該組端口為Access & 啟用PortFast & No Channel????????????? ??????? Switch#show vlan brief???????????????????????????????????????????????? ?//查看VLAN信息????????? Switch#show vlan id vlan-id????????????????????????????????????????? //查看某個VLAN的信息??? Switch#show running-config interface interface-id????????//驗證端口的VLAN號????? Switch#show interface interface-id Switch port??????????? //驗證端口的管理模式和VLAN的情況
????
switch(config-if)# switchport mode trunk???????????????????????????????????????? ?//定義中繼鏈路 switch(config-if)# switchport trunk encapsulation {isl|dotlq}?????????? //選擇中繼封裝類型 ? switch(config-if)# switchport trunk allowed vlan remove vlan-list??? //刪除允許通過此中繼鏈路的Vlan switch(config-if)# switchport trunk allowed vlan add vlan-list???????? ?//添加允許通過此中繼鏈路的Vlan ? switch(config-if)# switchport nonegotiate???????????????????????????????????????? //關閉DTP協(xié)商
Part4.VTP配置 ? switch# vlan database switch(vlan)# vtp domain domain-name???????????? //定義一個VTP域 switch(vlan)# vtp {sever|cilent|transparent}????? //定義SW在域中角色 switch(vlan)# vtp password password????????????? //設置VTP密碼 switch(vlan)# vtp v2-mode?????????????????????????????? ?//設置VTP版本 switch(vlan)# vtp pruning??????????????????????????????? ? //啟用VTP剪裁 switch#show vtp domain /statistics?????????????????? //顯示管理域的VTP參數(shù).
Part5.STP配置 ? switch(config-if)# spanning-tree vlan vlan-id?root primary?????//指定根網(wǎng)橋???????? switch(config-if)# spanning-tree vlan vlan-id cost num????????? //定義Vlan生成樹端口開銷? switch(config-if)# spanning-tree vlan vlan-id priority num?????//定義Vlan的網(wǎng)橋優(yōu)先級(推薦) ? switch(config)# spanning-tree uplinkfast??????????????????????????????? //配置UplinkFast switch(config)# spanning-tree backbonefast???????????????????????? ? //配置BackboneFast????????
???
switch(config-if)# spanning-tree guard root????????????????????? //配置根防御 switch(config-if)# spanning-tree guard loop???????????????????? //配置環(huán)防御 switch(config)# interface range fa2/1 - 2/28?????????????????? ? ?//配置快速端口 switch(config-if or -range)# spanning-tree portfast???????? ?//全局配置or端口配置or局部端口 Switch(config)# spanning-tree portfast default????????????????//設置所有access port為PortFast ? switch# show spanning-tree vlan vlan-id???????????????????????? //顯示STP信息 switch# show spanning-tree vlan vlan-id detail????????????????//顯示STP詳細信息 switch# debug spanning-tree events????????????????????????????????//調試STP
?
switch(config)# spanning-tree [vlan vlan-list] hello-time seconds switch(config)# spanning-tree [vlan vlan-list] forward-time seconds switch(config)# spanning-tree [vlan vlan-list] max-age seconds
Part6.Feature配置 ? switch(config)# cdp run????????????????????????????? //全局下啟用CDP switch(config-if)# cdp enable????????????????????? //接口下啟用CDP Switch#show cdp??????????????????????????????????????? //查看CDP全局配置信息 Switch#show cdp interface f0/19????????????????//顯示f0/19接口的CDP配置信息 Switch#show cdp traffic???????????????????????????? //顯示有關CDP包的統(tǒng)計信息 Switch#show cdp neighbors???????????????????????//以簡潔的形式列出與本設備相鄰的Cisco設備 Switch#show cdp neighbors detail?????????????//顯示相鄰Cisco設備的詳細信息
switch(config-if)# udld port aggressive??????????? //啟用UDLD積極模式 switch# show udld GigabitEthernet 0/1?????????? //查看UDLD積極模式
switch(config-if)# channel-group port-channel-number mode desirable? //將EtherChannel分配到EtherChannel組中(PAgP) switch(config-if)# channel-protocol lacp?????????????????????????????????????????? ?//指定采用LACP協(xié)議 switch(config-if)# channel-group group-number mode active??????????? //將端口分配給LACP EtherChannel ?
轉載于:https://blog.51cto.com/steven24/70018
總結
以上是生活随笔為你收集整理的Switch命令汇总的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [翻译]一步步教你配置SQL SERVE
- 下一篇: 旧金山GDC2008见闻一