思科三层交换机配置
为解决vlan间的路由问题,我们引进三层交换概念,它被大家称为二层交换+三层转发。三层交换机相当于多个专门处理vlan间路由的多个单臂路由和交换的集成。
三层交换机的转发原理
三层交换机通过硬件来交换和路由选择数据包。为处理数据包的高层信息,三层交换有两种体系结构:
1>传统的MLS(Multilayer Switching)
依靠ASIC(Application-Specific Integrated Circuit)对数据流的.第一个数据包进行路由处理后,第三层引擎对硬件交换组件进行程序处理为后续数据包提供路由。产生MLS条目记录,一次路由多次交换。
2>基于CEF(Cisco Express Forwarding)的MLS
CEF是基于拓扑的转发模型,它预先将所有路由信息加入到转发信息库(FIB),方便快速路由。基本概念有:
转发信息库(FIB):类似路由表,记录IP与vlan的对应关系
邻接关系表:类似mac地址表,记录相邻接口所连接主机的mac地址
虚接口:不依赖物理接口的子接口,开启vlan配置网关,属于该vlan的物理接口即可动态充当vlan的网关
三层交换机配置
三层交换机的接口默认是二层接口,命令switchport 转换为三层接口,相反no switchport将路由接口转为交换接口。以下面模拟图配置为例。
配置步骤:
1>在二层交换机上创建vlan,并分配端口,f0/0端口配置trunk(命令略)
2>在三层交换机上创建vlan,并配置trunk指定接口封装方式
SW_3L(config)# int f0/0
SW_3L(config-if)# switchport trunk encapsulation dot1q
SW_3L(config-if)# switchport mode trunk
3>在三层交换机上配置各vlan的ip地址
SW_3L(config)# int vlan 10
SW_3L(config-if)# ip add 192.168.1.1 255.255.255.0
SW_3L(config-if)# no sh
vlan20和vlan30略
4>三层交换机启用路由,配置接口ip
SW_3L(config)# ip routing
SW_3L(config)# int f1/0
SW_3L(config-if)# no switchport
SW_3L(config-if)# ip add 10.1.1.1 255.255.255.248
SW_3L(config-if)# no sh
5>为三层交换机配置默认路由
SW_3L(config)# ip route 0.0.0.0 0.0.0.0 10.1.1.2
经过上面配置,在对客户机设置ip和网关,不同vlan间已经可以正常通信。三层交换机上也可以配置DHCP中继转发,方便客户机地址配置,效果是使不同vlan共用一个dhcp服务器,dhcp的广播信息可以在不同vlan间转发。配置过程如下:
首先选择一个vlan配置dhcp服务作为dhcp server。第三讲配置过这里略。
其次为除了dhcp server 所在vlan之外的每个vlan上配置dhcp中继转发。例如dhcp server在vlan2 现在配置vlan3:
SW_3L(config)# int vlan3
SW_3L(config-if)# ip add 192.168.2.1 255.255.255.0 设置vlan3网关地址
SW_3L(config-if)# ip helper-address 192.168.2.100 vlan2中dhcp server主机地址
需要说明的是,像在单臂路由上配置dhcp服务一样,我们需要配置多个地址池,地址池应包含相应vlan的网关地址。
思科二层与三层交换机
三层交换机是不是经常让你机器不好使,看看下面的三层交换机配置文章,一切问题都能解决。本文详细介绍实例讲解:全面的三层交换机配置比较全面的三层交换机配置实例,带命令解释哟!
三层交换机配置:
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 //三层交换机名字Catalyst 3550-12T1对应的IP地址是172.16.8.1
Service dhcp //提供DHCP服务
ip routing //启用三层交换机上的路由模块
Exit
三层交换机配置:
Vtp mode server //定义VTP工作模式为sever模式
Vtp domain centervtp //定义VTP域的名称为centervtp
Vlan 2 name vlan2 //定义vlan并给vlan取名(如果不取名的话,vlan2的名字应该是vlan002)
Vlan 3 name vlan3
Vlan 4 name vlan4
Vlan 5 name vlan5
Vlan 6 name vlan6
Vlan 7 name vlan7
Vlan 8 name vlan8
Vlan 9 name vlan9
Exit
三层交换机配置:
interface Port-channel 1 //进入虚拟的以太通道组1
switchport trunk encapsulation dot1q //给这个接口的trunk封装为802.1Q的帧格式
switchport mode trunk //定义这个接口的工作模式为trunk
switchport trunk allowed vlan all //在这个trunk上允许所有的vlan通过
Interface gigabitethernet 0/1 //进入模块0上的吉比特以太口1
switchport trunk encapsulation dotlq //给这个接口的trunk封装为802.1Q的帧格式
switchport mode trunk //定义这个接口的工作模式为trunk
switchport trunk allowed vlan all //在这个trunk上允许所有的vlan通过
channel-group 1 mode on //把这个接口放到快速以太通道组1中
Interface gigabitethernet 0/2 //同上
switchport trunk encapsulation dotlq
switchport mode trunk
switchport trunk allowed vlan all
channel-group 1 mode on
三层交换机配置:
port-channel load-balance src-dst-ip //定义快速以太通道组的负载均衡方式(依*源和目的IP的方式)
interface gigabitethernet 0/3 //进入模块0上的吉比特以太口3
switchport trunk encapsulation dotlq //给trunk封装为802.1Q
switchport mode trunk //定义这个接口的工作模式为trunk
switchport trunk allowed vlan all //允许所有vlan信息通过
interface gigabitethernet 0/4 //同上
switchport trunk encapsulation dotlq
switchport mode trunk
switchport trunk allowed vlan all
interface gigbitethernet 0/5 //同上
switchport trunk encapsulation dotlq
switchport mode trunk
switchport trunk allowed vlan all
interface gigbitethernet 0/6 //同上
switchport trunk encapsulation dotlq
switchport mode trunk
switchprot trunk allowed vlan all
三层交换机配置:
interface gigbitethernet 0/7 //进入模块0上的吉比特以太口7
Switchport mode access //定义这个接口的工作模式为访问模式
switchport access vlan 9 //定义这个接口可以访问哪个vlan(实际就是分配这个接口到vlan)
no shutdown
spanning-tree vlan 6-9 cost 1000 //在生成树中,vlan6-9的开销定义为10000
interface range gigabitethernet 0/8 – 10 //进入模块0上的吉比特以太口8,9,10
switchport mode access //定义这些接口的’工作模式为访问模式
switchport access vlan 8 //把这些接口都分配到vlan8中
no shutdown
三层交换机配置:
spanning-tree portfast //在这些接口上使用portfast(使用portfast以后,在生成树的时候不参加运算,直接成为转发状态)
interface gigabitethernet 0/11 //进入模块0上的吉比特以太口11
switchport trunk encapsulation dotlq //给这个接口封装为802.1Q
switchport mode trunk //定义这个接口的工作模式为trunk
switchport trunk allowed vlan all //允许所有vlan信息通过
interface gigabitethernet 0/12 //同上
switchport trunk encapsulation dotlq
switchport mode trunk
switchport trunk allowed vlan all
interface vlan 1 //进入vlan1的逻辑接口(不是物理接口,用来给vlan做路由用)
ip address 172.16.1.7 255.255.255.0 //配置IP地址和子网掩码
no shutdown
三层交换机配置:
standby 1 ip 172.16.1.9 //开启了冗余热备份(HSRP),冗余热备份组1,虚拟路由器的IP地址为172.16.1.9
standby 1 priority 110 preempt //定义这个三层交换机在冗余热备份组1中的优先级为110,preempt是用来开启抢占模式
interface vlan 2 //同上
ip address 172.16.2.252 255.255.255.0
no shutdown
standby 2 ip 172.16.2.254
standby 2 priority 110 preempt
ip access-group 101 in //在入方向上使用扩展的访问控制列表101
interface vlan 3 //同上
ip address 172.16.3.252 255.255.255.0
no shutdown
三层交换机配置:
standby 3 ip 172.16.3.254
standby 3 priority 110 preempt
ip access-group 101 in
interface vlan 4 //同上
ip address 172.16.4.252 255.255.255.0
no shutdown
standby 4 ip 172.16.4.254
standby 4 priority 110 preempt
ip access-group 101 in
interface vlan 5
ip address 172.16.5.252 255.255.255.0
no shutdown
standby 5 ip 172.16.5.254
standby 5 priority 110 preempt
ip access-group 101 in
interface vlan 6
ip address 172.16.6.252 255.255.255.0
no shutdown
三层交换机配置:
standby 6 ip 172.16.6.254
standby 6 priority 100 preempt
interface vlan 7
ip address 172.16.7.252 255.255.255.0
no shutdown
standby 7 ip 172.16.7.254
standby 7 priority 100 preempt

interface vlan 8
ip address 172.16.8.252 255.255.255.0
no shutdown
standby 8 ip 172.16.8.254
standby 8 priority 100 preempt
interface vlan 9
ip address 172.16.9.252 255.255.255.0
no shutdown
三层交换机配置:
standby 9 ip 172.16.9.254
standby 9 priority 100 preempt
access-list 101 deny ip any 172.16.7.0 0.0.0.255 //扩展的访问控制列表101
access-list 101 permit ip any any
Interface vlan 1 //进入vlan1这个逻辑接口
Ip helper-address 172.16.8.1 //可以转发广播(helper-address的作用就是把广播转化为单播,然后发向172.16.8.1)
Interface vlan 2
Ip helper-address 172.16.8.1
Interface vlan 3
ip helper-address 172.16.8.1
interface vlan 4
ip helper-address 172.16.8.1
interface vlan 5
ip helper-address 172.16.8.1
interface vlan 6
ip helper-address 172.16.8.1
interface vlan 7
ip helper-address 172.16.8.1
interface vlan 9
ip helper-address 172.16.8.1
router rip//启用路由协议RIP
version 2//使用的是RIPv2,如果没有这句,则是使用RIPv1
network 172.16.0.0//宣告直连的网段
exit
三层交换机配置:
ip route 0.0.0.0 0.0.0.0 172.16.9.250//缺省路由,所有在路由表中没有办法匹配的数据包,都发向下一跳地址为172.16.9.250这个路由器
line con 0
line aux 0
line vty 0 15//telnet线路(路由器只有5个,是0-4)
password 12345678//login密码
login
end
copy running-config startup-config 保存配置
思科三层交换机路由功能配置实例
―人不会老去,直到悔恨取代了梦想!
正文:
enable 进入特权模式
在此模式下可以进入
config terminal和 vlan database
一、进入虚拟局域网配置模式
vlan 10 name vlan10 设置vlan 10 名称为vlan10
一、config terminal 进入全局配置模式
1、设置交换机名字
hostname xxxx
2、设置交换机的特权密码
enable password xxxx
3、设置交换机的配置线密码
line console 0
password xxxx
login
4、设置交换机的远程登录密码
line vty 0 4
password xxxx
login
5、进入vlan 设置IP
interface vlan 10
ip address 网址 掩码
no shutdown
6、进入端口,连接vlan10
interface fastethernet 0/1
switchport access vlan 10
no shutdown
也可以进入多个端口,配置vlan
interface range fastethernet 0/1-10
switchport access vlan 10
no shutdown
7、设置交换机的默认网关
ip default-gateway x.x.x.x
8、设置端口模式
switchport mode access 设置普通模式
switchport mode trunk 设置中继模式
9、配置链路聚合
配置一个端口
interface fastethernet0/1
channel-group 1 mode on/desirable
interface port-channel 1
switchport mode trunk
配置多个端口
interface range fastethernet0/1-10
channel-group 1 mode on/desirable
interface port-channel 1
switchport mode trunk
tip:配置端口要一一对应
三层交换机区别于二层交换机的地方
1、进入端口,配置端口ip地址,端口的地址即为连接它的区域的网关
interface fastethernet 0/1
no switchport
ip address x.x.x.x x.x.x.x
2、开启交换机路由器功能
ip routing
3、设置rip协议
route rip(最多15)
network x.x.x.x
network y.y.y.y
即声明此机器上端口的IP地址
4、设置默认路由
ip route 0.0.0.0 0.0.0.0 x.x.x.x
即是回头路由,地址为数据流流经方向的的下一个端口,通常此端口的下一个端口也要设一个回来的,不然ping不通
5、设置静态路由
ip route 目标地址 其掩码 下一跳地址
注:如有不对,敬请指正
希望大家成为心目中的大牛
思科三层交换机路由功能配置实例
普通交换机工作在链路层,即二层交换机,无路由功能,也就是只能同一个网段的机器才能通信。下面是我收集的思科三层交换机路由功能配置实例,希望对你有帮助!
配置23口:
Switch#enable
Switch#configure terminal
Switch(config)#interface fastEthernet 0/23
Switch(config)ip addr 50.1.1.1 255.255.255.0
Switch(config-if)#no switchport
Switch(config-if)#no shutdown
Switch(config-if)#end
类似的配置24口:
Switch#enable
Switch#configure terminal
Switch(config)#interface fastEthernet 0/24
Switch(config)ip addr 60.1.1.1 255.255.255.0
Switch(config-if)#no switchport
Switch(config-if)#no shutdown
Switch(config-if)#end
打开交换机路由转发开关:
Switch#configure terminal
Switch(config)#ip routing
Switch(config)#ip cef (这个默认是打开的)
此时可以查看下23口的状态:
Switch#show interfaces fastEthernet 0/23
此时在交换机上ping两个口的地址成功:
Switch#ping 50.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 50.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms
Switch#ping 60.1.1.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 60.1.1.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/4 ms
Switch#
pc1(win7)增加路由:
到60.1.1.0/24的`数据包通过50.1.1.1转发:
route ADD 60.1.1.0 MASK 255.255.255.0 50.1.1.1 METRIC 3
对应的pc2也增加路由:
route ADD 50.1.1.0 MASK 255.255.255.0 60.1.1.1 METRIC 3
此时50.1.1.2和60.1.1.2即可通信。
如果使用了交换机口的路由功能,那么此口(即这里的23,24口)就没有交换能力了。
如果又要交换机有路由功能,又有交换功能,那么交换功能可以由其它口负担。
以上就是关于思科三层交换机配置全部的内容,如果了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
