不同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可以互通通信):

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM