In Switching technology, basically there are two concepts working-. Layer-2 vs Layer-3 Switching. Switching is very much important in IT network. Its required to communicate within network and used in Small, Medium and Large, Home, Office big Organisation and Data Centre. Switching is part of LAN ( Local Area Network). We will understand How Layer-2 Switching works and how it communicate within VLAN. Also we will understand the difference between Layer-2 and Layer-3 Switching.
What is a layer 2 switching?
Layer-2 devices build hardware address tables, which will contain the following at a minimum:
- Hardware addresses for host devices
- The port each hardware address is associated with
- In OSI Layer, L-2 Switch works layer-2 called Data Layer.
- Ethernet switches build MAC-address tables through a dynamic learning process.
- Hardware address learning
- Intelligent forwarding of frames
- Loop avoidance
How Layer-2 Switching Works?
When we create a network, then there is hierarchical network architecture, where we have Router, Firewall, Core Switch, Distribution Switch and Access Switch.
If we talk about Layer-2 switch, then Layer-2 switch used at Access Layer only, because this Layer is only used for connecting End-Devices, laptops etc. and at this Layer, switch no need to bother about Routing decision, inter-Vlan communication, gateways etc. its only works based on Vlan and forwards the frame to their default Gateways for further decision.
Let’s understand with Scenario and Examples:
In Above topology, there are two Layer-2 switch, SW-1 and SW-2
On these Layer-2 switches we will try to perform below activity and will see the result, what happens
- Create Layer-2 VLANs
- Assign Port in VLAN
- Configure Trunk
- Give IP Address to Laptop (Per VLAN IP address with Different Subnet & Same VLAN)
- Ping Different VLAN Laptop IP address from laptop
Switch config Sample:
Switch-1# sh running-config
Building configuration…
Current configuration: 1236 bytes
!
version 12.2
no service timestamps log datetime msec
no service timestamps debug datetime msec
no service password-encryption
!
hostname Switch-1
spanning-tree mode pvst
!
interface FastEthernet0/1
switchport access vlan 10
switchport mode access
!
interface FastEthernet0/2
switchport access vlan 20
switchport mode access
!
interface FastEthernet0/3
switchport mode trunk
!
interface Vlan10
no ip address
!
interface Vlan20
no ip address
Config Output
Above Switch configuration is Sample config for all Switches.
In above snap shots, we have configured all Laptop with IP address as per their VLAN
In above output we can see that, if we try to ping 20.1.1.4 from 10.1.1.4 its not Pinging, because 20.x.x.x laptop is in different Subnet, but if we ping 10.1.1.5 on another Laptop its pinging as these both Laptops are in same subnet. Although these laptops are connected on different Switches, but both are pingable as both Switches Fa0/3 are configured as Trunk and all Vlans are allowed over this trunk port.
Same thing happening in above laptops as well.
So, based on above testing below is summary:
- We can create Layer-2 Vlan on L2 Switch
- We can configure Trunk Port between two different L2 Switches to travel all Vlan
- Same VLAN and Subnet IP address is pingable
- We cannot ping different subnet devices because to communicate two different subnet or VLAN need inter-Vlan communication with L3 routing feature which L2 switch doesn’t have.
- Layer-2 switch works on OSI layer-1 (Physical) & Layer-2 (Data link Layer) only not on Layer-3.
Difference between layer-2 and Layer-3 Switching
Criteria | Layer 2 switches | Layer 3 switches |
Initial set-up and configuration | Easy to setup, configuration, manage and troubleshoot | Require advanced configurations and Skill set to manage |
Routing capability | Can not capable to perform Inter-VLAN communication. | Can do Routing and Inter-Vlan Communication |
Scalability | Limited scalability. | Higher scalability |
Data transfer speed | High-speed data transfer within network segments. | High-speed data transfer between different network segments. |
Security | Not configure much security, need to go with default | Can configure ACL, Policies, QoS and other Security Parameters |
VLAN IP configuration | Can not give IP to all Vlan, only L2 Vlan can create | Can configure Layer-3 VLAN and can give IP address to Vlan |
Using Topology | Using at Access Layer | Can use at Distribution and Core Layer |
OSI Layer support | At Data Link layer | Worked at both Data Link and Network Layer |
Required for | Required to connect End Device, Laptop, IP Phone, Camera etc | Mostly using for connect Services like WLC, Servers etc, but can use to connect some end device as well |
HA support | Can not provide HA at end user level | Can provide Hardware level and Link level Redundancy for Access Switches |
To read more on how Layer-2 works, please read- https://techblog.kbrosistechnologies.com/best-guide-4-how-switch-works/
Visit to our site : https://www.kbrosistechnologies.com/
Watch more Video https://www.youtube.com/channel/UCpcd6IshE1caAbf9EdJd3gw
https://www.youtube.com/channel/UCTbOmLTSlHggEBkt5wFGNRA
FAQ
Q: What is Layer-2 switching?
A: It is used for forward Ethernet frames based on MAC addresses and it is worked on Data Link layer. Also it used to communicate within same subnet or Vlan.
Q: What is Layer-3 switching?
A: It has capability to do Layer-2 switching and Layer-3 routing and can perform inter-Vlan or inter-Subnet network communication.
Q: What are the key differences between Layer-2 and Layer-3 switching?
A: Layer-2 switching operates at the data link layer and forwards frames based on MAC addresses
Layer-3 switching operates at the network layer and routes packets based on IP addresses.
Layer-2 Switching only communicate within same Vlan or subnet and can not do Inter-Vlan communication
Layer-3 switching provides inter-network communication.
Q: When should I use Layer-2 switching?
A: Layer-2 switching is suitable for local network environments where there is no need for routing between subnets.
Q: When should I use Layer-3 switching?
A: Layer-3 switching is beneficial when there is a need for routing between different subnets or networks.
Q: Can Layer-3 switches perform as Layer-2 switching?
A: Yes, we can use as Layer-2 Switching, but it is not a good solution, because Layer-3 switch is very expensive and have capability to do routing, so it will not recommend to use Layer-2.
Q. Can a Layer-3 switch have all Gigabit Port?
A. Yes, a Layer-3 will be come with all Gig Port.
Q. Do we need High Availability on Access Layer?
A. No, we no do required High Availability on Access Layer for End user, but High- Availability is required between Access Layer and Distribution Layer in terms of Link Layer and Hardware Layer.