Although VLAN is used to split the broadcast domain, it is necessary to enable communication between two or more VLANs at layer 3 using IP routing. This is called InterVLAN routing and can be configured using both routers and layer 3 switches. This requires allocating a different IP subnet for devices in each VLAN.
We will configure InterVLAN routing by connecting the router to a switch using a single link. All the traffic to other VLANs passes through this link, to the router and back again through this link. This method of configuration is also called router-on-a-stick, as a single link to the router handles all traffic.
We will use the following topology for this setup:

As stated earlier, each VLAN will have IP addresses from different network ranges and the router's interface will have three IP addresses—each belonging to a different network.
Sw1(config)#int range f0/2-3 Sw1(config-if-range)#switchport access vlan 10 Sw1(config-if-range)#int range f0/4-5 Sw1(config-if-range)#switchport access vlan 20 Sw1(config-if-range)#int range f0/6-7 Sw1(config-if-range)#switchport access vlan 30
Sw1(config)#int f0/1 Sw1(config-if)#switchport mode trunk
R1(config)#int f0/0 R1(config-if)#no shutdown
R1(config-subif)#int f0/0.10 R1(config-subif)#encapsulation dot1Q 10 R1(config-subif)#ip address 10.10.0.1 255.255.255.0 R1(config-subif)#int f0/0.20 R1(config-subif)#encapsulation dot1Q 20 R1(config-subif)#ip address 10.20.0.1 255.255.255.0 R1(config-subif)#int f0/0.30 R1(config-subif)#encapsulation dot1Q 30 R1(config-subif)#ip address 10.30.0.1 255.255.255.0
encapsulation command here. It specifies the VLAN ID the interface will handle.The only layer 3 switch present on Packet Tracer is 3560-24PS. We will use the same topology by replacing only the router with the layer 3 switch, as shown in the following screenshot:

Creation and configuration of VLANs is the same on the layer 2 switch, hence it won't be repeated here. So, we'll move to the layer 3 switch straightaway.
switchport mode trunk command, the same port on the layer 3 switch will also be in trunking mode. This can be verified as follows:
MSw1#sh interface trunk

The trunking status indicates this. More on how this port automatically moved to trunk will be discussed in the next section (Switch-to-switch trunk links).
MSw1(config)#int vlan 10 MSw1(config-if)#ip add 10.10.0.1 255.255.255.0 MSw1(config-if)#int vlan 20 MSw1(config-if)#ip add 10.20.0.1 255.255.255.0 MSw1(config-if)#int vlan 30 MSw1(config-if)#ip add 10.30.0.1 255.255.255.0
10, 20, and 30. So we'll create them as follows:MSw1(config)#vlan 10 MSw1(config-vlan)#vlan 20 MSw1(config-vlan)#vlan 30
MSw1(config)#ip routing
Here, too, the first packet will always time out as the ARP process takes some time.