vlan划分和trunk应用

在这里插入图片描述
首先在路由器上配置各个接口地址

[R1]int g0/0/1
[R1-GigabitEthernet0/0/1]ip add 12.1.1.1 24
Apr  6 2021 17:06:55-08:00 R1 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/1 has entered the UP state. 
[R1-GigabitEthernet0/0/1]int g0/0/0
[R1-GigabitEthernet0/0/0]ip add 192.168.2.254 24
Apr  6 2021 17:07:21-08:00 R1 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. 
[R1-GigabitEthernet0/0/0]
[R1-GigabitEthernet0/0/0]dis cu
[V200R003C00]
#
 sysname R1
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load portalpage.zip
#
 drop illegal-mac alarm
#
 set cpu-usage threshold 80 restore 75
#
aaa 
 authentication-scheme default
 authorization-scheme default
 accounting-scheme default
 domain default 
 domain default_admin 
 local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
 local-user admin service-type http
#
firewall zone Local
 priority 15
#
interface GigabitEthernet0/0/0
 ip address 192.168.2.254 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 12.1.1.1 255.255.255.0 
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
user-interface con 0
 authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac
#
return
[R1-GigabitEthernet0/0/0]
[R2-GigabitEthernet0/0/0]ip add 12.1.1.2 24
Apr  6 2021 17:07:51-08:00 R2 %%01IFNET/4/LINK_STATE(l)[0]:The line protocol IP 
on the interface GigabitEthernet0/0/0 has entered the UP state. int g0/0/1
[R2-GigabitEthernet0/0/1]ip add 192.168.10.254 24
[R2-GigabitEthernet0/0/1]
Apr  6 2021 17:08:08-08:00 R2 %%01IFNET/4/LINK_STATE(l)[1]:The line protocol IP 
on the interface GigabitEthernet0/0/1 has entered the UP state. 
[R2-GigabitEthernet0/0/1]
[R2-GigabitEthernet0/0/1]dis cu
[V200R003C00]
#
 sysname R2
#
 snmp-agent local-engineid 800007DB03000000000000
 snmp-agent 
#
 clock timezone China-Standard-Time minus 08:00:00
#
portal local-server load portalpage.zip
#
 drop illegal-mac alarm
#
 set cpu-usage threshold 80 restore 75
#
aaa 
 authentication-scheme default
 authorization-scheme default
 accounting-scheme default
 domain default 
 domain default_admin 
 local-user admin password cipher %$%$K8m.Nt84DZ}e#<0`8bmE3Uw}%$%$
 local-user admin service-type http
#
firewall zone Local
 priority 15
#
interface GigabitEthernet0/0/0
 ip address 12.1.1.2 255.255.255.0 
#
interface GigabitEthernet0/0/1
 ip address 192.168.10.254 255.255.255.0 
#
interface GigabitEthernet0/0/2
#
interface NULL0
#
user-interface con 0
 authentication-mode password
user-interface vty 0 4
user-interface vty 16 20
#
wlan ac
#
return
[R2-GigabitEthernet0/0/1]

在交换机创建vlan10,20,将各个pc划到各自的vlan中,并设置成access口

[sw1]vlan batch 10 20
Info: This operation may take a few seconds. Please wait for a moment...done.
[sw1]port-group 1
[sw1-port-group-1]group-member e0/0/1 e0/0/3
[sw1-port-group-1]port l 
Apr  6 2021 17:14:18-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 7, the c
hange loop count is 0, and the maximum number of records is 4095.a
[sw1-Ethernet0/0/1]port l a
[sw1-Ethernet0/0/3]port l a
[sw1-port-group-1]qu
[sw1]int e0/0/2
[sw1-Ethernet0/0/2]p l a
[sw1-Ethernet0/0/2]p d v 
Apr  6 2021 17:17:28-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 10, the 
change loop count is 0, and the maximum number of records is 4095.20
[sw1-Ethernet0/0/2]
[sw1-port-group-1]dis vl
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:Eth0/0/4(U)     Eth0/0/5(U)     Eth0/0/6(D)     Eth0/0/7(D)     
                Eth0/0/8(D)     Eth0/0/9(D)     Eth0/0/10(D)    Eth0/0/11(D)    
                Eth0/0/12(D)    Eth0/0/13(D)    Eth0/0/14(D)    Eth0/0/15(D)    
                Eth0/0/16(D)    Eth0/0/17(D)    Eth0/0/18(D)    Eth0/0/19(D)    
                Eth0/0/20(D)    Eth0/0/21(D)    Eth0/0/22(D)    GE0/0/1(D)      
                GE0/0/2(D)                                                      

10   common  UT:Eth0/0/1(U)     Eth0/0/3(U)                                     

20   common  UT:Eth0/0/2(U)                                                     


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------

1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020                         
[sw1-port-group-1]
[sw2]vlan 10
[sw2-vlan10]vlan 20
[sw2-vlan20]
Apr  6 2021 17:22:14-08:00 sw2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 7, the c
hange loop count is 0, and the maximum number of records is 4095.
[sw2-vlan20]int e0/0/2
[sw2-Ethernet0/0/2]p l a
[sw2-Ethernet0/0/2]p d v 20
[sw2-Ethernet0/0/2]int e0/0/3
[sw2-Ethernet0/0/3]p l a
[sw2-Ethernet0/0/3]p 
Apr  6 2021 17:22:44-08:00 sw2 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 9, the c
hange loop count is 0, and the maximum number of records is 4095.
Error: The interface is already a L2 interface.
[sw2-Ethernet0/0/3]
[sw2-Ethernet0/0/3]
[sw2-Ethernet0/0/3]p d v 10
[sw2-Ethernet0/0/3]dis vl
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:Eth0/0/1(U)     Eth0/0/4(D)     Eth0/0/5(D)     Eth0/0/6(D)     
                Eth0/0/7(D)     Eth0/0/8(D)     Eth0/0/9(D)     Eth0/0/10(D)    
                Eth0/0/11(D)    Eth0/0/12(D)    Eth0/0/13(D)    Eth0/0/14(D)    
                Eth0/0/15(D)    Eth0/0/16(D)    Eth0/0/17(D)    Eth0/0/18(D)    
                Eth0/0/19(D)    Eth0/0/20(D)    Eth0/0/21(D)    Eth0/0/22(D)    
                GE0/0/1(D)      GE0/0/2(D)                                      

10   common  UT:Eth0/0/3(U)                                                     

20   common  UT:Eth0/0/2(U)                                                     


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------

1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020       

将两个交换机连接的接口设为trunk口

[sw1]int e0/0/5
[sw1-Ethernet0/0/5]p l t
[sw1-Ethernet0/0/5]
Apr  6 2021 17:26:28-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 14, the 
change loop count is 0, and the maximum number of records is 4095.
[sw1-Ethernet0/0/5]po t a v a
[sw1-Ethernet0/0/5]
[sw1-Ethernet0/0/5]dis vl
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:Eth0/0/4(U)     Eth0/0/5(U)     Eth0/0/6(D)     Eth0/0/7(D)     
                Eth0/0/8(D)     Eth0/0/9(D)     Eth0/0/10(D)    Eth0/0/11(D)    
                Eth0/0/12(D)    Eth0/0/13(D)    Eth0/0/14(D)    Eth0/0/15(D)    
                Eth0/0/16(D)    Eth0/0/17(D)    Eth0/0/18(D)    Eth0/0/19(D)    
                Eth0/0/20(D)    Eth0/0/21(D)    Eth0/0/22(D)    GE0/0/1(D)      
                GE0/0/2(D)                                                      

10   common  UT:Eth0/0/1(U)     Eth0/0/3(U)                                     

             TG:Eth0/0/5(U)                                                     

20   common  UT:Eth0/0/2(U)                                                     

             TG:Eth0/0/5(U)                                                     


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------

1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020                         
[sw1-Ethernet0/0/5]
[sw2]int e0/0/1
[sw2-Ethernet0/0/1]p l t
[sw2-Ethernet0/0/1]p t a v a
[sw2-Ethernet0/0/1]
[sw2-Ethernet0/0/1]dis vl
The total number of vlans is : 3
--------------------------------------------------------------------------------
U: Up;         D: Down;         TG: Tagged;         UT: Untagged;
MP: Vlan-mapping;               ST: Vlan-stacking;
#: ProtocolTransparent-vlan;    *: Management-vlan;
--------------------------------------------------------------------------------

VID  Type    Ports                                                          
--------------------------------------------------------------------------------
1    common  UT:Eth0/0/1(U)     Eth0/0/4(D)     Eth0/0/5(D)     Eth0/0/6(D)     
                Eth0/0/7(D)     Eth0/0/8(D)     Eth0/0/9(D)     Eth0/0/10(D)    
                Eth0/0/11(D)    Eth0/0/12(D)    Eth0/0/13(D)    Eth0/0/14(D)    
                Eth0/0/15(D)    Eth0/0/16(D)    Eth0/0/17(D)    Eth0/0/18(D)    
                Eth0/0/19(D)    Eth0/0/20(D)    Eth0/0/21(D)    Eth0/0/22(D)    
                GE0/0/1(D)      GE0/0/2(D)                                      

10   common  UT:Eth0/0/3(U)                                                     

             TG:Eth0/0/1(U)                                                     

20   common  UT:Eth0/0/2(U)                                                     

             TG:Eth0/0/1(U)                                                     


VID  Status  Property      MAC-LRN Statistics Description      
--------------------------------------------------------------------------------

1    enable  default       enable  disable    VLAN 0001                         
10   enable  default       enable  disable    VLAN 0010                         
20   enable  default       enable  disable    VLAN 0020                         
[sw2-Ethernet0/0/1]

pc1 pc3 能与pc5通信
在这里插入图片描述
在这里插入图片描述
pc2能与pc4通信
在这里插入图片描述
要使pc4与pc6通信,需要在路由器上配置静态路由

[R1]ip route-static 192.168.10.0 24 12.1.1.2
<R1>dis ip routing-table 
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 11       Routes : 11       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       12.1.1.0/24  Direct  0    0           D   12.1.1.1        GigabitEthernet
0/0/1
       12.1.1.1/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
     12.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
    192.168.2.0/24  Direct  0    0           D   192.168.2.254   GigabitEthernet
0/0/0
  192.168.2.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
  192.168.2.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
   192.168.10.0/24  Static  60   0          RD   12.1.1.2        GigabitEthernet
0/0/1
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

<R1>
[R2]ip route-static 192.168.2.0 24 12.1.1.1
[R2]dis ip ro
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 11       Routes : 11       

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       12.1.1.0/24  Direct  0    0           D   12.1.1.2        GigabitEthernet
0/0/0
       12.1.1.2/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
     12.1.1.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/0
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
127.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0
    192.168.2.0/24  Static  60   0          RD   12.1.1.1        GigabitEthernet
0/0/0
   192.168.10.0/24  Direct  0    0           D   192.168.10.254  GigabitEthernet
0/0/1
 192.168.10.254/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
 192.168.10.255/32  Direct  0    0           D   127.0.0.1       GigabitEthernet
0/0/1
255.255.255.255/32  Direct  0    0           D   127.0.0.1       InLoopBack0

[R2]

并且在交换机与路由器相连的口配置access,并将vlan20划分进去

[sw1-Ethernet0/0/5]int e0/0/4
[sw1-Ethernet0/0/4]p l a
[sw1-Ethernet0/0/4]p 
Apr  6 2021 17:34:43-08:00 sw1 %%01PHY/1/PHY(l)[12]:    Ethernet0/0/2: change st
atus to downd 
Apr  6 2021 17:34:44-08:00 sw1 %%01PHY/1/PHY(l)[13]:    Ethernet0/0/2: change st
atus t
Apr  6 2021 17:34:49-08:00 sw1 DS/4/DATASYNC_CFGCHANGE:OID 1.3.6.1.4.1.2011.5.25
.191.3.1 configurations have been changed. The current change number is 16, the 
change loop count is 0, and the maximum number of records is 4095.
[sw1-Ethernet0/0/4]p d v 20
[sw1-Ethernet0/0/4]

此时pc4就可以与pc6通信
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值