不同VLAN下实现网络互相通信(配置ip static静态路由进行数据转发)

1. 三台交换机,不同VLAN,不同网段实现网络互通,逻辑拓扑图如下:

  需求:实现VLAN 10、VLAN 20、VLAN 30之间的PC网络互通

 

 在LSW 14交换机进行如下命令行配置:

<Huawei>system-view             #进入系统视图
[Huawei]sysname test            #将交换机命名为test
[test]vlan batch 5 10            #创建vlan 5和vlan 10
[test]vlan 5            #进入vlan 5
[test-vlan5]description internet            #为vlan 5描述为internet
[test-vlan5]quit             #退出

[test]vlan 10            #进入vlan 10
[test-vlan10]description test            #为vlan 10描述为test
[test-vlan10]quit            #退出


#接口配置
[test]interface e0/0/1            #进入e0/0/1接口
[test-Ethernet0/0/1]port link-type access            #将链路类型设置为access
[test-Ethernet0/0/1]port default vlan 10            #划分至vlan 10中
[test-Ethernet0/0/1]quit            #退出

[test]interface e0/0/2            #进入e0/0/2接口
[test-Ethernet0/0/2]port link-type access            #链路类型为access
[test-Ethernet0/0/2]port default vlan 10            #划分至vlan 10
[test-Ethernet0/0/2]quit            #退出

[test]interface e0/0/3            #进入e0/0/3接口
[test-Ethernet0/0/3]port link-type trunk            #链路类型trunk
[test-Ethernet0/0/3]port trunk allow-pass vlan 5            #只运行vlan 5数据通过
[test-Ethernet0/0/3]quit            #退出

#vlanif IP配置
[test]interface Vlanif 10            #进入vlan 10
[test-Vlanif10]ip address 192.168.10.1 24            #配置vlan 10 IP网关
[test-Vlanif10]quit             #退出

[test]interface Vlanif 5            #进入vlan 5
[test-Vlanif5]ip address 10.0.1.1 24            #配置vlan 5 IP网关
[test-Vlanif5]quit            #退出

#配置静态路由
[test]ip route-static 192.168.20.0 255.255.255.0 10.0.1.2            #目的地为192.168.20.0/24的数据包全部转发给10.0.1.2

[test]ip route-static 192.168.30.0 255.255.255.0 10.0.1.3            #目的地为192.168.30.0/24的数据包全部转发给10.0.1.3

#查看路由表信息
[test]display ip routing-table             #查看路由表


Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 8        Routes : 8        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.1.0/24  Direct  0    0           D   10.0.1.1        Vlanif5
       10.0.1.1/32  Direct  0    0           D   127.0.0.1       Vlanif5
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
   192.168.10.0/24  Direct  0    0           D   192.168.10.1    Vlanif10
   192.168.10.1/32  Direct  0    0           D   127.0.0.1       Vlanif10
   192.168.20.0/24  Static  60   0          RD   10.0.1.2        Vlanif5
   192.168.30.0/24  Static  60   0          RD   10.0.1.3        Vlanif5

 

 在LSW 15交换机上配置:

<Huawei>system-view             #进入系统视图
[Huawei]sysname device            #命名为device
[device]vlan 5            #创建vlan 5
[device-vlan5]description internet            #为vlan 5描述为internet
[device-vlan5]quit        #退出

[device]vlan 20        #创建vlan 20
[device-vlan20]description device            #为vlan 20描述为device
[device-vlan20]quit        #退出

#接口配置
[device]interface g0/0/1            #进入g0/0/1接口
[device-GigabitEthernet0/0/1]port link-type access            #链路类型access
[device-GigabitEthernet0/0/1]port default vlan 20            #划分至vlan 20
[device-GigabitEthernet0/0/1]quit             #退出

[device]interface g0/0/2            #进入g0/0/2接口
[device-GigabitEthernet0/0/2]port link-type access            #链路类型access
[device-GigabitEthernet0/0/2]port default vlan 20            #划分至vlan 20
[device-GigabitEthernet0/0/2]quit            #退出

[device]interface g0/0/3            #进入g0/0/3接口
[device-GigabitEthernet0/0/3]port link-type trunk            #链路类型trunk
[device-GigabitEthernet0/0/3]port trunk allow-pass vlan 5            #只允许vlan 5数据通过
[device-GigabitEthernet0/0/3]quit            #退出

[device]interface g0/0/4            #进入g0/0/4接口
[device-GigabitEthernet0/0/4]port link-type trunk            #链路类型trunk
[device-GigabitEthernet0/0/4]port trunk allow-pass vlan 5            #只允许vlan 5数据通过
[device-GigabitEthernet0/0/4]quit             #退出

#配置vlan IP地址
[device]interface Vlanif 20            #进入vlan 20
[device-Vlanif20]ip address 192.168.20.1 24            #配置vlan 20网关地址
[device-Vlanif20]quit                 #退出

[device]interface Vlanif 5            #进入vlan 5
[device-Vlanif5]ip address 10.0.1.2 24            #配置vlan 5网关地址
[device-Vlanif5]quit            #退出


#配置静态路由
[device]ip route-static 192.168.10.0 24 10.0.1.1            #目的地为192.168.10.0/24的数据包全部转发给10.0.1.1

[device]ip route-static 192.168.30.0 24 10.0.1.3            #目的地为192.168.30.0/24的数据包全部转发给10.0.1.3


#查看路由表
[device]display ip routing-table            #查看路由表


Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 8        Routes : 8        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.1.0/24  Direct  0    0           D   10.0.1.2        Vlanif5
       10.0.1.2/32  Direct  0    0           D   127.0.0.1       Vlanif5
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
   192.168.10.0/24  Static  60   0          RD   10.0.1.1        Vlanif5
   192.168.20.0/24  Direct  0    0           D   192.168.20.1    Vlanif20
   192.168.20.1/32  Direct  0    0           D   127.0.0.1       Vlanif20
   192.168.30.0/24  Static  60   0          RD   10.0.1.3        Vlanif5

 

 继续在交换机LSW 16上配置:

<Huawei>system-view             #切换系统视图
[Huawei]sysname info            #将交换机命名为info
[info]vlan batch 5 30            #批量创建vlan 5和vlan 30
[info]vlan 5            #进入vlan 5
[info-vlan5]description internet            #为vlan 5描述为internet
[info-vlan5]quit            #退出

[info]vlan 30            #进入vlan 30
[info-vlan30]description info            #为vlan 30描述为info
[info-vlan30]quit            #退出

#接口配置
[info]interface e0/0/1            #进入e0/0/1接口
[info-Ethernet0/0/1]port link-type access            #链路类型access
[info-Ethernet0/0/1]port default vlan 30            #划分至vlan 30
[info-Ethernet0/0/1]quit            #退出

[info]interface e0/0/2            #进入e0/0/2接口
[info-Ethernet0/0/2]port link-type access            #链路类型access
[info-Ethernet0/0/2]port default vlan 30            #划分至vlan 30
[info-Ethernet0/0/2]quit            #退出

[info]interface e0/0/3            #进入e0/0/3接口
[info-Ethernet0/0/3]port link-type trunk             #链路类型trunk
[info-Ethernet0/0/3]port trunk allow-pass vlan 5            #只允许vlan 5数据通过
[info-Ethernet0/0/3]quit            #退出

#配置vlan IP
[info]interface Vlanif 30            #进入vlan 30
[info-Vlanif30]ip address 192.168.30.1 24            #配置vlan 30 网关地址
[info-Vlanif30]quit             #退出

[info]interface Vlanif 5            #进入vlan 5
[info-Vlanif5]ip address 10.0.1.3 24            #配置vlan 5网关地址
[info-Vlanif5]quit            #退出

#配置静态路由
[info]ip route-static 192.168.10.0 24 10.0.1.1            #目的地为192.168.10.0/24的数据包全部转发给10.0.1.1

[info]ip route-static 192.168.20.0 24 10.0.1.2            #目的地为192.168.20.0/24的数据包全部转发给10.0.1.2


#查看路由表
[info]display ip routing-table            #查看路由表


Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 8        Routes : 8        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

       10.0.1.0/24  Direct  0    0           D   10.0.1.3        Vlanif5
       10.0.1.3/32  Direct  0    0           D   127.0.0.1       Vlanif5
      127.0.0.0/8   Direct  0    0           D   127.0.0.1       InLoopBack0
      127.0.0.1/32  Direct  0    0           D   127.0.0.1       InLoopBack0
   192.168.10.0/24  Static  60   0          RD   10.0.1.1        Vlanif5
   192.168.20.0/24  Static  60   0          RD   10.0.1.2        Vlanif5
   192.168.30.0/24  Direct  0    0           D   192.168.30.1    Vlanif30
   192.168.30.1/32  Direct  0    0           D   127.0.0.1       Vlanif30

 

 验证网络通信状态(VLAN 10、VLAN 20、VLAN 30之间的PC可以互通通信):

 

posted @ 2020-12-06 18:40  凡是過往;皆為序章  阅读(2754)  评论(0编辑  收藏  举报