CCNA之旅-交换机的基本配置-stp、vtp、vlan间通信实验

 如上图:为一小型企业的网络拓扑,公司有两个部门为了安全起见划分了两个vlan来限制两个部门的访问,同时用了三层交换机允许特殊时期两个vlan间的访问。为了管理vlan的方便,又用到了VTP协议,同时用两台三层交换机分别做为两个vlan的vtp服务器,在两个三层交换机之间用到了以太网通道的技术,公司通一一个网关出口用于访问Internet。

现在来看这个小型项目的具体实施:

一、计划好拓扑开始实施布线工程(这时必须的)。

二、配置每台设备,进行调试(这时我们讨论的重点):

       仔细看拓扑,两个三层设备相连,并且都和接入层的低端交换机相连,目的只有一个保证网络线路的冗余,防患于必然。如果交换机之间就这样简单的连连不做任何设置,这样的网络大家都只知道的是无法正常工作的,因为会出现,广播风暴、交换机MAC地址表不稳定,多帧复制等等让人头痛的问题。所以我们要运行STP生成树协议,检查网络的拓扑断掉冗余的线路,并在网络线路出现故障的时候,启用冗余线路。OK,我们来看看具体的配置吧.......

1、三层交换机SW1的配置:

配置vtp

sw1(config)#vtp domain server

sw1#vlan database
% Warning: It is recommended to configure VLAN from config mode,
  as VLAN database mode is being deprecated. Please consult user
  documentation for configuring VTP/VLAN in config mode.

sw1(vlan)#vlan 2

sw1(vlan)#vlan 3

配置vtp服务器的时候我们要注意复习一下vtp的知识:

vtp(vlan trunk protocol)默认时所有交换机都配置为VTP服务器模式,配置时我们可以想一个VTP域名,用来标识这个VTP域,同时可以加一些验证信息配置域内口令,还可以设置操作模式和交换机的修剪功能,在这里我们配置SW1的VTP域名为SERVER,不启用域内口令验证功能了,默认时SW1就工作在服务器的模式下。SW2、SW3、SW4我们直接用一条命令

sw2(config)#vtp mode client  同时把相连的线路接口都设为中继模式,来传送多个VLAN信息,这样每个VTP客户端都会学到VTP服务器SW1上配置的VLAN信息了,所以我们只在SW1也就是VTP服务器上来添加修改VLAN 的数量,来管理整个网络的VLAN信息。客户端学到VLAN后,可以设置不同的接口加入到不同的VLAN里。

看配置SW1:

前面我们已经配置了vtp域,同时配置了两个vlan 2 和3 。接下来我们把端口F0/3 F0/4 F0/13 F0/14 配置为trunk模式

sw1(config)#interface range fastEthernet 0/3 - fastEthernet 0/4  //这个命令是同时配置多个连续的端口

也可以用简写的命令:Interface range f0/3 -4 效果是一样的
sw1(config-if-range)#switchport mode trunk  //让后配置trunk模式

同样的方法配置F0/13 - F0/14

看配置SW2:

sw2(config)#vtp mode client

sw2(config)#interface range f0/3 - 4

sw2(config-if-range)#switchport mode trunk

sw2(config)#interface range f0/13 - 14

sw2(config-if-range)#switchport mode trunk

看配置SW3:

sw3(config)#vtp mode client

sw3(config)#interface range f0/13 -1 4

sw3(config-if-range)#switchport mode trunk

看配置SW4:

sw4(config)#vtp mode client

sw4(config)#interface range f0/13 -1 4

sw4(config-if-range)#switchport mode trunk

现在SW2 SW3 SW4 如果不出问题的话已经学到了VTP服务器通告的VLAN 2 VLAN 3的信息了。

这时候其实每个VLAN都已经运行了生成树协议,只是根桥的选择是严格按照交换机的优先级来选择的,有时候自动选择的根桥并不是最理想的,比如三层交换机是性能最好的,做根桥也是最恰当的,可有时候却不能称为根桥,这时候我们就需要手工指定不同VLAN的根桥了,手工制定根桥可以修改优先级,或者直接指定,我们下面来看看指定SW1为VLAN2的根桥并作为VLAN3的备份根桥,指定SW2为VLAN3的根桥并作为VLAN2的备份根桥,

看SW1的配置:

sw1(config)#spanning-tree vlan 2 root primary   //作为VLAN2的根桥

sw1(config)#spanning-tree vlan 3 root secondary   //作为VLAN3的备份根桥

看SW2的配置:

sw2(config)#spanning-tree vlan 3 root primary   //作为VLAN3的根桥

sw2(config)#spanning-tree vlan 2 root secondary   //作为VLAN2的备份根桥

配置SW1和SW2之间的以太网通道:

Ethernet Channel

  以太通道
 

  以太通道也称为以太端口捆绑、端口聚集或以太链路聚集. 以太通道为交换机提供了端口捆绑的技术,允许两个交换机之间通过两个或多个端口并行连接,同时传输数据,以提供更高的带宽. 通过端口聚集协议(PAgP) 建立以太通道. 端口聚合是目前许多交换机支持的一个高级特性. 配置命令 Switch(config)#in range [需要做通道的接口] Switch(config-range)#channel-group 1 mode on 以太通道的特点:以太网通道最多可以捆绑8条物理链路,可以是双绞线,也可以是光纤。 以太通道的规则:参与捆绑的端口必须属于同一个VLAN,或者都是中继模式 如果端口配置是中继模式,则链路中的两个端口必须都是中继模式 所有参与捆绑的端口的物理参数必须相同,例如全部为半双工或者全部为全双工

我们这里配置SW1和SW2的F0/3-F0/4捆绑成以太网通道

sw1(config)#interface range f0/3 -4
sw1(config-if-range)#switchport mode trunk
Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode.
Command rejected: An interface whose trunk encapsulation is "Auto" can not be configured to "trunk" mode.
sw1(config-if-range)#channel-group ?
  <1-48>  Channel group number
sw1(config-if-range)#channel-group 1 mode ?
  active     Enable LACP unconditionally
  auto       Enable PAgP only if a PAgP device is detected
  desirable  Enable PAgP unconditionally
  on         Enable Etherchannel only
  passive    Enable LACP only if a LACP device is detected
sw1(config-if-range)#channel-group 1 mode on ?
  <cr>
sw1(config-if-range)#channel-group 1 mode on
sw1(config-if-range)#

同样的方法,配置SW2这样他们之间就成功了......

我们现在来看一下这个网络的状态.....

就像最上面的拓扑状态一样........以太网通道为阻塞状态并没有起到快速传输数据的作用......为什么呢?我们到每个交换机上来看看,生成树协议最终生成的网络拓扑......

sw1#show spanning-tree vlan 2
VLAN0002
  Spanning tree enabled protocol ieee
  Root ID    Priority    20482
             Address     00E0.8FAD.1847
             This bridge is the root
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    20482  (priority 20480 sys-id-ext 2)
             Address     00E0.8FAD.1847
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/13           Desg FWD 19        128.13   P2p
Fa0/14           Desg FWD 19        128.14   P2p

SW1上的F0/13 F0/14在VLAN2中都为根端口(因为SW1为VLAN2得根桥吗,是吧?)处于转发状态

sw2#show spanning-tree vlan 2
VLAN0002
  Spanning tree enabled protocol ieee
  Root ID    Priority    20482
             Address     00E0.8FAD.1847
             Cost        19
             Port        14(FastEthernet0/14)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    28674  (priority 28672 sys-id-ext 2)
             Address     0050.0F9C.7DC1
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/13           Altn BLK 19        128.13   P2p
Fa0/14           Root FWD 19        128.14   P2p

sw2#

我们看到,f0/14端口为根端口,处于转发状态.....

sw3#show spanning-tree vlan 2
VLAN0002
  Spanning tree enabled protocol ieee
  Root ID    Priority    20482
             Address     00E0.8FAD.1847
             Cost        19
             Port        13(FastEthernet0/13)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32770  (priority 32768 sys-id-ext 2)
             Address     0000.0C57.88D6
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Desg FWD 19        128.1    P2p
Fa0/14           Desg FWD 19        128.14   P2p
Fa0/13           Root FWD 19        128.13   P2p
我们看到F0/1为指定端口,F0/13为根端口,F0/14为指定端口 都处于转发状态。

sw4#show spanning-tree vlan 2
VLAN0002
  Spanning tree enabled protocol ieee
  Root ID    Priority    20482
             Address     00E0.8FAD.1847
             Cost        19
             Port        14(FastEthernet0/14)
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec

  Bridge ID  Priority    32770  (priority 32768 sys-id-ext 2)
             Address     0090.2B9C.B829
             Hello Time  2 sec  Max Age 20 sec  Forward Delay 15 sec
             Aging Time  20

Interface        Role Sts Cost      Prio.Nbr Type
---------------- ---- --- --------- -------- --------------------------------
Fa0/1            Desg FWD 19        128.1    P2p
Fa0/13           Desg FWD 19        128.13   P2p
Fa0/14           Root FWD 19        128.14   P2p

我们看到SW4上:F0/1端口为指定端口,F0/13端口为指定端口,F0/14端口为根端口,也都处于转发状态

经过以上的验证我们可以的得出,VLAN2经过生成树算法,得到的无环冗余网络拓扑为:

 

CCNA之旅-交换机的基本配置-stp、vtp、vlan间通信实验 

如果上面的拓扑中SW3的F0/14接口断了,那么会出现什么样的情况呢,备份线路又是怎么起到作用呢?

我们把SW3的F0/14接口给SHUTDOWN了,然后观察效果.......

CCNA之旅-交换机的基本配置-stp、vtp、vlan间通信实验

备份链路马上起到了作用,那么VLAN3的链路和上面的也差不多,实验做出来了自己分析分析。。。。。

 

CCNA之旅-交换机的基本配置-stp、vtp、vlan间通信实验 

这是以太网通道起到作用的时刻........

在上面我们看到交换机SW3 的,F0/1接口为指定端口,出于转发状态。在这里出于转发状态是正确的,但是为制定端口就不正确了,意思是他也参与了STP的过程,其实这个接口我们不需要参与STP整个状态的,因为它下面接的是主机。所以我们可以进如此端口设置此端口为快速端口,不参与STP

sw3(config)#int f0/1
sw3(config-if)#spanning-tree portfast

忘了这里还没有在SW3上把F0/1 F0/2 接口分别加入到VLAN2 VLAN3上呢

sw3(config)#int f0/3
sw3(config-if)#switchport access vlan 2
sw3(config-if)#int f0/4

sw3(config-if)#switchport access vlan 3

局域网的VLAN我们部署好了,现在开始部署VLAN间通信:

配置SW2:

w2(config)#int vlan 2
sw2(config-if)#ip add 192.168.1.1 255.255.255.0
sw2(config-if)#no shut
sw2(config-if)#int vlan 3
sw2(config-if)#ip add 192.168.2.1 255.255.255.0
sw2(config-if)#no shut
sw2(config-if)#exit

sw2(config)#ip routing  //开启三层交换功能,同时也开启SW1的三层交换功能

sw1(config)#ip routing

这样,我们VLAN 间就可以通信了

PC>ipconfig

IP Address......................: 192.168.1.10
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.1.1

PC>ping 192.168.2.1

Pinging 192.168.2.1 with 32 bytes of data:

Request timed out.
Reply from 192.168.2.1: bytes=32 time=31ms TTL=255
Reply from 192.168.2.1: bytes=32 time=62ms TTL=255
Reply from 192.168.2.1: bytes=32 time=62ms TTL=255

Ping statistics for 192.168.2.1:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 31ms, Maximum = 62ms, Average = 51ms

PC>ping 192.168.2.20

Pinging 192.168.2.20 with 32 bytes of data:

Request timed out.
Reply from 192.168.2.20: bytes=32 time=111ms TTL=127
Reply from 192.168.2.20: bytes=32 time=93ms TTL=127
Reply from 192.168.2.20: bytes=32 time=125ms TTL=127

Ping statistics for 192.168.2.20:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 93ms, Maximum = 125ms, Average = 109ms

PC>

如果我们不需要VLAN间通信了,怎么办呢?

关闭三层交换机的路由功能,是不是就不能通信了,或者把交换机的VLAN网关一改,哈哈哈神不知鬼不觉,做个网管就是爽,钱虽然不多,但是只要你肯努力,慢慢学,有属于你的一片天,加油我的兄弟姐妹们!

配置公司的外部业务访问

配置SW2:

sw2#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
sw2(config)#int f0/10
sw2(config-if)#no sw
sw2(config-if)#no switchport   //关闭次接口的交换功能
sw2(config-if)#ip add 10.0.0.1 255.0.0.0   //为此接口设置IP地址
sw2(config-if)#no shut
sw2(config-if)#exit
sw2(config)#router rip   //配置路由协议RIPv2
sw2(config-router)#version 2
sw2(config-router)#no auto
sw2(config-router)#no auto-summary
sw2(config-router)#network 10.0.0.0
sw2(config-router)#network 192.168.1.0
sw2(config-router)#network 192.168.2.0
sw2(config-router)#

配置R1:

r1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
r1(config)#int f0/1
r1(config-if)#ip add 10.0.0.2 255.0.0.0
r1(config-if)#no shut
r1(config-if)#int f0/0
r1(config-if)#ip add 20.0.0.1 255.0.0.0
r1(config-if)#no shut
r1(config-if)#exit
r1(config)#router rip
r1(config-router)#version 2
r1(config-router)#no auto
r1(config-router)#no auto-summary
r1(config-router)#network 10.0.0.0
r1(config-router)#network 20.0.0.0
r1(config-router)#end
r1#

我们查看路由表:

sw2#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

C    10.0.0.0/8 is directly connected, FastEthernet0/10
R    20.0.0.0/8 [120/1] via 10.0.0.2, 00:00:25, FastEthernet0/10
C    192.168.1.0/24 is directly connected, Vlan2
C    192.168.2.0/24 is directly connected, Vlan3
sw2#

r1#show ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
       * - candidate default, U - per-user static route, o - ODR
       P - periodic downloaded static route

Gateway of last resort is not set

C    10.0.0.0/8 is directly connected, FastEthernet0/1
C    20.0.0.0/8 is directly connected, FastEthernet0/0
R    192.168.1.0/24 [120/1] via 10.0.0.1, 00:00:23, FastEthernet0/1
R    192.168.2.0/24 [120/1] via 10.0.0.1, 00:00:23, FastEthernet0/1
r1#

然后我们在R1上接一个电脑配置IP地址,模拟出网络上的SERVER.

最后我们就可以实现公司上internet了

PC>ipconfig

IP Address......................: 192.168.2.20
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.2.1

PC>ping 20.0.0.2

Pinging 20.0.0.2 with 32 bytes of data:

Request timed out.
Reply from 20.0.0.2: bytes=32 time=125ms TTL=126
Reply from 20.0.0.2: bytes=32 time=94ms TTL=126
Reply from 20.0.0.2: bytes=32 time=95ms TTL=126

Ping statistics for 20.0.0.2:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 94ms, Maximum = 125ms, Average = 104ms

PC>tracert 20.0.0.2

Tracing route to 20.0.0.2 over a maximum of 30 hops:

  1   47 ms     62 ms     62 ms     192.168.2.1
  2   93 ms     94 ms     78 ms     10.0.0.2
  3   125 ms    125 ms    94 ms     20.0.0.2

Trace complete.