华为交换机配置跨网段通过vlanif通信,二层隔离三层通信

网络拓扑:

华为交换机配置跨网段通过vlanif通信,二层隔离三层通信

文章插图
拓扑图
通过ospf实现两个不同网段的三层互通二层隔离
交换机A vlan及端口配置信息The device is running!<Huawei>system-view#进入系统视图Enter system view, return user view with Ctrl+Z.[Huawei]sysname Switch#修改设备名称[Switch A]vlan batch 1030#批量创建vlan10 30[Switch A]interfaceGigabitEthernet0/0/1#进入端口0/0/1[Switch A-GigabitEthernet0/0/1]port link-type trunk#配置端口类型为trunk[Switch A-GigabitEthernet0/0/1]port trunk allow-passvlan 10#配置端口允许vlan 10[Switch A-GigabitEthernet0/0/1]quit#退出端口[Switch A]interfaceGigabitEthernet 0/0/2#进入端口0/0/2[Switch A-GigabitEthernet0/0/2]port link-type trunk#配置端口类型为trunk[Switch A-GigabitEthernet0/0/2]port trunk allow-passvlan 30#配置端口允许vlan 30[Switch A-GigabitEthernet0/0/2]quit#退出端口交换机A vlan ip和ospf配置信息[Switch A]interfaceVlanif10#进入vlanif 10[Switch A-Vlanif10]ip address10.10.10.1 24#配置IP地址及子网掩码[Switch A-Vlanif10]quit#退出[Switch A]interfaceVlanif 30#进入vlanif 30[Switch A-Vlanif30]ip address10.10.30.1 24#配置IP地址及子网掩码[Switch A-Vlanif30]quit#退出[Switch A]interfaceLoopBack 0#进入looback 0接口[Switch A-LoopBack0]ip address1.1.1.1 32#配置IP地址及子网掩码[Switch A-LoopBack0]quit#对此[Switch A]ospf 1#创建编号为1的ospf[Switch A-ospf-1]area 0#进入area 0 区域[Switch A-ospf-1-area-0.0.0.0]network 10.10.10.0 0.0.0.255#宣告网络及网络长度[Switch A-ospf-1-area-0.0.0.0]network 10.10.30.0 0.0.0.255#宣告网络及网络长度[Switch A-ospf-1-area-0.0.0.0]quit#退出区域0[Switch A-ospf-1]quit#退出ospf 1交换机B vlan及端口配置信息,和交换机A的配置差不多The device is running!<Huawei>system-view#进入系统视图Enter system view, return user view with Ctrl+Z.[Huawei]sysnameSwitch B#修改设备名称[Switch B]vlan batch10 30#批量创建vlan 10 30[Switch B]interfaceGigabitEthernet0/0/1#进入端口0/0/1[Switch B-GigabitEthernet0/0/1]port link-type trunk#配置端口类型为trunk[Switch B-GigabitEthernet0/0/1]port trunk allow-passvlan 10#配置端口允许vlan 10[Switch B-GigabitEthernet0/0/1]quit#退出端口[Switch B]interfaceGigabitEthernet 0/0/2#进入端口0/0/2[Switch B-GigabitEthernet0/0/2]port link-type trunk#配置端口类型为trunk[Switch B-GigabitEthernet0/0/2]port trunk allow-passvlan 30#配置端口允许vlan 30[Switch B-GigabitEthernet0/0/2]quit#退出端口交换机B vlan ip和ospf配置信,和交换机A的配置差不多[Switch B]interfaceVlanif10#进入vlanif 10[Switch B-Vlanif10]ip address 10.10.20.1 24#配置IP地址及子网掩码[Switch B-Vlanif10]quit#退出[Switch B]interfaceVlanif30#进入vlanif 30[Switch B-Vlanif30]ip address10.10.30.2 24#配置IP地址及子网掩码[Switch B-Vlanif30]ping 10.10.30.1#检测与交换机A的是否连通PING 10.10.30.1: 56data bytes, press CTRL_C to breakReply from 10.10.30.1: bytes=56 Sequence=1 ttl=255 time=80 msReply from 10.10.30.1: bytes=56 Sequence=2 ttl=255 time=1 msReply from 10.10.30.1: bytes=56 Sequence=3 ttl=255 time=50 msReply from 10.10.30.1: bytes=56 Sequence=4 ttl=255 time=40 msReply from 10.10.30.1: bytes=56 Sequence=5 ttl=255 time=30 ms--- 10.10.30.1 ping statistics ---5 packet(s) transmitted5 packet(s) received0.00% packet lossround-trip min/avg/max = 1/40/80 ms[Switch B-Vlanif30]quit#退出[Switch B]interfaceLoopBack 0 #进入looback 0接口[Switch B-LoopBack0]ip address2.2.2.2 32#配置IP地址及子网掩码,用做router ID[Switch B-LoopBack0]quit#退出[Switch B]ospf 1#创建编号为1的ospf#同样创建ospf 编号为1[Switch B-ospf-1]area 0#area区域为0,主干区域[Switch B-ospf-1-area-0.0.0.0]network 10.10.20.0 0.0.0.255#宣告网络及网络长度[Switch B-ospf-1-area-0.0.0.0]network 10.10.30.0 0.0.0.255#宣告网络及网络长度[Switch B-ospf-1-area-0.0.0.0]quit#退出[Switch B-ospf-1]quit#退出交换机C的接入配置,比较简单The device is running! <Huawei>system-view#进入系统视图Enter system view, return user view with Ctrl+Z.[Huawei]sysname Switch C#修改设备名称[Switch C]vlan10#创建vlan 10[Switch C]interfaceGigabitEthernet 0/0/2#进入端口0/0/2[Switch C-GigabitEthernet0/0/2]port link-type access#配置端口类型[Switch C-GigabitEthernet0/0/2]port defaultvlan10#配置默认vlan为10[Switch C-GigabitEthernet0/0/2]quit#退出[Switch C]interfaceGigabitEthernet 0/0/1#进入端口0/0/1[Switch C-GigabitEthernet0/0/1]port link-type trunk#配置端口类型[Switch C-GigabitEthernet0/0/1]port trunk allow-passvlan10#配置允许通行的vlan为10[Switch C-GigabitEthernet0/0/1]quit #退出交换机D的配置,跟交换机C一样,接入配置,比较简单The device is running!<Huawei>system-view#进入系统视图Enter system view, return user view with Ctrl+Z.[Huawei]sysnameSwitch D#修改设备名称[Switch D]vlan 10 #创建vlan 10[Switch D]interfaceGigabitEthernet 0/0/2#进入端口0/0/2[Switch D-GigabitEthernet0/0/2]port link-type access#配置端口类型[Switch D-GigabitEthernet0/0/2]port defaultvlan10#配置端口默认vlan为10[Switch D-GigabitEthernet0/0/2]quit #退出[Switch D]interfaceGigabitEthernet 0/0/1 #进入端口0/0/1[Switch D-GigabitEthernet0/0/1]port link-type trunk#配置端口类型[Switch D-GigabitEthernet0/0/1]port trunk allow-passvlan10#配置允许通行的vlan为10[Switch D-GigabitEthernet0/0/1]quit#退出


推荐阅读