

图1 三层交换机与路由器对接上网组网图

三层交换机是具有路由功能的交换机。 由于路由属于 OSI 模型中的第三层(网络层)功能,因此称为三层交换机。
三层交换机既可以工作在二层,也可以工作在三层, 可以部署在:
具体默认版本请参见产品说明文档。
某公司拥有多个部门,位于不同网段,各部门均需访问 Internet。
要求:
<HUAWEI> system-view
[HUAWEI] sysname Switch
[Switch] vlan batch 2 3
[Switch] interface gigabitethernet 0/0/2
[Switch-GE0/0/2] port link-type access
[Switch-GE0/0/2] port default vlan 2
[Switch-GE0/0/2] quit
[Switch] interface gigabitethernet 0/0/3
[Switch-GE0/0/3] port link-type access
[Switch-GE0/0/3] port default vlan 3
[Switch-GE0/0/3] quit
[Switch] interface vlanif 2
[Switch-Vlanif2] ip address 192.168.1.1 24
[Switch-Vlanif2] quit
[Switch] interface vlanif 3
[Switch-Vlanif3] ip address 192.168.2.1 24
[Switch-Vlanif3] quit
[Switch] vlan batch 100
[Switch] interface gigabitethernet 0/0/1
[Switch-GE0/0/1] port link-type access
[Switch-GE0/0/1] port default vlan 100
[Switch-GE0/0/1] quit
[Switch] interface vlanif 100
[Switch-Vlanif100] ip address 192.168.100.2 24
[Switch-Vlanif100] quit
[Switch] ip route-static 0.0.0.0 0.0.0.0 192.168.100.1
[Switch] dhcp enable
[Switch] interface vlanif 2
[Switch-Vlanif2] dhcp select interface
[Switch-Vlanif2] dhcp server dns-list 114.114.114.114 223.5.5.5
[Switch-Vlanif2] quit
[Switch] interface vlanif 3
[Switch-Vlanif3] dhcp select interface
[Switch-Vlanif3] dhcp server dns-list 114.114.114.114 223.5.5.5
[Switch-Vlanif3] quit
<Huawei> system-view
[Huawei] sysname Router
[Router] interface gigabitethernet 0/0/1
[Router-GE0/0/1] ip address 192.168.100.1 255.255.255.0
[Router-GE0/0/1] quit
[Router] interface gigabitethernet 0/0/2
[Router-GE0/0/2] ip address 203.0.113.2 255.255.255.0
[Router-GE0/0/2] quit
[Router] ip route-static 0.0.0.0 0.0.0.0 203.0.113.1
[Router] ip route-static 192.168.0.0 255.255.0.0 192.168.100.2
[Router] acl number 2001
[Router-acl-basic-2001] rule 5 permit source 192.168.0.0 0.0.255.255
[Router-acl-basic-2001] quit
[Router] interface gigabitethernet 0/0/2
[Router-GE0/0/2] nat outbound 2001
[Router-GE0/0/2] quit
设备 | IP | 网关 |
|---|---|---|
PC1 | 192.168.1.2/24 | 192.168.1.1 |
PC2 | 192.168.2.2/24 | 192.168.2.1 |
设备 | IP | 网关 |
|---|---|---|
外网PC | 203.0.113.1/24 | 203.0.113.2 |
验证结果:
sysname Switch
vlan batch 2 to 3 100
dhcp enable
interface Vlanif2
ip address 192.168.1.1 255.255.255.0
dhcp select interface
dhcp server dns-list 114.114.114.114 223.5.5.5
interface Vlanif3
ip address 192.168.2.1 255.255.255.0
dhcp select interface
dhcp server dns-list 114.114.114.114 223.5.5.5
interface Vlanif100
ip address 192.168.100.2 255.255.255.0
interface GigabitEthernet0/0/1
port link-type access
port default vlan 100
interface GigabitEthernet0/0/2
port link-type access
port default vlan 2
interface GigabitEthernet0/0/3
port link-type access
port default vlan 3
ip route-static 0.0.0.0 0.0.0.0 192.168.100.1
return
sysname Router
acl number 2001
rule 5 permit source 192.168.0.0 0.0.255.255
interface GigabitEthernet0/0/1
ip address 192.168.100.1 255.255.255.0
interface GigabitEthernet0/0/2
ip address 203.0.113.2 255.255.255.0
nat outbound 2001
ip route-static 0.0.0.0 0.0.0.0 203.0.113.1
ip route-static 192.168.0.0 255.255.0.0 192.168.100.2
return