We often use the terms switches, routers, and gateways when discussing IP networks. However, do you really know what characterizes each, and the ways in which they differ?
When TCP/IP networks were new, there were typical classroom definitions. Switches, originally called bridges, operate at layer two, the Ethernet level. Routers operate at layer three, the IP level. Gateways operate using information from layers four through seven. Today, these definitions seem coarse and are only partly accurate. Further, each of the devices often shares attributes of switching, routing, and packet inspection. Despite this, we can give a somewhat accurate description of each type of device.
A switch operates primarily based on layer-two information, namely the mac addresses of devices that are on attached networks. The main purpose of a switch is to move an Ethernet frame in one port and out a second port without modifying the frame in any form. A more capable switch might support VLANs, which segment devices into groups. This is done so that packet flow between the groups can be controlled. This function is described as routing between the VLANs. As we’ll discuss later, this isn’t quite the same as the typical method used by routers. Devices interconnected by switches never have active duplicate paths between them. This would allow for loops.
A router primarily learns the locations of networks relative to its input and output ports. Then, its main function is to relay packets based on destination IP addresses in the packets. A key distinction between this routing and VLAN routing is how network addresses are learned. Routers typically uses a dynamic routing protocol that continuously shares updates about the network topology. Routers routinely allow for duplicate paths between networks. This provides redundancy. However, one path is always designated as the preferred path. In order to route between VLANs, switches are almost always manually configured with the necessary network addresses.
Finally, the term gateway loosely refers to a device that relays a packet based on almost any field in the packet. It might use mac or IP addresses, layer-four port numbers, or subfields of the headers such as the code bits in the TCP header.
If we think of latency as a measure of efficiency, switches are generally the most efficient because their function is simple. Routers have more to do with each packet. Besides a route table lookup, they must run an error check, modify the hop count, recalculate the error check code, and more. Finally, gateways are most often the least efficient as they might need to do a deep packet inspection that requires substantially more processing.
Using these terms accurately will facilitate descriptions of network problems and can aid in proper design, troubleshooting, and network management.