Difference Between Layer 2 and Layer 3 Switches in Computer Networking System:
We will learn the various features and application of Switches at layer-2 and layer-3 of the OSI reference model.
We will explore the fundamental differences between the working method of layer-2 and layer-3 switches here.
The basic concept which branches out the way of working between both the types of switches is that the layer-2 switches dispose the data packet to a predefined switch port rooted on the MAC address of the destination host.
There is no routing algorithm followed by these types of switches. Whereas the Layer-3 Switches follow the routing algorithm, and the data packets are destined to the next defined hop and destination host is rooted on the defined IP address in the receiver's end.
We will also explore how these switches help the software testers situated miles apart in sending and receiving a software tool.
What You Will Learn:
From the above introduction about both the layer switches, an interesting question arises in our mind. If the switches at the layer-2 don’t follow any routing table then how they will learn the MAC address (unique address of a machine like 3C-95-09-9C-21-G2) of the next hop?
The answer is that it will do it by following the Address resolution Protocol known as ARP.
The working of this protocol is as follows:
We have taken the example of a Network where a switch is connected to four host devices known as PC1, PC2, PC3, and PC4. Now, PC1 wants to send a data packet to PC2 for the first time.
Although PC1 knows the IP address of PC2 as they are communicating for the first time, it doesn’t know the MAC (hardware) Address of the receipt host. Thus PC1 uses an ARP to discover the MAC address of PC2.
The switch sends the ARP request to all the ports excluding the port on which PC1 is connected to. PC2 when receives the ARP request, will then reply with an ARP response message with its MAC address. PC2 also gathers the MAC address of PC1.
Therefore, by the above to and fro flow of messages, the Switch learns which MAC addresses are assigned to which ports. Similarly, as PC2 sends its MAC address in the ARP response message, the switch now gathers the MAC address of PC2 and banks it into its MAC address table.
It also stores the MAC address of PC1 in the Address table as it was sent by PC1 to switch with the ARP request message. From now onwards, whenever PC1 Wants to send any data to PC2, the switch will simply look up in its table and forward it to the destination port of PC2.
Like this, the Switch will keep on maintaining the hardware address of each connecting hosts.
Collision and Broadcast Domain
Collision can occur in Layer-2 switching where two or more hosts are trying to communicate at the same interval of time on the same network link.
The network efficiency will get diminish here as the data frame will collide and we have to resend them. But every port in a switch generally lies in a dissimilar collision domain. The domain which is used to forward all type of broadcast messages is known as Broadcast domain.
All layer-2 devices inclusive of Switches appear in the identical broadcast domain.
To overcome the issue of collision and broadcast domain, the VLAN technique is introduced in the computer networking system.
Virtual Local area network commonly known as VLAN is a logical set of end devices lying in the identical group of the broadcast domain. VLAN configuration is done at the switch level by using different interfaces. Different switches can have different or same VLAN configuration and set up according to the need of a network.
The hosts connected to two or more different switches can be connected within the same VLAN even if they are not connected physically as VLAN behave as virtual LAN network. Therefore, hosts, that are connected with different switches can share the same broadcast domain.
For a better understanding of the use of VLAN, let's take the example of a sample network, where one is using VLAN and the other which is not using VLAN.
The below network topology is not using VLAN technique:
Without VLAN, the broadcast message sent from host 1 will reach to all the network components of the network.
But by using VLAN and configuring VLAN in both switches of the network by adding an interface card naming fast Ethernet 0 and fast Ethernet 1, generally notated as Fa0/0, in two different VLAN network, a broadcast message from Host 1 will deliver only to Host 2.
This happens while doing the configuration, and only Host 1 and host 2 are defined under the same set of VLAN while the other components are a member of some other VLAN network.
It is important to note here that layer-2 switches can allow hosts devices to reach the host of the same VLAN only. To reach the host device of some another network the Layer-3 switch or router is required.
VLAN networks are highly secured networks as due to its type of configuration any confidential document or file can be sent over two predefined hosts of the same VLAN which are not physically connected.
Broadcast traffic is also managed by this as the message will be transmitted and received only to the set of defined VLAN, and not to everyone on the network.
The diagram of a network using VLAN is shown below:
Access and Trunk Ports
Various types of configurations are done at Switch ports. In order to access a single VLAN network, we assign an access port to that VLAN.
Access ports are used when we need to simply configure only host end devices to a particular VLAN network.
To access more than one switches and different VLAN’s the interface has been assigned to Trunk port of the switch. The truck port is smart enough to bear the traffic of several VLAN’s.
- To configure VLAN on the switch, firstly enable the IOS mode in the switch.
- The command for creating VLAN is in the config mode VLAN NUMBER i.e. Switch(config)# VLAN 10.
- By using an interface command we can allocate the fast Ethernet port under VLAN.
- Now, by using the switchport access command line we can specify that the interface is an access mode.
- The next command will be allocating VLAN NUMBER to the switch port access mode.
The example of a series of command will be as follows:
Switch(config) #vlan 10 Switch(config-vlan) #exit Switch(config) #int fa0/1 Switch(config-if) #switchport mode access Switch(config-if) #switchport access vlan 10
From the above series of commands, it is clear that VLAN 10 is created and fa0/1 port of the switch is moved to VLAN 10.
- The switchport access mode command can be assigned to a single VLAN only. To configure multiple VLAN’s, switchport trunk mode interface command is used, as it can carry the traffic of multiple VLAN’s.
Features of Layer-2 Switches
Enlisted below are the various features of Layer-2 switches.
- Layer-2 Switch act as a network bridge that links up various end devices of a computer networking system on one single platform. They are able to transport data very rapidly and competently from the source to the destination end in LAN networks.
- Layer-2 switches perform the switching function to re-arrange the data frames from the source to a destination end by learning the MAC address of the destination node from the address table of the Switch.
- The MAC address table provisions the unique address of each device of layer-2, on the basis of which it can identify the end devices and the node on which the data is to be delivered.
- Layer-2 Switch splits a bulky complicated LAN network into small VLAN networks.
- By configuring multiple VLAN’s within a vast LAN network, the switching becomes faster as it is not being physically connected.
Applications of Layer-2 Switches
Given below are the various Applications of Layer-2 switches.
- Through Layer-2 switches, we can send data frame from the source to the destination that is situated in the same VLAN easily without being physically connected or being at the same location.
- Thus the servers of a software company can be put centrally at one location and the clients dispersed at the other locations can access the data easily without latency and thereby save the server cost and time.
- Organizations can make internal communications by configuring the hosts on the same VLAN by using these types of switches without the need of any internet connection.
- Software testers also use these switches for sharing their tool by keeping it centrally at one server location and the other server can access them by being far apart and not physically connected by configuring all on the same VLAN of the networking system.
The layer-2 switch fails when we need to transfer the data between different LAN or VLAN’s.
This is where the Layer-3 switches come in the picture as the technique they use for routing the data packets to the destination is using IP addresses and subnetting.
The layer-3 switches work at the 3rd Layer of the OSI reference model and perform the routing of data packets using IP addresses. They have faster-switching speed than the layer-2 switches.
They are even faster than the conventional routers as they perform the routing of data packets without using additional hops, thereby leading to better performance. Due to the functionality of this routing technique in the Layer-3 switches, they are implemented for network building of inter and intra networks.
In order to understand the functions of Layer-3 switches, we need to understand the concept of routing first.
The layer-3 device at the source end firstly looks at its routing table which has all the information regarding the source and destination IP addresses and subnet mask.
Later, based on the information that it gathers from the routing table it delivers the data packet to the destination and can pass along the data further between different LAN, MAN, and WAN networks. It follows the shortest and secure path to deliver data between the end devices. This is the overall concept of routing.
Various networks can be linked together by STM links which have very high bandwidths and DS3 links as well. The type of connectivity depends upon the various parameters of the network.
Features of Layer-3 Switches
The various features of Layer-3 switches are given below:
- It performs the static routing to transfer data between different VLAN’s. Whereas the layer-2 device can transfer data between the networks of the same VLAN only.
- It also performs dynamic routing in the same way in which a router performs. This dynamic routing technique allows the switch to execute optimal packet routing.
- It provides a set of multiple paths according to the real-time scenario of the network to deliver the data packets. Here, the switch can select the most feasible path for routing the data packet. The most popular routing techniques include RIP and OSPF.
- The switches have the capability to recognize the IP address related information that is heading towards the switch about the traffic.
- Switches have the capability to deploy QoS classifications depending upon subnetting or VLAN traffic tagging instead of configuring the switch port manually as in the case of layer-2 switches.
- They require more power to operate and tender higher bandwidths links between the switches which are almost more than 10Gbits.
- They provide highly secure paths for data exchange. Thereby, they are implemented in such instances where data security is a prime concern.
- The features associated with switches like 802.1x authentication, loopback detection, and ARP inspection make it efficient to use at instances where secure data transmission is essential.
Applications of Layer-3 Switches
Enlisted below are the Applications of Layer-3 Switches:
- It is widely used in data centers and vast campus like universities where there is a very big setup of computer networking. Owing to its features like static and dynamic routing and its fast switching speed than a router, it is used in LAN connectivity for interconnection of several VLAN and LAN networks.
- The layer-3 switch in combination with a number of layer-2 switches supports more users to connect on the network without the need for implementation of an extra layer-3 switch and more bandwidth. Thus it is widely implemented in universities and small-scale industries. In case if the number of end users on a network platform increases, then without any enhancement of the network, it can be accommodated in the same running scenario easily.
- Thus the layer-3 switch can easily deal with high bandwidth resources and end-user application as it is offering 10Gbits bandwidth.
- They have the skills to unburden the overloaded routers. This can be done by configuring a layer-3 switch, each with a main router in a wide area networking scenario so that the switch can manage all the local level VLAN routing.
- By following the above type of scenario the router working efficiency will improve and it can be used dedicatedly for long distance (WAN) connectivity and data transmission.
- A layer-3 switch is smart enough to handle and manage the routing and traffic controlling of locally connected servers and end devices utilizing its high bandwidth. Thus the firms generally use a L-3 switch to connect their monitoring servers and host nodes in any NOC centers of a sub-system which are part of a big computer networking system.
Inter-VLAN Routing at L-3 Switch
The below diagram shows the operation of the inter-VLAN routing with the layer-3 switch in combination with the L-2 switch.
Let’s go through it with the help of an Example:
In a university, the PC’s of faculties, staff, and students are connected via L-2 and L-3 switches on a different set of VLAN’s.
PC 1 of a faculty VLAN in a university wants to communicate with the PC 2 of some other VLAN of a staff member. As both end devices are of different VLAN, we need L-3 switch for routing the data from host 1 to host 2.
Firstly, with the help of the hardware part of the MAC address table, the L-2 switch will locate the destination host. Then, it will learn the destination address of the receipt host from the MAC table. After that, the layer-3 switch will perform the switching and routing part on the basis of IP address and subnet mask.
It will find out that PC1 wants to communicate with the destination PC of which of the VLAN networks present there. Once it gathers all the necessary information, it will establish the link between them and route the data to the receiver from the sender's end.
In this tutorial, we have explored the basic features and applications of layer-2 and layer-3 switches with the help of live examples and pictorial representation.
We learned that both types of switches have a couple of merits as well as demerits and according to the type of the network topologies, we deploy the type of switch in the network.