A hub serves as a central point to which all of the hosts in a network connect to. It is an OSI layer 1 device. It receives a signal from one port and sends it out to all other ports. Sometimes it is called a multiport repeater (photo credit: Wikipedia)
Today, these devices are considered obsolete and switches are commonly used instead. Hubs have numerous disadvantages. They are not aware of the traffic that passes through them. They create only one large collision domain. A hub typically operates in half duplex. There is also a security issue with hubs since the traffic is forwarded to all ports (except the source port), which makes it possible to capture all traffic on a network with a network sniffer!
Like hubs, a switch is used to connect multiple hosts together, but it has many advantages over a hub. Switch is an OSI Layer 2 device, which means that it can inspect received traffic and make forwarding decisions. Each port on a switch is a separate collision domain and can run in a full duplex mode (photo credit: Wikipedia).
How switches work : Let's take a look at the following example:
Host A is trying to communicate with Host B and sends a packet. A packet arrives at the switch, which looks at the destination MAC address. The switch then searches that address in its MAC address table. If the MAC address is found, the switch then forwards the packet only to the port that connected to the frame's destination. If the MAC address is not found, the switch will flood the frame out all other ports. To learn which MAC address is associated with which port, switches examine the source MAC addresses of the receiving packet and store that MAC addresses in their MAC address table.
What is a MAC address table?
A MAC address table lists which MAC address is connected to which port. It is used by switches to make forwarding decisions. The table is populated by examining the source MAC address of the incoming packet. If the source MAC address of a packet is not present in the table, the switch adds an entry to it's MAC address table. The picture below show how a MAC address table on a switch looks like:
Difference between a switch and a bridge
A switch is sometimes called a multiport bridge, but there are differences between these two devices. A bridge usually has fewer ports than switch. A switch operates faster because it is hardware-based, which means that it uses chips (ASICs) when making forwarding decisions. In contrast, a bridge is software based. A switch can also have multiple spanning-tree instances while a bridge can have only one. Switches can also have multiple broadcast domains, one per VLAN.
A router is a device that routes packets from one network to another. A router is most commonly an OSI Layer 3 device. Routers divide broadcast domains and have traffic filtering capabilities.
The picture below shows a typical home router:
How routers work
A router uses IP addresses to figure out where to send packets. If two hosts from different networks want to communicate, they will need a router between them to route packets
For example, check the following scenario:
Host A and host B are on different networks. If host A wants to communicate with host B, it will have to send a packet to the router. The router receives the packet and checks the destination IP address. If the destination IP address is in the routing table, the router will forward the packet out the interface associated with that network.
What is a routing table?
A routing table lists a route for every network that a router can reach. It can be statically configured (using IOS commands) or dynamically learned (using a routing protocol). It is used by routers when deciding where to forward packets.
The picture below shows how a routing table looks like:
The command to display an IP routing table is show ip route. In the picture above, you can see that this router has two directly connected subnets. Let's take a closer look at the first entry in the routing table:
„C“ means that the route is a directly connected route. The network in question is 10.0.0.0/8, and the router will forward each packet destined for that network out interface FastEthernet0/1.
NOTE – in Windows, you can use the netstat –r command to display the routing table of your system.