1. 程式人生 > >兩層交換機上劃分VLAN藉助三層交換機路由功能實現跨網段互訪

兩層交換機上劃分VLAN藉助三層交換機路由功能實現跨網段互訪

拓撲圖如下:


配置兩層S1-2960交換機:

Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#host S1-2960
S1-2960(config)#vlan 20
S1-2960(config-vlan)#vlan 30
S1-2960(config-vlan)#exit
S1-2960(config)#int fa0/2   !--- 指定埠,一次將一個埠指定至VLAN 20
S1-2960(config-if)#switchport mode access


S1-2960(config-if)#switchport access vlan 20
S1-2960(config-if)#exit
S1-2960(config)#int range fa0/3 - 5    !--- 指定埠組的方式,一次將多個埠指定至同一VLAN 30
S1-2960(config-if-range)#switchport mode access
S1-2960(config-if-range)#switchport access vlan 30
S1-2960(config-if-range)#exit
S1-2960(config)#int fa0/1
S1-2960(config-if)#switchport mode access

S1-2960(config-if)#switchport mode trunk
S1-2960(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
S1-2960(config-if)#end
S1-2960#
%SYS-5-CONFIG_I: Configured from console by console
S1-2960#show vlan

VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                Fa0/10, Fa0/11, Fa0/12, Fa0/13
                                                Fa0/14, Fa0/15, Fa0/16, Fa0/17
                                                Fa0/18, Fa0/19, Fa0/20, Fa0/21
                                                Fa0/22, Fa0/23, Fa0/24, Gig1/1
                                                Gig1/2
20   VLAN0020                         active    Fa0/2
30   VLAN0030                         active    Fa0/3, Fa0/4, Fa0/5
1002 fddi-default                     act/unsup 
1003 token-ring-default               act/unsup 
1004 fddinet-default                  act/unsup 
1005 trnet-default                    act/unsup 


VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1    enet  100001     1500  -      -      -        -    -        0      0
20   enet  100020     1500  -      -      -        -    -        0      0
30   enet  100030     1500  -      -      -        -    -        0      0
1002 fddi  101002     1500  -      -      -        -    -        0      0   
1003 tr    101003     1500  -      -      -        -    -        0      0   
1004 fdnet 101004     1500  -      -      -        ieee -        0      0   
1005 trnet 101005     1500  -      -      -        ibm  -        0      0   


Remote SPAN VLANs
------------------------------------------------------------------------------




Primary Secondary Type              Ports
------- --------- ----------------- ------------------------------------------
S1-2960#


配置兩層S2-2960交換機:
Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#host S2-2960
S2-2960(config)#vlan 30
S2-2960(config-vlan)#vlan 50
S2-2960(config-vlan)#exit
S2-2960(config)#int fa0/8   !--- 指定埠,一次將一個埠指定至VLAN 30
S2-2960(config-if)#switchport mode access
S2-2960(config-if)#switchport access vlan 30
S2-2960(config-if)#exit
S2-2960(config)#int range fa0/1 - 7    !--- 指定埠組的方式,一次將多個埠指定至同一VLAN 50
S2-2960(config-if-range)#switchport mode access
S2-2960(config-if-range)#switchport access vlan 50
S2-2960(config-if-range)#exit
S2-2960(config)#int fa0/3
S2-2960(config-if)#switchport mode access
S2-2960(config-if)#switchport mode trunk
S2-2960(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to up
S2-2960(config-if)#end
S2-2960#
%SYS-5-CONFIG_I: Configured from console by console
S2-2960#show vlan
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/9, Fa0/10, Fa0/11, Fa0/12
                                                Fa0/13, Fa0/14, Fa0/15, Fa0/16
                                                Fa0/17, Fa0/18, Fa0/19, Fa0/20
                                                Fa0/21, Fa0/22, Fa0/23, Fa0/24
                                                Gig1/1, Gig1/2
30   VLAN0030                         active    Fa0/8
50   VLAN0050                         active    Fa0/1, Fa0/2, Fa0/4, Fa0/5
                                                Fa0/6, Fa0/7
1002 fddi-default                     act/unsup 
1003 token-ring-default               act/unsup 
1004 fddinet-default                  act/unsup 
1005 trnet-default                    act/unsup 


VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1    enet  100001     1500  -      -      -        -    -        0      0
30   enet  100030     1500  -      -      -        -    -        0      0
50   enet  100050     1500  -      -      -        -    -        0      0
1002 fddi  101002     1500  -      -      -        -    -        0      0   
1003 tr    101003     1500  -      -      -        -    -        0      0   
1004 fdnet 101004     1500  -      -      -        ieee -        0      0   
1005 trnet 101005     1500  -      -      -        ibm  -        0      0   


Remote SPAN VLANs
------------------------------------------------------------------------------

Primary Secondary Type              Ports
------- --------- ----------------- ------------------------------------------
S2-2960#


配置三層S1-3560交換機:
Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#host S1-3560
S1-3560(config)#vlan 20
S1-3560(config-vlan)#vlan 30
S1-3560(config-vlan)#vlan 50
S1-3560(config-vlan)#exit
S1-3560(config)#int vlan 20
S1-3560(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
S1-3560(config-if)#ip add 192.168.2.1 255.255.255.0
S1-3560(config-if)#no shut
S1-3560(config-if)#exit
S1-3560(config)#int vlan 30
S1-3560(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to up
S1-3560(config-if)#ip add 192.168.3.1 255.255.255.0
S1-3560(config-if)#no shut
S1-3560(config-if)#exit
S1-3560(config)#int vlan 50
S1-3560(config-if)#
%LINK-5-CHANGED: Interface Vlan50, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan50, changed state to up
S1-3560(config-if)#ip add 192.168.5.1 255.255.255.0
S1-3560(config-if)#no shut
S1-3560(config-if)#exit
S1-3560(config)#int fa0/2
S1-3560(config-if)#switchport mode access
S1-3560(config-if)#switchport access vlan 20
S1-3560(config-if)#exit
S1-3560(config)#int fa0/1
S1-3560(config-if)#switchport mode access
S1-3560(config-if)#switchport mode trunk
S1-3560(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/1, changed state to up
S1-3560(config-if)#exit
S1-3560(config)#int fa0/3
S1-3560(config-if)#switchport mode access
S1-3560(config-if)#switchport mode trunk
S1-3560(config-if)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to up
S1-3560(config-if)#ip routing     !--- 啟動三層交換機路由功能
S1-3560(config)#end
S1-3560#
%SYS-5-CONFIG_I: Configured from console by console
S1-3560#show vlan
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/4, Fa0/5, Fa0/6, Fa0/7
                                                Fa0/8, Fa0/9, Fa0/10, Fa0/11
                                                Fa0/12, Fa0/13, Fa0/14, Fa0/15
                                                Fa0/16, Fa0/17, Fa0/18, Fa0/19
                                                Fa0/20, Fa0/21, Fa0/22, Fa0/23
                                                Fa0/24, Gig0/1, Gig0/2
20   VLAN0020                         active    Fa0/2
30   VLAN0030                         active    
50   VLAN0050                         active    
1002 fddi-default                     act/unsup 
1003 token-ring-default               act/unsup 
1004 fddinet-default                  act/unsup 
1005 trnet-default                    act/unsup 


VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1    enet  100001     1500  -      -      -        -    -        0      0
20   enet  100020     1500  -      -      -        -    -        0      0
30   enet  100030     1500  -      -      -        -    -        0      0
50   enet  100050     1500  -      -      -        -    -        0      0
1002 fddi  101002     1500  -      -      -        -    -        0      0   
1003 tr    101003     1500  -      -      -        -    -        0      0   
1004 fdnet 101004     1500  -      -      -        ieee -        0      0   
1005 trnet 101005     1500  -      -      -        ibm  -        0      0   


Remote SPAN VLANs
------------------------------------------------------------------------------

Primary Secondary Type              Ports
------- --------- ----------------- ------------------------------------------
S1-3560#



測試三層交換機路由功能跨網段互訪:
PC>ipconfig
FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::260:47FF:FE2B:2A39
IP Address......................: 192.168.5.57
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.5.1
PC>
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=14ms TTL=127
Reply from 192.168.2.20: bytes=32 time=0ms TTL=127
Reply from 192.168.2.20: bytes=32 time=0ms 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 = 0ms, Maximum = 14ms, Average = 4ms
PC>ping 192.168.3.30
Pinging 192.168.3.30 with 32 bytes of data:
Request timed out.
Reply from 192.168.3.30: bytes=32 time=0ms TTL=127
Reply from 192.168.3.30: bytes=32 time=0ms TTL=127
Reply from 192.168.3.30: bytes=32 time=1ms TTL=127
Ping statistics for 192.168.3.30:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms
PC>


PC>ipconfig
FastEthernet0 Connection:(default port)
Link-local IPv6 Address.........: FE80::260:5CFF:FE82:D58
IP Address......................: 192.168.3.32
Subnet Mask.....................: 255.255.255.0
Default Gateway.................: 192.168.3.1
PC>ping 192.168.2.20
Pinging 192.168.2.20 with 32 bytes of data:
Reply from 192.168.2.20: bytes=32 time=71ms TTL=127
Reply from 192.168.2.20: bytes=32 time=1ms TTL=127
Reply from 192.168.2.20: bytes=32 time=1ms TTL=127
Reply from 192.168.2.20: bytes=32 time=0ms TTL=127
Ping statistics for 192.168.2.20:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 71ms, Average = 18ms
PC>ping 192.168.2.21
Pinging 192.168.2.21 with 32 bytes of data:
Request timed out.
Reply from 192.168.2.21: bytes=32 time=1ms TTL=127
Reply from 192.168.2.21: bytes=32 time=0ms TTL=127
Reply from 192.168.2.21: bytes=32 time=1ms TTL=127
Ping statistics for 192.168.2.21:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms
PC>ping 192.168.3.38
Pinging 192.168.3.38 with 32 bytes of data:
Reply from 192.168.3.38: bytes=32 time=10ms TTL=128
Reply from 192.168.3.38: bytes=32 time=0ms TTL=128
Reply from 192.168.3.38: bytes=32 time=0ms TTL=128
Reply from 192.168.3.38: bytes=32 time=1ms TTL=128
Ping statistics for 192.168.3.38:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 10ms, Average = 2ms
PC>ping 192.168.5.51
Pinging 192.168.5.51 with 32 bytes of data:
Request timed out.
Reply from 192.168.5.51: bytes=32 time=1ms TTL=127
Reply from 192.168.5.51: bytes=32 time=37ms TTL=127
Reply from 192.168.5.51: bytes=32 time=1ms TTL=127
Ping statistics for 192.168.5.51:
    Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
Approximate round trip times in milli-seconds:
    Minimum = 1ms, Maximum = 37ms, Average = 13ms
PC>
測試結果表明所有網段之間可以正確的互相訪問。