当前位置:文档之家› Cisco交换机简单配置实例

Cisco交换机简单配置实例

命令句法约定:垂直竖线 ( | )分隔可选的,互斥的元素方括号 ([ ])表示可选的元素花括号 ({ })表示必选项.在方括号内的花括号 ( [{ }] )表示可选元素中的必选项.粗体表示要按字母所示原封不动输入的命令和关键词.即粗休表示由用户手工输入的命令.斜体表示要为之提供实际值的参数.Show 指令:# Show run (显示内存配置文件,当你下了一条指令即在内存中,但若没有用write mem 则不会写入Flash,)# Show conf (显示Flash配置文件,每条指令一定是写入到Flash中的,这样突然停机配置文件才不会丢失)# Show session (列出到本地交换机的连接上所有打开的会话以及连接号)# show int vlan n (n 是编号,用来查看vlan n的信息)# show hardware 或 show version (L2 IOS上显示交换机的硬件或模块信息)# show clock (显示日期和时间)# sh mac-address-table {dynamic | static | secure} mac-address {Vlan vlan-id} {interface int1 [int2…int4] {protocol {ip | ipx | assigned}} (显示mac 交换表信息)# sh mac-address-table address 0000.1111.2222 (显示特定的pc在交换机的哪一端口)# sh int status (显示所有端口的状态信息)# sh int f 0/1 switchport (显示指定交换端口的信息)Switch# boot system filesname (从Flash文件系统内指定一个引导系统的os映像)Switch# vlan database 进入VLAN数据库模式Switch(config)# ip domain-lookup 在交换机上启用DNS服务:Switch(config)# ip name-server serveraddress1 [serveraddress2….serveraddress6] 规定DNS服务器的地址:Switch(config)# ip host name address 指定用于名字解析的主机配置项Switch(config)# interface type mod/num type是界面类型,mod是模块,num是端口号Switch(config)# interface range port-range 选择一个范围内的端口Switch(config-if)# description word 给端口指派一个描述性的名字及端口速度Switch(config-if)# speed {10 |100 |1000|auto|nonegotiate} (设置端口的速度)Switch(config-if)# no shutdown (启用端口,shutdown是禁用端口)Switch(config)# ip routing (启动路由功能 )Switch(config-if)# no switchport (为3层操作配置接口:可以将端口配置成2层交换接口或3层路由端口,要把端口配置成3层端口,可使用 no switchport命令禁止2层操作,启动3层操作)Switch(config-if)# no shutdown (启用接口:许多3层接口默认状态是shutdown的.)配置VTP指定VTP域名:Switch# vlan databaseSwitch(vlan)# vtp domain name (各交换机之间要同步vlan数据,则各交换机的vtp domain name要相同)或Switch(config)# vtp domain name配置VTP模式Switch(vlan)# vtp transparent或Switch(config)# vtp mode transparent改变VTP模式Switch(vlan)# vtp mode [ server | client | transparent ]VTP有3种模式运行: Server(服务器), Client(客户机), Transparent(透明).这三种模式决定了VTP如何传送信息,如何保持VLAN数据库同步,以及是否可以为给定的交换机管理VLAN.Server服务器模式: 这是默认模式,此模式可以创建,删除或者修改本地VLAN数据库里的VLAN,在做过改动之后,vlan数据库的变化被送出到vtp域内所有处于server或者client模式的其他交换机上,Server模式也可以接收从域内其他交换机发送来的vlan数据库变化信息.Client客户机模式: 此Client模式的交换机不能创建,修改或者删除本地vlan数据库里的vlan,相反,它们依靠域内的其他交换机来更新自己的新Vlan它会保持数据库同步,但不会保存vlan信息,如果掉电的话,会丢失所有这些信息.Client还会公布自己数据库的信息,把VTP信息转发给其他交换机.Transparent模式: Transparent模式运行起来和Server模式非常相像,Transparent模式也可以创建,删除或者修改本地vlan数据库里的vlan,这与Server模式的区别在于这些变化不会被传播给其他交换机.此外,本地vlan数据库也不接收从其他交换机来的修改信息.VTP Transparent模式的交换机在其他的Server或者Client模式的交换机之间转发或者中继信息.VTP Transparent模式的交换机不要求有VTP域名.创建vlan:创建一个新的Vlan:Switch# vlan database (进入vlan数据库)Switch(vlan)# vlan number (创建一个vlan,number为新建一个vlan的号, 正常范围1~1000和扩展范围1025~4096)Switch(config)# int vlan 2Switch(config-if)#vlan 2Switch(config-vlan)# name vlantest (给number号的vlan取名为vlantest)划分端口:在Cisco交换机上,端口被分配给独立的VLAN,这些端口称为接入端口(access ports),用于连接终端用户或结点设备.在默认情况下,所有的端口都被划入vlan 1,它叫做默认vlan (default vlan ) ,在创建vlan后,您可手工把某个端口分配给一个新建的vlan.使之成为某个vlan的成员.步骤如下:Switch(config)# int type mod/port (type为适配卡类型,mod/port为端口号,在全局下进入某一个vlan模式如# int f 0/1)Switch(config-if)# switchport mode access (设定f 0/1端口的接入类型为接入端口即access ports.)Switch(config-if)# switchport access vlan number (把此端口即接入端口划分到vlan number 中.number为vlan 号)Switch(config-if)# no shutdown删除一个已存在的vlan要删除一个vlan, 先从VLAN中移除所有存在的PORT,也就是将此vlan所属的端口移到其它vlan 中.进入到vlan database à no vlan numberSwitch# vlan databaseSwitch(vlan)# no vlan 2Switch(vlan)# apply (要apply保证修改,abort放弃修改)注意:在删除某一个vlan之前,要确定此vlan没有任何端口,而且此vlan不在trunk中,否则你先要从trunk中把此vlan移除再下no vlan 2的指令.从trunk中移除vlan的指令:Switch(config-if)# switchport trunk allowed vlan remove 2)使用下面的步骤启动交换机之间的Trunking功能:Switch(config)#int f0/2switch(config-if)#switchport (设定端口为交换端口而不路由端口)Switch(config-if)#switchport trunk encapsulation dot1q (设定此端口的封装为dot1q而不是isl & negotiate)Switch(config-if)#switchport mode trunk (设定此交换端口为trunk即中继端口)Switch(config-if)#switchport nonegotiate (禁止发出任何DTP信令)手工从Trunk链路中删除一个vlan,使此vlan不能通过Trunk链路传送流量:Switch(config)#int f0/2Switch(config-if)#switchport trunk allowed vlan remove 2 (不允许vlan 2使用f 0/2 的Trunk链路)手工将一个vlan新增到Trunk链路中:Switch(config-if)#switchport trunk allowed vlan add 2 (新增一个vlan到Trunk链路中.)&Switch(config-if)#switchport trunk allowed vlan add all (所有vlan使用Trunk 链路)端口安全SwitchL3(config-if)#switchport port-security 启用端口安全功能SwitchL3(config-if)#switchport port-security maximum 1 设定接入mac最大值SwitchL3(config-if)#switchport port-security violation protect 指定端口所采取的措施:SwitchL3(config-if)#switchport port-security mac-address 0000.1111.2222 锁定mac 地址Switch之DHCP功能先介绍第一种方式第一步,启用某台win2k server作DHCP第二步:启用DHCP中继代理/*关键一步,若缺少以下两条命令,在VLAN中使用“IP HELPER-ADDRESS DHCP服务器地址”指定DHCP服务器,客户机仍然不能获得IP地址*/Switch>EnableSwitch#Config tSwitch(Config)Service DhcpSwitch(Config)Ip Dhcp Relay Information Option第三步在C3550的每个vlan中都要下一个指令: ip helper x.x.x.x接着介绍第二种方式:配置Vlan1所用的地址池和相应参数:switch(config)#ip dhcp pool test01 设定dhcp pool 名称为test01switch(config-pool)#network 10.31.0.0 255.255.255.0 设定此名称可分配的IP 地址即地址池.switch(config-pool)#dns-server 10.32.0.2 设定DNS Serverswitch(config-pool)default-router 10.31.0.1 设定默认网关,也就是vlan的ip设置dhcp保留不分配的地址switch(config)#ip dhcp excluded-address 10.31.0.1 10.31.0.10WEB浏览器界面a. 启用web界面: Switch(config)# ip http server (no ip http server 命令可以禁用http服务器)b. 设置浏览器的端口号Switch(config)# ip http port numberc. 限制对web界面的访问Switch(config)# ip http access-class access-listd. 选择用户身份验证的方法Switch(config)# ip http authentication {aaa | enable | local | tacacs}e. 查看交换机的主页:http://switch/ 就能访问交换机的主页.这里的switch是交换机的ip地址或主机名.配置用户级口令: (为0至4级telnet登录配置口令)Switch(config)# line vty 0 4Switch(config-line)# loginSwitch(config-line)# password password配置特权级口令:Switch(config)# enable secret paaword日志记录启用或禁用日志记录Switch(config)# [no] logging on把消息日志记录到systlog服务器:a. 标识syslog服务器: Switch(config)# logging 10.132.227.168b. 向syslog的设备发送消息: Switch(config)# logging facility facility-typeMonitor功能Switch(config)# monitor session session {source {interface interface} | {vlan vlan-id} } [, |-|rx|tx|both]Switch(config)# monitor session session {destination {interface interface} [, |- ] | {vlan vlan-id}例: SwitchL3(config)#monitor session 1 source interface fastEthernet 0/1 bothSwitchL3(config)#monitor session 1 destination interface f0/24此两句指令是将f0/1上产生的流量镜像到f0/24 Port.Spanning-tree快速接入设定:SwitchL3(config)# int f0/24SwitchL3(config-if)#spanning-tree portfast此两句指令是将f0/24port设为快速以太网口,设为快速以太网口后计算机只要接入交换机的端口,此端口就会立马被激活使用,而不需要等待一段时间,其优点是接入速度更快,缺点是不能阻止环.这样就会导致当接入此port的hub有两个port被做成环时会造成网络瘫痪!有关端口的几个指令选择一个端口:Switch(config)# interface type mod/num (type是界面类型,mod是模块,num是端口号)选择一个范围内的端口Switch(config)# interface range port-range(交换机允许指定多个端口,各端口之间用逗号隔开,同模块下的range端口可写成0/1-4,1/1,不同模块下的range端口写成0/1,1/1)给端口指派一个描述性的名字及端口速度Switch(config-if)# description wordSwitch(config-if)# speed {10 |100 |1000|auto|nonegotiate} (设置端口的速度)设置端口模式及流控Switch(config-if)# duplex {full | half |auto} (设置端口的单双工模式)Switch(config)-if# flowcontrol {send | receive} {desired |off |on} (启用或禁用端口Switch(config-if)# no shutdown (启用端口,shutdown是禁用端口)Copy Flash的IOS到本机的TFTP首先在本机开启TFTP程序,然后在console模式下输入指令:Switch#copy flash tftp (copy flash下的某檔到tftpSource filename [c3550-i5q3l2-mz.121-20.EA1a/c3550-i5q3l2-mz.121-20.EA1a.bin]? (注意源文档位于EA1a目录下,)Address or name of remote host []? 10.132.227.168 (指定tftp 的IP)Destination filename [c3550-i5q3l2-mz.121-20.EA1a/c3550-i5q3l2-mz.121-20.EA1a.bin]? c3550 (指定目的地文件名)从Flash文件系统内指定一个引导系统的OS映像:Switch(config)# boot system flashnameVLAN访问控制列表基础知识:访问列表分为标准(Standard access-list)和扩展(Extended access-list)两种访问列表.区别:标准访问列表(1-99):a. 只检查源地址而不管数据包所有达到的目的地.b. 只管理数据包而不分数据包是哪种协议扩展访问列表(100-199): a. 检查源地址和目的地址b. 检查数据包具体是哪种协议允许或拒绝.当设置了访问列表后,当packet到达access-list后,若Access-list没有说明数据包是被deny 还是被permit,则数据包会被deny掉.例: router(config)#1.建立标准访问列表:access-list access-list-number {permit | deny} {源地址}2.应用到某一适配卡: {protocol} access-group access-list-number { in | out}这里在写掩码时是子网掩码的反码Ip及子网在access-list中的一些写法:192.168.0.1 255.255.255.255在access-list中写成: 192.168.0.1 0.0.0.0或 host 192.168.0.1Any 在access-list 中写成0.0.0.0 255.255.255.255注意:如果你想删除access-list 1的某一项列表,用no access-list 1 deny host 10.32.0.1指令它会将整个access-list 1删除.。

相关主题