案例33:单臂路由实现VLAN间路由

问题引入:

不同vlan之间如何通信?

如果是二层交换机,可以另外借助一台路由器,做单臂路由;如果是三层交换机,直接开启三层交换功能,思科的话需要全局配置模式下手动开ip routing,华为或者其他思科风格的交换机应该默认开启的
不同vlan之间如何通信?

一、单臂路由概述

(1)单臂路由可实现不同vlan间的通信

(2)把路由器的物理接口划分成多个逻辑接口《虚拟网关》,每一个子接口对应一个vlan网段的网关,实现通信。

(3)链路类型,交换机连接主机的 端口为access链路,交换机连接路由器的端口为trunk链路

二、单臂路由的配置

在交换机里

(1)vlan 10 《创建vlan10》

(2)vlan 20 《创建vlan20》

(3)in f0/1 《进入接口0/1》

(4)sw acc vlan 10 《将0/1接口加入到vlan10》

(5)in f0/2 《进入接口0/2》

(6)sw acc vlan 20 《将接口0/2加入到vlan20》

(7)in f0/24 《进入接口0/24》

(8)sw mo tr 《将接口0/24改为trunk 模式》

在路由里

(1)in f0/0 《进入接口0/0》

(2)no sh 《激活0/0接口》

(3)in f0/0.1 《进入虚拟接口0/0.1》

(4)en dot1q 10 《将dot1q <这个是不同设备间通信的公有协议,还有一个思科的私有协议>协议封装到vlan10 里边,和虚拟接口0/0.1通信》

(5)ip add 0.0.0.0 0.0.0.0 《给虚拟接口0/0.1 设置ip地址和子网掩码》

(6)no sh 《激活虚拟接口0/0.1》

(7)in f0/0.2 《进入虚拟接口0/0.2》

(8)en dot1q 20 《将dot1q协议封装到vlan20里边和虚拟接口0/0.2通信》

(9)ip add 0.0.0.0 .0.0.0.0 《给虚拟接口0/0.2设置ip地址和子网掩码》

(10)no sh 《激活虚拟接口 0/0.2》

感谢:张闯 传送门

 

 静态路由的思想就是把一个路由器分成两个接口,这两个接口用来实现两个不能VLAN之间的通信

一、配置主机IP地址

二、配置路由器

Switch>en
Switch#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Switch(config)#hostname S1
S1(config)#int range f0/1
S1(config-if-range)#switchPort mode trunk
S1(config-if-range)#end
S1#
%SYS-5-CONFIG_I: Configured from console by console
将交换机与路由器之间的链路设置为trunk
S1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
S1(config)#vlan 2
S1(config-vlan)#exit
S1(config)#vlan 3
S1(config-vlan)#end
S1#
%SYS-5-CONFIG_I: Configured from console by console
创建VLAN
S1#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
S1(config)#int f0/5
S1(config-if)#switchport mode access
S1(config-if)#switchport access vlan 2
S1(config-if)#exit
S1(config)#int f0/6
S1(config-if)#switchport mode access
S1(config-if)#switchport access vlan 3
S1(config-if)#end
S1#
%SYS-5-CONFIG_I: Configured from console by console
划分VLAN端口

 测试PC0与PC1之间连通性,由于交换机为配置,ping失败!

三、配置路由器

Router>en
Router#conf t
Enter configuration commands, one per line.  End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#no shut

%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up

Router(config-if)#exit
Router(config)#int f0/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)#encapsulation dot1Q 2
Router(config-subif)#ip addr 172.16.1.1 255.255.255.0
Router(config-subif)#int f0/0.3

%LINK-5-CHANGED: Interface FastEthernet0/0.3, changed state to up

%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0.3, changed state to up
Router(config-subif)#encap
Router(config-subif)#encapsulation dot1Q 3
Router(config-subif)#ip addr 172.16.2.1 255.255.255.0
Router(config-subif)#end
Router#
%SYS-5-CONFIG_I: Configured from console by console
为VLAN2和VLAN3配置子接口
Router#sh ip ro
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

     172.16.0.0/24 is subnetted, 2 subnets
C       172.16.1.0 is directly connected, FastEthernet0/0.2
C       172.16.2.0 is directly connected, FastEthernet0/0.3
Router#
验证R1路由表

单臂路由的配置就是使用dot1Q协议来实现PC机之间通信

百度百科:dot1q就是802.1q,是vlan的一种封装方式。dot就是点的意思,就简写为dot1q了  传送门

此时PC0能直接Ping通PC1!

 

dot1Q协议

猜你喜欢

转载自www.cnblogs.com/1138720556Gary/p/9170822.html