今天我们来说一下,如何通过交换机网关上网:
要求交换机作为下面两个网段,192.168.2.0/24网段和192.168.3.0/24网段的网关。在交换机上创建两个vlan虚地址,并添加缺省路由指向路由器的网关,路由器上添加两条明细的回程路由,交换机的G1/0/2接PC1,G1/0/3接PC2,要求PC1和PC2可以访问互联网(访问路由器的网关)。
路由器端配置#配置虚接口地址
<H3C>system-view
[H3C]interface Vlan-interface 1
[H3C-Vlan-interface1]ip address 192.168.1.1 24
[H3C-Vlan-interface1]quit
#添加两条静态路由
[H3C]ip route-static 192.168.2.0 24 192.168.1.254
[H3C]ip route-static 192.168.3.0 24 192.168.1.254
#保存配置
[H3C]save force
交换机端的配置#创建vlan
<H3C>system-view
[H3C]vlan 2 to 3
#创建虚接口地址,vlan2和vlan3的地址分别作为PC1和PC2的网关
[H3C]interface vlan 1
[H3C-Vlan-interface1]ip address 192.168.1.254 24
[H3C]interface vlan 2
[H3C-Vlan-interface2]ip address 192.168.2.1 24
[H3C]interface vlan 3
[H3C-Vlan-interface3]ip address 192.168.3.1 24
#将连接PC1和PC2接口划分到相应的vlan中
[H3C]interface GigabitEthernet 1/0/2
[H3C-GigabitEthernet1/0/2] port access vlan 2
[H3C-GigabitEthernet1/0/2]interface GigabitEthernet 1/0/3
[H3C-GigabitEthernet1/0/3] port access vlan 3
#添加静态路由,指向路由器的网关
[H3C]ip route-static 0.0.0.0 0 192.168.1.1
#保存配置
[H3C]save force
伙伴们,你们学会了吗?