L3SW:
int Vlan2
ip address 192.168.2.254 255.255.255.0
int Vlan3
ip address 192.168.3.254 255.255.255.0
int F0/1
switchport access vlan 3
switchport mode access
int F0/2
switchport access vlan 2
switchport mode access
int F0/3
switchport access vlan 2
switchport mode access
int F0/4
switchport access vlan 3
switchport mode access
配到这里,PC21和PC22可以通信,PC31和PC32可以通信,但是VLAN之间不能通信。
L3SW(config-if)#do sh ip route
Default gateway is not set
Host Gateway Last Use Total Uses Interface
ICMP redirect cache is empty
此时在三层交换机上看不到路由。
L3SW(config-if)#ip routing ##开启路由功能
L3SW(config)#do sh ip route
C 192.168.2.0/24 is directly connected, Vlan2
C 192.168.3.0/24 is directly connected, Vlan3
ip routing开启以后,VLAN间可以互相通信。
再引入另外一个场景,比如公司电脑很多,需要多台2层交换机参与工作的情况:
L2SW1#sh run
int F0/1
switchport mode trunk
int F0/2
switchport access vlan 2
switchport mode access
int F0/3
switchport access vlan 3
switchport mode access
L3SW#sh run
ip routing ##灵魂
interface Vlan2
ip address 192.168.2.254 255.255.255.0
interface Vlan3
ip address 192.168.3.254 255.255.255.0
L3SW#sh ip route
C 192.168.2.0/24 is directly connected, Vlan2
C 192.168.3.0/24 is directly connected, Vlan3