1、比较全面的三层交换机配置实例(带命令解释哟!)Enable /进入私有模式Configure terminal /进入全局模式service password-encryption /对密码进行加密hostname Catalyst 3550-12T1 /给三层交换机定义名称enable password 123456. /enable 密码Enable secret 654321 /enable 的加密密码(应该是乱码而不是 654321 这样)Ip subnet-zero /允许使用全 0 子网(默认都是打开的)Ip name-server 172.16.8.1 172.16.8.2 /三
2、层交换机名字 Catalyst 3550-12T1 对应的 IP 地址是172.16.8.1Service dhcp /提供 DHCP 服务ip routing /启用三层交换机上的路由模块ExitVtp mode server /定义 VTP 工作模式为 sever 模式Vtp domain centervtp /定义 VTP 域的名称为 centervtpVlan 2 name vlan2 /定义 vlan 并给 vlan 取名(如果不取名的话,vlan2 的名字应该是 vlan002)Vlan 3 name vlan3Vlan 4 name vlan4Vlan 5 name vlan5V
3、lan 6 name vlan6Vlan 7 name vlan7Vlan 8 name vlan8Vlan 9 name vlan9Exitinterface Port-channel 1 /进入虚拟的以太通道组 1switchport trunk encapsulation dot1q /给这个接口的 trunk 封装为 802.1Q 的帧格式switchport mode trunk /定义这个接口的工作模式为 trunkswitchport trunk allowed vlan all /在这个 trunk 上允许所有的 vlan 通过Interface gigabitethernet
4、 0/1 /进入模块 0 上的吉比特以太口 1switchport trunk encapsulation dotlq /给这个接口的 trunk 封装为 802.1Q 的帧格式switchport mode trunk /定义这个接口的工作模式为 trunkswitchport trunk allowed vlan all /在这个 trunk 上允许所有的 vlan 通过channel-group 1 mode on /把这个接口放到快速以太通道组 1 中Interface gigabitethernet 0/2 /同上switchport trunk encapsulation dotl
5、qswitchport mode trunkswitchport trunk allowed vlan allchannel-group 1 mode onport-channel load-balance src-dst-ip /定义快速以太通道组的负载均衡方式(依* 源和目的 IP 的方式)interface gigabitethernet 0/3 /进入模块 0 上的吉比特以太口 3switchport trunk encapsulation dotlq /给 trunk 封装为 802.1Qswitchport mode trunk /定义这个接口的工作模式为 trunkswitchp
6、ort trunk allowed vlan all /允许所有 vlan 信息通过interface gigabitethernet 0/4 /同上switchport trunk encapsulation dotlqswitchport mode trunkswitchport trunk allowed vlan allinterface gigbitethernet 0/5 /同上switchport trunk encapsulation dotlqswitchport mode trunkswitchport trunk allowed vlan allinterface gig
7、bitethernet 0/6 /同上switchport trunk encapsulation dotlqswitchport mode trunkswitchprot trunk allowed vlan allinterface gigbitethernet 0/7 /进入模块 0 上的吉比特以太口 7Switchport mode access /定义这个接口的工作模式为访问模式switchport access vlan 9 /定义这个接口可以访问哪个 vlan(实际就是分配这个接口到 vlan)no shutdownspanning-tree vlan 6-9 cost 1000
8、 /在生成树中,vlan6-9 的开销定义为 10000interface range gigabitethernet 0/8 10 /进入模块 0 上的吉比特以太口 8,9,10switchport mode access /定义这些接口的工作模式为访问模式switchport access vlan 8 /把这些接口都分配到 vlan8 中no shutdownspanning-tree portfast /在这些接口上使用 portfast(使用 portfast 以后,在生成树的时候不参加运算,直接成为转发状态)interface gigabitethernet 0/11 /进入模块
9、0 上的吉比特以太口 11switchport trunk encapsulation dotlq /给这个接口封装为 802.1Qswitchport mode trunk /定义这个接口的工作模式为 trunkswitchport trunk allowed vlan all /允许所有 vlan 信息通过interface gigabitethernet 0/12 /同上switchport trunk encapsulation dotlqswitchport mode trunkswitchport trunk allowed vlan allinterface vlan 1 /进入
10、 vlan1 的逻辑接口(不是物理接口,用来给 vlan 做路由用)ip address 172.16.1.7 255.255.255.0 /配置 IP 地址和子网掩码no shutdownstandby 1 ip 172.16.1.9 /开启了冗余热备份(HSRP),冗余热备份组 1,虚拟路由器的 IP 地址为172.16.1.9standby 1 priority 110 preempt /定义这个三层交换机在冗余热备份组 1 中的优先级为110,preempt 是用来开启抢占模式interface vlan 2 /同上ip address 172.16.2.252 255.255.255
11、.0no shutdownstandby 2 ip 172.16.2.254standby 2 priority 110 preemptip access-group 101 in /在入方向上使用扩展的访问控制列表 101interface vlan 3 /同上ip address 172.16.3.252 255.255.255.0no shutdownstandby 3 ip 172.16.3.254standby 3 priority 110 preemptip access-group 101 ininterface vlan 4 /同上ip address 172.16.4.252
12、 255.255.255.0no shutdownstandby 4 ip 172.16.4.254standby 4 priority 110 preemptip access-group 101 ininterface vlan 5ip address 172.16.5.252 255.255.255.0no shutdownstandby 5 ip 172.16.5.254standby 5 priority 110 preemptip access-group 101 ininterface vlan 6ip address 172.16.6.252 255.255.255.0no s
13、hutdownstandby 6 ip 172.16.6.254standby 6 priority 100 preemptinterface vlan 7ip address 172.16.7.252 255.255.255.0no shutdownstandby 7 ip 172.16.7.254standby 7 priority 100 preemptinterface vlan 8ip address 172.16.8.252 255.255.255.0no shutdownstandby 8 ip 172.16.8.254standby 8 priority 100 preempt
14、interface vlan 9ip address 172.16.9.252 255.255.255.0no shutdownstandby 9 ip 172.16.9.254standby 9 priority 100 preemptaccess-list 101 deny ip any 172.16.7.0 0.0.0.255 /扩展的访问控制列表 101access-list 101 permit ip any anyInterface vlan 1 /进入 vlan1 这个逻辑接口Ip helper-address 172.16.8.1 /可以转发广播(helperaddress 的
15、作用就是把广播转化为单播,然后发向 172.16.8.1)Interface vlan 2Ip helper-address 172.16.8.1Interface vlan 3ip helper-address 172.16.8.1interface vlan 4ip helper-address 172.16.8.1interface vlan 5ip helper-address 172.16.8.1interface vlan 6ip helper-address 172.16.8.1interface vlan 7ip helper-address 172.16.8.1interfa
16、ce vlan 9ip helper-address 172.16.8.1router rip /启用路由协议 RIPversion 2 /使用的是 RIPv2,如果没有这句,则是使用 RIPv1network 172.16.0.0 /宣告直连的网段exitip route 0.0.0.0 0.0.0.0 172.16.9.250 /缺省路由,所有在路由表中没有办法匹配的数据包,都发向下一跳地址为 172.16.9.250 这个路由器line con 0line aux 0line vty 0 15 /telnet 线路(路由器只有 5 个,是 0-4)password 12345678 /login 密码loginendcopy running-config startup-config 保存配置