三层交换机实现VLAN 间路由

配置三层交换机实现VLAN间路由
文章展示了如何使用华为交换机进行VLAN配置,创建VLAN41和42,并分配端口。配置完成后,VLAN41和42的IP地址可成功通信,实现了VLAN间的路由功能。

三层交换机集成了路由器和交换机的功能,融合了路由器和交换机各自的优势,在功能上实现了VLAN 的划分、VLAN 内部的二层交换和VLAN 间路由的功能。 

<Huawei>SYS
Enter system view, return user view with Ctrl+Z.
[Huawei]sysname WU
[WU]vlan batch 41 42
[WU]interface GigabitEthernet0/0/1
[WU-GigabitEthernet0/0/1]port link-type access
[WU-GigabitEthernet0/0/1]port default vlan 41
[WU-GigabitEthernet0/0/1]interface GigabitEthernet0/0/2
[WU-GigabitEthernet0/0/2]port link-type access
[WU-GigabitEthernet0/0/2]port default vlan 41
[WU-GigabitEthernet0/0/2]interface GigabitEthernet0/0/3
[WU-GigabitEthernet0/0/3]port link-type access
[WU-GigabitEthernet0/0/3]port default vlan 42
[WU-GigabitEthernet0/0/3]q
[WU]q
<WU>save
The current configuration will be written to the device.
Are you sure to continue?[Y/N]y
Info: Please input the file name ( *.cfg, *.zip ) [vrpcfg.zip]:
Sep 13 2022 01:05:27-08:00 WU %%01CFM/4/SAVE(l)[1]:The user chose Y when decidin
g whether to save the configuration to the device.

 

测试:
PC>ping 192.168.41.2

Ping 192.168.41.2: 32 data bytes, Press Ctrl_C to break
From 192.168.41.2: bytes=32 seq=1 ttl=128 time=32 ms
From 192.168.41.2: bytes=32 seq=2 ttl=128 time=32 ms
From 192.168.41.2: bytes=32 seq=3 ttl=128 time=46 ms
From 192.168.41.2: bytes=32 seq=4 ttl=128 time=31 ms
From 192.168.41.2: bytes=32 seq=5 ttl=128 time=47 ms

--- 192.168.41.2 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 31/37/47 ms

PC>ping 192.168.42.1

Ping 192.168.42.1: 32 data bytes, Press Ctrl_C to break
From 192.168.41.1: Destination host unreachable
From 192.168.41.1: Destination host unreachable
From 192.168.41.1: Destination host unreachable
From 192.168.41.1: Destination host unreachable
From 192.168.41.1: Destination host unreachable

--- 192.168.41.254 ping statistics ---
  5 packet(s) transmitted
  0 packet(s) received
  100.00% packet loss

PC>
三层配置:
[WU]interface Vlanif 41
[WU-Vlanif41]ip address 192.168.41.254 24
[WU-Vlanif41]q                    
[WU]interface Vlanif 42
[WU-Vlanif42]ip address 192.168.42.254 24
[WU-Vlanif42]q
[WU]q
<WU>save
The current configuration will be written to the device.
Are you sure to continue?[Y/N]y
Info: Please input the file name ( *.cfg, *.zip ) [vrpcfg.zip]:
Sep 13 2022 01:10:32-08:00 WU %%01CFM/4/SAVE(l)[6]:The user chose Y when decidin
g whether to save the configuration to the device.
Now saving the current configuration to the slot 0.
Save the configuration successfully.

[WU]display ip routing-table
Route Flags: R - relay, D - download to fib
------------------------------------------------------------------------------
Routing Tables: Public
         Destinations : 6        Routes : 6        

Destination/Mask    Proto   Pre  Cost      Flags NextHop         Interface

      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.41.0/24  Direct  0    0           D   192.168.41.254  Vlanif41
 192.168.41.254/32  Direct  0    0           D   127.0.0.1       Vlanif41
   192.168.42.0/24  Direct  0    0           D   192.168.42.254  Vlanif42
 192.168.42.254/32  Direct  0    0           D   127.0.0.1       Vlanif42

[WU]
测试:
PC>ping 192.168.42.1

Ping 192.168.42.1: 32 data bytes, Press Ctrl_C to break
From 192.168.42.1: bytes=32 seq=1 ttl=127 time=93 ms
From 192.168.42.1: bytes=32 seq=2 ttl=127 time=32 ms
From 192.168.42.1: bytes=32 seq=3 ttl=127 time=15 ms
From 192.168.42.1: bytes=32 seq=4 ttl=127 time=47 ms
From 192.168.42.1: bytes=32 seq=5 ttl=127 time=31 ms

--- 192.168.42.1 ping statistics ---
  5 packet(s) transmitted
  5 packet(s) received
  0.00% packet loss
  round-trip min/avg/max = 15/43/93 ms

PC>

### 配置三层交换机实现VLAN路由 在企业网络中,通过配置三层交换机VLANIF接口,可以实现不同VLAN的通信。以下是一个完整的配置指南,包括创建VLAN、绑定接口、配置SVI(Switch Virtual Interface)以及启用路由功能。 #### 1. 创建VLAN 首先,在三层交换机上创建所需的VLAN。使用以下命令来创建VLAN: ```shell [Switch] vlan batch <vlan-id> ``` 例如,创建VLAN 10和VLAN 20: ```shell [Switch] vlan batch 10 20 ``` #### 2. 将接口绑定到VLAN 将物理接口分配给相应的VLAN。对于Access模式的接口,使用以下命令: ```shell [Switch] interface <interface-name> [Switch-Interface] port link-type access [Switch-Interface] port access vlan <vlan-id> ``` 例如,将接口GigabitEthernet 0/0/1绑定到VLAN 10: ```shell [Switch] interface GigabitEthernet 0/0/1 [Switch-GigabitEthernet0/0/1] port link-type access [Switch-GigabitEthernet0/0/1] port access vlan 10 ``` #### 3. 配置Trunk接口 如果需要多个VLAN通过同一链路传输数据,则需要配置Trunk接口: ```shell [Switch] interface <interface-name> [Switch-Interface] port link-type trunk [Switch-Interface] port trunk allow-pass vlan <vlan-id-list> ``` 例如,将接口GigabitEthernet 0/0/2配置为Trunk,并允许VLAN 10和VLAN 20的数据通过: ```shell [Switch] interface GigabitEthernet 0/0/2 [Switch-GigabitEthernet0/0/2] port link-type trunk [Switch-GigabitEthernet0/0/2] port trunk allow-pass vlan 10 20 ``` #### 4. 配置VLANIF接口 为每个VLAN创建逻辑接口(VLANIF),并为其分配IP地址: ```shell [Switch] interface Vlanif <vlan-id> [Switch-Vlanif<vlan-id>] ip address <ip-address> <subnet-mask> ``` 例如,为VLAN 10配置IP地址10.1.1.1/24,为VLAN 20配置IP地址20.1.1.1/24: ```shell [Switch] interface Vlanif 10 [Switch-Vlanif10] ip address 10.1.1.1 255.255.255.0 [Switch] interface Vlanif 20 [Switch-Vlanif20] ip address 20.1.1.1 255.255.255.0 ``` #### 5. 启用路由功能 默认情况下,三层交换机可能需要手动启用IP路由功能: ```shell [Switch] ip routing ``` #### 6. 验证配置 完成上述配置后,可以通过以下命令验证VLAN路由的配置是否正确: - 查看VLAN信息:`display vlan` - 查看接口状态:`display interface brief` - 查看路由表:`display ip routing-table` 通过以上步骤,三层交换机可以成功实现VLAN路由功能[^1]。 #### 示例配置 以下是一个完整的示例配置脚本: ```shell [Switch] vlan batch 10 20 [Switch] interface GigabitEthernet 0/0/1 [Switch-GigabitEthernet0/0/1] port link-type access [Switch-GigabitEthernet0/0/1] port access vlan 10 [Switch] interface GigabitEthernet 0/0/2 [Switch-GigabitEthernet0/0/2] port link-type trunk [Switch-GigabitEthernet0/0/2] port trunk allow-pass vlan 10 20 [Switch] interface Vlanif 10 [Switch-Vlanif10] ip address 10.1.1.1 255.255.255.0 [Switch] interface Vlanif 20 [Switch-Vlanif20] ip address 20.1.1.1 255.255.255.0 [Switch] ip routing ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值