一、模式命令
1. 用戶模式
Switch>
2.特權模式:
Switch>enable
Switch#
3.全局配置模式:
Switch#config terminal
Switch(config)#
4.接口配置模式:
Switch(config)#interface fastethernet0/1
Switch(config-if)#
Switch# show interface status查看接口名稱
常用接口名稱有FastEthernet(百兆)、GigabitEthernet(千兆)和TenGigabitEthernet(萬兆)
交換機的端口工作模式一般可以分爲三種:Access,Multi,Trunk。trunk模式的端口用於交換機與交換機,交換機與路由器,大多用於級聯網絡設備。Access多用於接入層也叫接入模式。主要是將端口靜態接入(終端設備接入)。
Switch(config-if)#Switchport mode access (強制接口成爲access接口,並且可以與對方主動進行協商,誘使對方成爲access模式)
Switch(config-if)#switchport mode dynamic desirable:(主動與對協商成爲Trunk接口的可能性,如果鄰居接口模式爲Trunk/desirable/auto之一,則接口將變成trunk接口工作。如果不能形成trunk模式,則工作在access模式。這種模式是現在交換機的默認模式。)
Switch(config-if)#switchport mode dynamic auto(只有鄰居交換機主動與自己協商時纔會變成Trunk接口,所以它是一種被動模式,當鄰居接口爲Trunk/desirable之一時,纔會成爲Trunk。如果不能形成trunk模式,則工作在access模式)
Switch(config-if)#switchport mode trunk( 強制接口成爲Trunk接口,並且主動誘使對方成爲Trunk模式,所以當鄰居交換機接口爲trunk/desirable/auto時會成爲Trunk接口)
5.Line模式:
Switch(config)#line console 0
Switch(config-line)#
6.模式的返回:
返回上一級:
exit
返回特權模式:
Ctrl+Z
特權模式返回用戶模式:
disable
二、特權模式下的命令:
1. 查看機MAC地址:
Switch#show mac-address-table
2.發現(CDP):
Switch#show cdp
Switch#show cdp interface fastethernet0/1
Switch#show cdp neighbors
Switch#show cdp neighbors detail
Switch#show cdp entry
3.保存機配置:
Switch#copy running-config startup-config或者Switch#write
4.恢復交換機出廠值:
Switch#erase startup-config
Switch#reload
三、全局配置模式下的命令:
1. 配置主機名:
Switch(config)#hostname Sw1
Sw1(config)#
2.設置登陸臺密碼:
Switch(config)#line console 0 進入控制檯口
Switch(config-line)#line vty 0 4 ;進入虛擬終端
Switch(config-line)#password 密碼
Switch(config-line)#login 允許登錄
3.配置使用口令(只要用於用戶模式切換到特權模式時使用的口令,該口令是不加密的):
Switch(config)#enable password 密碼
Switch(config)#no enabled password 刪除密碼
4.配置加密口令
Switch(config)#enable secret 密碼
5.配置IP地址:
Switch(config)#interface vlan 1
Switch(config-if)#ip address IP地址 網關
Switch(config-if)#no shutdown
6.默認網關
二層交換機的端口是無法設置IP地址,但由於交換機都默認有一個VLAN1接口,VLAN接口是可以設置IP地址的,因此,對於二層交換機,其管理地址,就是VLAN1接口的地址
Switch#config t
Switch(config)#interface vlan 1
Switch(config-if)#ip address 192.168.1.254 255.255.255.0
Switch(config-if)#no shutdown
Switch(config-if)#exit
Switch(config)#
要跨網段去登錄連接到另一個網段的二層交換機,則必須給二層交換機配置指定默認網關,雙方的二層交換機都要配置指定默認網關地址。
Switch(config)#ip default-gateway 192.168.1.1
Switch(config)#exit
Switch#write
對於三層交換機,則不需要配置管理地址和默認網關地址,可使用三層交換機上的任何一個三層接口的IP地址來遠程登錄。
四、VLAN配置命令:
1.創建vlan命令:
a) 全局配置模式下:
Switch(config)#vlan 2
Switch(config)#name v2
Switch(config)#mtu 數值
Switch(config)#end
b) Vlan數據庫下:
Switch#vlan database
Switch#vlan 2 name v2
Switch#vlan 2 mut 數值
Switch#exit
2.刪除vlan命令:
a) 全局配置模式下:
Switch(config)#no vlan 2
Switch(config)#end
b) Vlan數據庫下:
Switch#no vlan 2 name v2
Switch#exit
3.在vlan中添加端口:
Switch#config terminal
Switch(config)#interface f0/1(端口)
Switch(config-if)#switchport access vlan 2
Switch(config-if)#end
一次將多個端口添加到vlan中:
Switch#config terminal
Switch(config)#interface range f0/1 - 5(端口)
Switch(config-if)#switchport access vlan 2
Switch(config-if)#end
注:switch#show vlan biref(查看vlan信息)
4.查看vlan信息
Switch# show vlan
查看端口vlan狀態
Switch#show interfaces f0/1 switchport
5.配置vlan trunk:
a. 配置接口爲trunk命令:
Switch(config)# interface f0/1(端口)
Switch(config-if)#switchport mode trunk
b. 配置接口爲動態協商模式的命令:
Switch(config)# interface f0/1(端口)
Switch(config-if)#switchport mode dynamic desirable/auto
c. 從trunk中刪除vlan:
Switch(config)# interface f0/1(端口)
Switch(config-if)#Switchport trunk allowed vlan remove 2
6.在trunk中添加vlan:
Switch(config)# interface f0/1(端口)
Switch(config-if)#Switchport trunk allowed vlan add 2
7.SVI配置(交換機虛擬接口,三層幾交換機Vlan的網關)
Switch(config)#interface vlan 2
Switch(config-if)#ip add 192.168.1.254 255.255.255.0
Switch(config-if)#exitshow running config 顯示所有的配置
show history 查看歷史記錄
8.爲輔助端口配置密碼
R(config)# line aux 0
R(config-line)# password yourpasswd
R(config-line)# login #應用密碼
作用:
1. 把輔助端口作爲後備的控制檯端口(可遠程登錄)
2. 把輔助端口當作異步串行接口使用
3. 爲輔助端口設置獨立的密碼
詳見:http://www.jb51.net/network/223238.html
9.router telnet
在R1ping通R2的前提下,首先在R2 配置enable密碼和vty密碼
R2(config)#enable password *
R2(config)#line vty 0 4 #最多支持同時5個telnet
R2(config-line)#password *
在R1上telnet R2
R1# telnet 12.1.1.2 #R2ip
Trying 12.1.1.2 …Open
User Access Verification
Password:R2> show users #在r2上查看連接情況
R1同時按 <\Ctrl+Shift+6>,然後放開按x,掛起R1對R2的連接,按兩次回車回到R2
R1 # show sessions #查看本地發起的所有連接
按兩次回車
R2 # exit #斷開連接
其他斷開連接
1.在連接發起方R1
R1 # disconnect
2.在被連接方
R2 # clear lint vty 0
二層交換機把端口變成trunk
switch(config)# interface interface_id //選擇要配置的端口號
switch(config-if)#switchport mode trunk //將端口配置爲trunk模式
三層交換機把端口變成trunk
switch(config)# interface interface_id //選擇要配置的端口號
switch(config-if)#switchport trunk encapsulation dot1q //以dot1q封裝端口
switch(config-if)#switchport mode trunk //將端口配置爲trunk模式