实验目的:学习和分析单臂路由
 
实验原理: 大家都知道vlan 之间是不能互相通讯的,我们可以通过路由器来让两个不同的vlan 之间通讯,叫单臂路由,如果是三层交换机也可以用三层交换来实现。
 
实验拓扑
 
File?id=dfnfszds_10gh7kswc5_b


实验步骤:
 
1.为各个PC配置IP 以及网关:
PC0:192.168.1.2/24 GW:192.168.1.1
PC1:192.168.2.2/24 GW:192.168.2.1
PC2:192.168.1.3/24 GW:192.168.1.1
PC3:192.168.2.3/24 GW:192.168.2.1 
 
 
2. 交换机上的配置
 
SW0上的配置:
新建VLAN2和VLAN3
把端口Fa0/2, Fa0/3的访问模式设置为静态访问模式(switchport mode acc)
把端口Fa0/2加入VLAN2 ;  Fa0/3加入VLAN3
把端口Fa0/1设置为Trunk模式 , Fa0/4也必须设置为Trunk模式
Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#vlan 3
Switch(config-vlan)#name v3
Switch(config-vlan)#exit
Switch(config)#vlan 2
Switch(config-vlan)#name v2
Switch(config-vlan)#^Z
%SYS-5-CONFIG_I: Configured from console by console
Switch#show vlan
VLAN Name                             Status    Ports
---- -------------------------------- --------- -------------------------------
1    default                          active    Fa0/1, Fa0/2, Fa0/3, 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
                                                Gig1/1, Gig1/2
2    v2                               active   
3    v3                               active   
1002 fddi-default                     active   
1003 token-ring-default               active   
1004 fddinet-default                  active   
1005 trnet-default                    active   
VLAN Type  SAID       MTU   Parent RingNo BridgeNo Stp  BrdgMode Trans1 Trans2
---- ----- ---------- ----- ------ ------ -------- ---- -------- ------ ------
1    enet  100001     1500  -      -      -        -    -        0      0
2    enet  100002     1500  -      -      -        -    -        0      0
3    enet  100003     1500  -      -      -        -    -        0      0
 
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#int fa0/2
Switch(config-if)#sw
Switch(config-if)#switchport mode acc
Switch(config-if)#switchport mode access
Switch(config-if)#sw
Switch(config-if)#switchport acc vlan 2
Switch(config-if)#no sh
Switch(config-if)#no shutdown
Switch(config-if)#int fa0/3
Switch(config-if)#sw
Switch(config-if)#switchport mode acc
Switch(config-if)#sw acc vlan 3
Switch(config-if)#no sh
Switch(config-if)#no shutdown
Switch(config-if)#int fa0/1
Switch(config-if)#sw
Switch(config-if)#switchport mode trun
Switch(config-if)#switchport mode trunk
%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
Switch(config-if)#
Switch(config-if)#no sh
Switch(config-if)#no shutdown
Switch(config-if)#int fa0/4
Switch(config-if)#sw mode tru
Switch(config-if)#sw mode trunk
Switch(config-if)#no sh
Switch(config-if)#no shutdown
 
 
SW1上的配置:
新建VLAN2和VLAN3
把端口Fa0/2, Fa0/3的访问模式设置为静态访问模式(switchport mode acc)
把端口Fa0/2加入VLAN2 ;  Fa0/3加入VLAN3
把端口Fa0/1,设置为Trunk模式
同理配置如SW0.
 
 
3.路由器的配置:
配置接口Fa0/0 打开该端口
配置Fa0/0的子接口 Fa0/0.1 Fa0/0.2 
Fa0/0.1 配置IP为:192.168.1.1 并且封装802.1Q
Fa0/0.2 配置IP为:192.168.2.1 并且封装802.1Q
 
先打开父端口fa0/0
Router(config)#int fa0/0
Router(config-if)#no sh
Router(config-if)#no shutdown
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
 
配置子端口 先封装802.1Q 再配置IP 才有效 
Router(config)#int fa0/0.1
Router(config-subif)#en
Router(config-subif)#encapsulation do
Router(config-subif)#encapsulation dot1Q 2
Router(config-subif)#ip add 192.168.1.1 255.255.255.0
Router(config-subif)#no sh
 
Router(config)#int fa0/0.2
%LINK-5-CHANGED: Interface FastEthernet0/0.2, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.2, changed state to up
Router(config-subif)#
Router(config-subif)#en
Router(config-subif)#encapsulation do
Router(config-subif)#encapsulation dot1Q 3
Router(config-subif)#ip add 192.168.2.1 255.255.255.0
Router(config-subif)#no sh