交换机的基本命令

来源:互联网 发布:xt800远程控制软件 编辑:程序博客网 时间:2024/06/05 07:29

一、模式命令
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)#exit

show 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模式

0 0
原创粉丝点击