广播风暴

用三层交换机隔离VLAN有一个问题,在大型网络中,所有设备都依赖于一个核心交换机,虽然它不再依赖于某一物理端口,但交换机仍有瘫痪的可能性

此时可以部署第二台三层交换机,通过HSRP协议将其路由引擎上的虚端口作为备份路由(HSRP协议备份的是端口不是设备),但有一个更严重的问题出现了,如下图:

上图中出现了两个环路,三层交换机虽然隔离了广播域,但在划分VLAN后主干道都需要配置trunk,而交换机是无法控制广播的。这时候数据帧会在这三台交换机中无限循环(数据帧是没有TTL的,最终的结果就是资源耗尽,整个网络瘫痪)。


生成树协议

STP

STP(Spanning Tree Protocol)可以消除网络中的环路。其基本理论依据是根据网络拓扑构建(生成)无回路的连通图(就是树),从而保证数据传输路径的唯一性,避免出现环路导致报文流量的增加和循环。STP是工作在OSI第二层(Data Link Layer)的协议。

所有管理型交换机在出厂时都自带STP协议

缺点

  1. 拓扑收敛慢,当网络拓扑发生改变的时候,生成树协议需要50-52秒的时间才能完成拓扑收敛。
  2. 不能提供负载均衡,当网络中出现环路时,只是简单的逻辑down掉端口,阻止数据帧的转发。

实验

拓扑图

思路

通过HSRP和浮动路由实现负载均衡,备份和活跃各一半,浮动路由也是

  • 接入层

    1. 配置trunk,
    2. 在core-1上配置vtp服务器,并将core-2和其他二层交换机配置为vtp client
    3. 创建VLAN
    4. 为所有二层端口上配置switchport access
    5. 起三层虚接口(网关)
    6. 将core-1部署为vlan10、20的活跃路由,作为vlan30、40的备份路由。core-2同理
    7. 为每个虚接口配置DHCP中继,将50.1.1.1作为DHCP服务器
  • 路由层

    • 两台三层交换机下面的链路都是二层链路,直接往上走,配置一个默认路由,R2和R3不能同时配置默认路由,否则形成路由环路,最终耗尽TTL。
    • R3配置默认路由,R2将10网段和20网段路由至50.1.1.1(需要为三层交换机开启三层接口),然后配置浮动路由至60.1.1.1,右边的三层交换机同理。

配置过程

配置trunk和vtp

以core-1为例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#ho core-1
core-1(config)#int range f0/1 - 3
core-1(config-if-range)#switchport trunk enca ;修改封装类型
core-1(config-if-range)#switchport trunk encapsulation dot1q
core-1(config-if-range)#sw m t
core-1(config-if-range)#exit
core-1(config)#vtp mode server
Device mode already VTP SERVER.
core-1(config)#vtp domain d1
Changing VTP domain name from NULL to d1
core-1(config)#vlan 10
core-1(config-vlan)#exit
core-1(config)#vlan 20
core-1(config-vlan)#exit
core-1(config)#vlan 30
core-1(config-vlan)#exit
core-1(config)#vlan 40
core-1(config-vlan)#exit
core-1(config)#vlan 50
core-1(config-vlan)#exit
core-1(config)#vlan 60
core-1(config-vlan)#exit
core-1(config)#no vlan 60

二层交换机配置vlan

1
2
3
4
5
6
Switch(config)#int range f0/1 - 2
Switch(config-if-range)#sw m t ;配置trunk
Switch(config-if-range)#exit
Switch(config)#int f0/3
Switch(config-if)#sw ac vl 10 ;配置switchport access
Switch(config-if)#exit

配置三层交换机

以core-1为例,配置虚接口、DHCP中继、HSRP

vlan50不需要配置DHCP中继

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
core-1(config)#ip routing
core-1(config)#int vlan 10
core-1(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up

core-1(config-if)#ip add 10.1.1.252 255.255.255.0
core-1(config-if)#ip helper
core-1(config-if)#ip helper-address 50.1.1.1
core-1(config-if)#standby 10 ip 10.1.1.254 255.255.255.0
^
% Invalid input detected at '^' marker.

core-1(config-if)#standby 10 ip 10.1.1.254
core-1(config-if)#standby 10 priority 200
core-1(config-if)#stand
%HSRP-6-STATECHANGE: Vlan10 Grp 10 state Speak -> Standby

%HSRP-6-STATECHANGE: Vlan10 Grp 10 state Standby -> Active
by
core-1(config-if)#standby 10 preempt
core-1(config-if)#standby 10 track f0/4
core-1(config-if)#no sh
core-1(config-if)#int vlan 20
core-1(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up

core-1(config-if)#ip add 20.1.1.252 255.255.255.0
core-1(config-if)#ip helper-address 50.1.1.1
core-1(config-if)#standby 20 ip 20.1.1.254
core-1(config-if)#standby 20 priority 200
core-1(config-if)#standby 20
%HSRP-6-STATECHANGE: Vlan20 Grp 20 state Speak -> Standby
p
%HSRP-6-STATECHANGE: Vlan20 Grp 20 state Standby -> Active
reempt
core-1(config-if)#standby 20 preempt
core-1(config-if)#standby 20 track f0/4
core-1(config-if)#no sh
core-1(config-if)#exit
core-1(config)#int vlan 30
core-1(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to up

core-1(config-if)#ip add 30.1.1.252 255.255.255.0
core-1(config-if)#ip helper-address 50.1.1.1
core-1(config-if)#standby 30 ip 30.1.1.254
core-1(config-if)#standby 30 priority 195
core-1(config-if)#s
%HSRP-6-STATECHANGE: Vlan30 Grp 30 state Speak -> Standby
tand
%HSRP-6-STATECHANGE: Vlan30 Grp 30 state Standby -> Active
by
core-1(config-if)#standby 30 preempt
core-1(config-if)#standby 30 track f0/4
core-1(config-if)#no sh
core-1(config-if)#exit
core-1(config)#int vlan 40
core-1(config-if)#
%LINK-5-CHANGED: Interface Vlan40, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan40, changed state to up

core-1(config-if)#ip add 40.1.1.252 255.255.255.0
core-1(config-if)#ip helper-address 50.1.1.1
core-1(config-if)#standby 40 ip 40.1.1.254
core-1(config-if)#standby 40 priority 195
core-1(config-if)#standby 40 preempt
core-1(config-if)#standby 40 track f0/4
core-1(config-if)#no sh
core-1(config-if)#exit
core-1(config)#
%HSRP-6-STATECHANGE: Vlan40 Grp 40 state Speak -> Standby

%HSRP-6-STATECHANGE: Vlan40 Grp 40 state Standby -> Active

core-1(config)#int vlan 50
core-1(config-if)#
%LINK-5-CHANGED: Interface Vlan50, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan50, changed state to up

core-1(config-if)#ip add 50.1.1.252 255.255.255.0
core-1(config-if)#standby 50 ip 50.1.1.254
core-1(config-if)#standby 50 priority 200
core-1(config-if)#
%HSRP-6-STATECHANGE: Vlan50 Grp 50 state Speak -> Standby

%HSRP-6-STATECHANGE: Vlan50 Grp 50 state Standby -> Active

core-1(config-if)#standby 50 preempt
core-1(config-if)#standby 50 track f0/4
core-1(config-if)#exit

core2配置

core-2不需要配置路由跟踪,当其f0/4down掉时,已经没有剩余路由器可以切换了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#ho core-2
core-2(config)#ip routing
core-2(config)#int vlan 10
core-2(config-if)#ip add 10.1.1.253 255.255.255.0
core-2(config-if)#ip helper-address 50.1.1.1
core-2(config-if)#standby 10 ip 10.1.1.254
core-2(config-if)#standby 10 priority 195
core-2(config-if)#standby 10 preempt
core-2(config-if)#exit
core-2(config)#int vlan 20
core-2(config-if)#ip add 20.1.1.253 255.255.255.0
core-2(config-if)#ip helper-address 50.1.1.1
core-2(config-if)#standby 20 ip 20.1.1.254
core-2(config-if)#standby 20 priority 195
core-2(config-if)#standby 20 preempt
core-2(config-if)#exit
core-2(config)#int vlan 30
core-2(config-if)#ip add 30.1.1.253 255.255.255.0
core-2(config-if)#ip helper-address 50.1.1.1
core-2(config-if)#standby 30 ip 30.1.1.254
core-2(config-if)#standby 30 priority 200
core-2(config-if)#standby 30 preempt
core-2(config-if)#exit
core-2(config)#int vlan 40
core-2(config-if)#ip add 40.1.1.253 255.255.255.0
core-2(config-if)#ip helper-address 50.1.1.1
core-2(config-if)#standby 40 ip 40.1.1.254
core-2(config-if)#standby 40 priority 200
core-2(config-if)#standby 40 preempt
core-2(config-if)#exit
core-2(config)#int vlan 50
core-2(config-if)#ip add 50.1.1.253 255.255.255.0
core-2(config-if)#standby 50 ip 50.1.1.254
core-2(config-if)#standby 50 priority 195
core-2(config-if)#standby 50 preempt
core-2(config-if)#exit

路由层配置

R1 配置浮动路由

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip add 60.1.1.2 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
exit
Router(config)#int f0/1
Router(config-if)#ip add 70.1.1.2 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/1, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
exit
Router(config)#int f1/0
Router(config-if)#ip add 80.1.1.1 255.255.255.0
Router(config-if)#no sh

Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet1/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet1/0, changed state to up
exit
Router(config)#ip route 90.1.1.0 255.255.255.0 80.1.1.2
Router(config)#ip route 100.1.1.0 255.255.255.0 80.1.1.2
Router(config)#ip route 10.1.1.0 255.255.255.0 60.1.1.1
Router(config)#ip route 10.1.1.0 255.255.255.0 70.1.1.1 2
Router(config)#ip route 20.1.1.0 255.255.255.0 60.1.1.1
Router(config)#ip route 20.1.1.0 255.255.255.0 70.1.1.1 2
Router(config)#ip route 30.1.1.0 255.255.255.0 70.1.1.1
Router(config)#ip route 30.1.1.0 255.255.255.0 60.1.1.1 2
Router(config)#ip route 40.1.1.0 255.255.255.0 70.1.1.1
Router(config)#ip route 40.1.1.0 255.255.255.0 60.1.1.1 2
Router(config)#ip route 50.1.1.0 255.255.255.0 60.1.1.1
Router(config)#ip route 50.1.1.0 255.255.255.0 70.1.1.1 2
Router(config)#exit
Router#
%SYS-5-CONFIG_I: Configured from console by console

core-1直接往上路由

1
core-1(config)#ip route 0.0.0.0 0.0.0.0 60.1.1.2

此时外网接口不管哪一个down掉都不会影响另一个,并实现了负载均衡。内网接口会根据HSRP协议切换至另一个网关。