拓扑:
-
需求
1.如图配置IP地址和设备互联
2.实现不同VLAN之间的PC互通
-
思路
1.配置终端设备
-IP/掩码/网关
2.配置网络设备
-交换机:vlan/trunk/access
-多层交换机:网关接口(vlanif)、路由
3.验证与测试
PC1:
192.168.10.1
255.255.255.0
192.168.10.254PC2:
192.168.20.2
255.255.255.0
192.168.20.254PC3:
192.168.10.3
255.255.255.0
192.168.10.254PC4:
192.168.30.4
255.255.255.0
192.168.30.254PC5:
192.168.40.5
255.255.255.0
192.168.40.254SW1:
undo terminal monitor
system-view
sysname SW1
vlan batch 10 20 30 40interface gi0/0/12
port link-type trunk
port trunk allow-pass vlan all
quitinterface gi0/0/21
port link-type trunk
port trunk allow-pass vlan all
quitinterface gi0/0/1
port link-type access
port default vlan 10
quit
SW2:
undo terminal monitor
system-view
sysname SW2
vlan batch 10 20 30 40interface gi0/0/12
port link-type trunk
port trunk allow-pass vlan all
quitinterface gi0/0/21
port link-type trunk
port trunk allow-pass vlan all
quitinterface gi0/0/22
port link-type trunk
port trunk allow-pass vlan all
quitinterface gi0/0/23
port link-type trunk
port trunk allow-pass vlan all
quitSW3:
undo terminal monitor
system-view
sysname SW3
vlan batch 10 20 30 40interface gi0/0/23
port link-type trunk
port trunk allow-pass vlan all
quitinterface gi0/0/5
port link-type access
port default vlan 40
quit
SW4:
undo terminal monitor
system-view
sysname SW4
vlan batch 10 20 30 40interface gi0/0/1
port link-type trunk
port trunk allow-pass vlan all
quitinterface gi0/0/2
port link-type trunk
port trunk allow-pass vlan all
quitinterface eth0/0/22
port link-type trunk
port trunk allow-pass vlan all
quitinterface eth0/0/2
port link-type access
port default vlan 20
quitinterface eth0/0/3
port link-type access
port default vlan 10
quit
SW5:
undo terminal monitor
system-view
sysname SW5
vlan batch 10 20 30 40interface gi0/0/1
port link-type trunk
port trunk allow-pass vlan all
quitinterface eth0/0/22
port link-type trunk
port trunk allow-pass vlan all
quitinterface eth0/0/4
port link-type access
port default vlan 30
quit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
SW1:
interface vlanif 10
ip address 192.168.10.254 24
quit
SW2:
interface vlanif 20
ip address 192.168.20.254 24
quitSW3:
interface vlanif 30
ip address 192.168.30.254 24
quit
interface vlanif 40
ip address 192.168.40.254 24
quit
-------------------------------网关之间,添加路由------------------------------@为了实现VLAN 10 和 VLAN 20 互通,我们在 SW1/2 之间,添加一个 VLAN 12(192.168.12.0/24)
SW1:
vlan 12
quit
interface vlanif 12
ip address 192.168.12.1 24
quitip route-static 192.168.20.0 24 192.168.12.2
SW2:
vlan 12
quit
interface vlanif 12
ip address 192.168.12.2 24
quitip route-static 192.168.10.0 24 192.168.12.1
并且,此时我们直接测试 VLAN30/40 ,他们之间本来就是互通的:因为两个VLAN的网关都在SW3上。
@为了实现 VLAN10/20 与 VLAN30/40 之间互通,所以在SW2/3 之间添加一个VLAN 23(192.168.23.0/24)
SW2:
vlan 23
quit
interface vlanif 23
ip address 192.168.23.2 24
quit
SW3:
vlan 23
quit
interface vlanif 23
ip address 192.168.23.3 24
quit-------------------在网关设备上添加彼此的路由,实现每个VLAN互通----------
SW1:
ip route-static 192.168.30.0 24 192.168.12.2
ip route-static 192.168.40.0 24 192.168.12.2
SW2:
ip route-static 192.168.30.0 24 192.168.23.3
ip route-static 192.168.40.0 24 192.168.23.3
SW3:
ip route-static 192.168.10.0 24 192.168.23.2
ip route-static 192.168.20.0 24 192.168.23.2总结:
想要实现全网的所有的 VLAN 的互通,必须达到一个结果 - 网络收敛。
即:网络中的每个网关设备上,都得有整个网络中的所有的网段的路由条目。
注意: 【创建/添加 新的 VLAN 时,应该在所有交换机上操作。确保所有交换机的VLAN信息,一致】之前我们在 SW1/2 之间,添加另一个 VLAN 12 ;
之前我们在 SW2/3 之间,添加了一个 VLAN 23 ;
并且需要确保:同一个网段的两个IP地址互通(即下一跳IP必须通)。
但是,你在做实验的时候,作为同网段的2个IP地址,不一定互通!!!!!!