配置通过VLANIF实现跨设备VLAN内通信示例
组网需求
如图4-33所示,Switch_1和Switch_2分别下挂VLAN10的二层网络,Switch_1和Switch_2之间通过三层网络互通,三层网络采用OSPF协议。
要求两个二层网络的PC实现二层隔离三层互通。
配置思路
采用如下的思路配置通过VLANIF接口跨越三层网络通信:
配置接口所属的VLAN,允许VLAN通过当前接口。
配置VLANIF接口的IP地址,实现三层互通。
配置OSPF基本功能,实现路由互通。
操作步骤
- 配置Switch_1
# 创建VLAN10和VLAN30。
<HUAWEI> system-view [HUAWEI] sysname Switch_1 [Switch_1] vlan batch 10 30
# 配置接口GE1/0/1加入VLAN10,GE1/0/2加入VLAN30。
[Switch_1] interface gigabitethernet 1/0/1 [Switch_1-GigabitEthernet1/0/1] port link-type trunk [Switch_1-GigabitEthernet1/0/1] port trunk allow-pass vlan 10 [Switch_1-GigabitEthernet1/0/1] quit [Switch_1] interface gigabitethernet 1/0/2 [Switch_1-GigabitEthernet1/0/2] port link-type trunk [Switch_1-GigabitEthernet1/0/2] port trunk allow-pass vlan 30 [Switch_1-GigabitEthernet1/0/2] quit
# 配置VLANIF10的IP地址为10.10.10.1/24,VLANIF30的IP地址为10.10.30.1/24。
[Switch_1] interface vlanif 10 [Switch_1-Vlanif10] ip address 10.10.10.1 24 [Switch_1-Vlanif10] quit [Switch_1] interface vlanif 30 [Switch_1-Vlanif30] ip address 10.10.30.1 24 [Switch_1-Vlanif30] quit
# 配置OSPF基本功能。
[Switch_1] router id 1.1.1.1 [Switch_1] ospf [Switch_1-ospf-1] area 0 [Switch_1-ospf-1-area-0.0.0.0] network 10.10.10.0 0.0.0.255 [Switch_1-ospf-1-area-0.0.0.0] network 10.10.30.0 0.0.0.255 [Switch_1-ospf-1-area-0.0.0.0] quit
- 配置Switch_2
# 创建VLAN10和VLAN30。
<HUAWEI> system-view [HUAWEI] sysname Switch_2 [Switch_2] vlan batch 10 30
# 配置接口GE1/0/1加入VLAN10,GE1/0/2加入VLAN30。
[Switch_2] interface gigabitethernet 1/0/1 [Switch_2-GigabitEthernet1/0/1] port link-type trunk [Switch_2-GigabitEthernet1/0/1] port trunk allow-pass vlan 10 [Switch_2-GigabitEthernet1/0/1] quit [Switch_2] interface gigabitethernet 1/0/2 [Switch_2-GigabitEthernet1/0/2] port link-type trunk [Switch_2-GigabitEthernet1/0/2] port trunk allow-pass vlan 30 [Switch_2-GigabitEthernet1/0/2] quit
# 配置VLANIF10的IP地址为10.10.20.1/24,VLANIF30的IP地址为10.10.30.2/24。
[Switch_2] interface vlanif 10 [Switch_2-Vlanif10] ip address 10.10.20.1 24 [Switch_2-Vlanif10] quit [Switch_2] interface vlanif 30 [Switch_2-Vlanif30] ip address 10.10.30.2 24 [Switch_2-Vlanif30] quit
# 配置OSPF基本功能。
[Switch_2] router id 2.2.2.2 [Switch_2] ospf [Switch_2-ospf-1] area 0 [Switch_2-ospf-1-area-0.0.0.0] network 10.10.20.0 0.0.0.255 [Switch_2-ospf-1-area-0.0.0.0] network 10.10.30.0 0.0.0.255 [Switch_2-ospf-1-area-0.0.0.0] quit
- 配置Switch_3
# 创建VLAN10,并配置接口GE1/0/1以Untagged方式加入VLAN10,接口GE1/0/2以Tagged方式加入VLAN10。Switch_4的配置与Switch_3类似,不再赘述。
<HUAWEI> system-view [HUAWEI] sysname Switch_3 [Switch_3] vlan batch 10 [Switch_3] interface gigabitethernet 1/0/1 [Switch_3-GigabitEthernet1/0/1] port link-type access [Switch_3-GigabitEthernet1/0/1] port default vlan 10 [Switch_3-GigabitEthernet1/0/1] quit [Switch_3] interface gigabitethernet 1/0/2 [Switch_3-GigabitEthernet1/0/2] port link-type trunk [Switch_3-GigabitEthernet1/0/2] port trunk allow-pass vlan 10 [Switch_3-GigabitEthernet1/0/2] quit
- 检查配置结果
Switch_1下挂的二层网络中PC上配置缺省网关为VLANIF10接口的IP地址10.10.10.1。
Switch_2下挂的二层网络中PC上配置缺省网关为VLANIF10接口的IP地址10.10.20.1。
配置完成后,两个二层网络的PC实现二层隔离三层互通。
配置文件
Switch_1的配置文件
# sysname Switch_1 # router id 1.1.1.1 # vlan batch 10 30 # interface Vlanif10 ip address 10.10.10.1 255.255.255.0 # interface Vlanif30 ip address 10.10.30.1 255.255.255.0 # interface GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 10 # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 30 # ospf 1 area 0.0.0.0 network 10.10.10.0 0.0.0.255 network 10.10.30.0 0.0.0.255 # return
Switch_2的配置文件
# sysname Switch_2 # router id 2.2.2.2 # vlan batch 10 30 # interface Vlanif10 ip address 10.10.20.1 255.255.255.0 # interface Vlanif30 ip address 10.10.30.2 255.255.255.0 # interface GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 10 # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 30 # ospf 1 area 0.0.0.0 network 10.10.20.0 0.0.0.255 network 10.10.30.0 0.0.0.255 # return
Switch_3的配置文件
# sysname Switch_3 # vlan batch 10 # interface GigabitEthernet1/0/1 port link-type access port default vlan 10 # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 10 # return
Switch_4的配置文件
# sysname Switch_4 # vlan batch 10 # interface GigabitEthernet1/0/1 port link-type access port default vlan 10 # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 10 # return