实验拓扑




实验目的



       理解单臂路由的原理



交换机被配置成两个VLAN:VLAN10和VLAN20。端口F0/3配置为一个中继端口,也就是说端口F0/3属于VLAN 10和VLAN 20。在路由器的一个快速以太口上配置两个子接口,每个子接口被配置到一个独立的IP子网上,并为每个子接口封装一个VLAN ID,分别对应VLAN 10和VLAN 20。
因此,交换机中VLAN 10或VLAN 20的数据流可以通过中继端口F0/3到达路由器子接口f0/0.10或f0/0.20,通过两个子接口实现两个VLAN之间的路由。因为路由器只有一个物理接口同一个交换机端口相连接,所以这种路由器有一种别名:单臂路由器

       掌握VLAN间路由的配置



实验要求:



1.利用路由器R1和R2模拟PC1 、PC2,关闭路由功能



2.将路由器R1的E0/0端口的IP设为:192.168.0.10/24,默认网关设为:192.168.0.1



3.将路由器R2的E0/0的端口的IP设为:192.168.1.10、24,默认网关为:192.168.1.1



4.将交换机SW1关闭路由功能作为二层交换机使用,并将F0/1端口划分到VLAN 10中,F0/2端口划分到VLAN 20中



实验步骤:



步骤1.在R1上进行配置



pc1(config)# 
    no ip routing  
     //关闭路由功能 
    
pc1(config)# 
    ip default-gateway 192.168.0.1  
    //配置网关为:192.168.0.1 
    
pc1(config)# 
    interface e0/0 pc1(config-if)# 
    ip address 192.168.0.10 255.255.255.0 
    
pc1(config-if)# 
    no shutdown 
    
   

     pc1(config-if)# 
    duplex full    
    //开启全双工



步骤2.在R2上进行配置



pc2(config)# 
    no ip routing 
    
pc2(config)# 
    ip default-gateway 192.168.1.1 
    
pc2(config)# 
    interface e0/0 
    
pc2(config-if)# 
    ip address 192.168.0.10 255.255.255.0 pc2(config-if)# 
    no shutdown 
    

pc2(config-if)# 
    duplex full


步骤3. 在SW1上划分VLAN并将端口加入到VLAN中



sw1# 
    vlan database  
    //进入数据库模式 
    
sw1(vlan)# 
    vlan 10    
     //创建VLAN 10 
    
VLAN 10 added: 
    
    Name: VLAN0010 
    
sw1(vlan)# 
    vlan 20 
    
VLAN 20 added: 
    
    Name: VLAN0020 
    
sw1(vlan)# 
    exit 
    
APPLY completed. 
    
Exiting.... 
    
      sw1# 
     configure terminal sw1(config)# 
     interface fastethernet 0/1    
     
sw1(config-if)# 
     switchport mode access    
     //将接口的模式设置为接入模式 
     
sw1(config-if)# 
     switchport access vlan 10 
     //将接口划入VLAN 10
sw1(config-if)# 
     no shutdown


sw1(config)# 
     interface fastethernet0/2sw1(config-if)# 
     switchport mode access 
     
sw1(config-if)# 
     switchport access vlan 20 
     
sw1(config-if)# 
     no shutdown


在PC1上ping PC2



pc1# 
     ping 192.168.1.10 
     

       Type escape sequence to abort. 
      
Sending 5, 100-byte ICMP Echos to 192.168.1.10, timeout is 2 seconds: 
      
.....



//说明同一交换机上的不同VLAN的两个端口之间不能通信



步骤4.在SW1上与R3相连的端口F0/3封装为Trunk



sw1(config-if)# 
      interface f0/3 
     
 
     

       sw1(config-if)# 
      switchport mode trunk    
      //将接口配置成Trunk
 
     

       sw1(config-if)# 
      switchport trunk encapsulation dot1q   
      //封装Trunk为dot1q


步骤5. 配置R3



R3(config-if)# 
      interface e0/0 R3(config-if)# 
      duplex full R3(config-if)# 
      no shutdown 
     
 
     

       R3(config)# 
      interface e0/0.10   
      //开启E0/0的子接口E0/0.10
R3(config-subif)# 
      encapsulation dot1q 10 
      //封装为dot1q   10为vlan ID
R3(config-subif)# 
      ip address 192.168.0.1 255.255.255.0 
      // 设置该子接口的IP地址为R1的所指向的默认网关地址192.168.0.1
R3(config-subif)# 
      no shutdown 
      
R3(config-subif)# 
      interface e0/0.20 
      
R3(config-subif)# 
      encapsulation dot1q 20 
      
R3(config-subif)# 
      ip address 192.168.1.1 255.255.255.0 
      
R3(config-subif)# 
      no shutdown


步骤6. 验证R1和R2之间的连通性



pc1# 
      ping 192.168.0.1 
      

        Type escape sequence to abort. 
       
Sending 5, 100-byte ICMP Echos to 192.168.0.1, timeout is 2 seconds: 
       
!!!!!


// 在R1上Ping自己的默认网关成功



pc2# 
       ping 192.168.1.1 
       

         Type escape sequence to abort. 
        
Sending 5, 100-byte ICMP Echos to 192.168.1.1, timeout is 2 seconds: 
        
.!!!! 
        // 在R2上Ping自己的默认网关成功


Type escape sequence to abort. 
          
Sending 5, 100-byte ICMP Echos to 192.168.1.10, timeout is 2 seconds: 
          
!!!!! 
          
Success rate is 100 percent (5/5), round-trip min/avg/max = 48/89/196 ms

//在R1上pingR2成功,说明R1和R2能相互通信。这就通过用三层设备路由器解决交换机不同VLAN之间相互通信的问题


转载于:https://blog.51cto.com/ljp0501/142464