Types of network devices - Switches vs Routers vs L3 Switches
This is always a hot topic between network beginner what is difference between Switches, Routers & L3 Switches? Each device has different uses in different cases. While planing infrastructure you need to select the right device for the right purpose.
The Switch has multiple ports it comes with 8,16,24,48 and 52 ports in single U, You can have a modular switch if you want more ports or you can do switch stacking.
As L2 device it works on MAC address and Frame only. A switch doesn't understand the packet or IP address. It works on frame switching.
Used for the Same network
A switch is used for the same network infrastructure. Although we can use VLAN to divide it and use it for a different network, logically VLAN also divides you switch in multiple virtual switches.
Works on MAC Address
The Switch has a MAC address table which is used for frame switching, it maintains records of which MAC address is connected on which port. If a switch doesn't have the desired MAC address in its table then it uses multicast frame flooding to get it. For multicast switch have a golden rule, never send traffic on the same port from which you have received that traffic. This helps to reduce looping and frame flooding.
The above image is a MAC table of a switch. It has 4 Columns:
MAC Address: Mac address of a connected device.
Address Type: It is learned dynamic or is it a static entry.
VLAN: Vlan of that MAC address (Vlan 1 is default or also called native VLAN)
PORT No: Port number on which that MAC address is connected.
Also, the aging time of the MAC address table is mentioned, which means how long the switch will remember that MAC address if not data is received on that port.
A Router comes with 2-4 ports if you want more ports then you can use a modular which also comes with 2-4 ports.
A Router is an L3 device which uses IP address and packets for data transfer, it is a higher layer device of OSI then switch. Instead of a MAC address table, it uses a Routing table.
Works between 2 different Networks.
A Router is used for communication between 2 different networks, the Router has a routing table to identify where to send the packet. A Routing table is created with the help of different kinds of routing protocols. In most cases where you are using it as an edge router then we generally use static route or default route only. But at the core layer of routing, we use BGP or other routing protocols.
Typical routing tables have 3 columns
Network: Destination network, in the above example it is 0.0.0.0/0 which is also known as default network or all network.
AD: AD or also known as Administrative Distance is used to get a more reliable route.
Gateway: Next Hope or Gateway for that network.
Used for NAT
As router works on L3 it is also used for Network Address Translation (NAT) purpose to access the internet. With the help of NAT, we can translate private IP address to Public IP address.
It looks just like L2 Switch and has the same number of ports.
Packet Switching and Frame Switching
L3 Switch can do both Packet switching and frame switching.
Have both MAC Table and Routing Table
It has both the MAC table and the Routing table. But as L3 switches are not designed for core routing due to less processing power, so it can't use a higher or bigger routing table. If its about 100 or fewer routes it is good to use, but for more routes, it is suggested to use Router.
Can't Do NAT
L3 switches do work on L3 but can't do NAT. NAT requires high processing power.
Used for different networks of Local infrastructure
If you have different networks in your local infrastructure like for SMB infra or Collage infra and etc. then these devices are used.
Further, I have attached a video for a more detailed explanation.