Function of Router
A router is a networking device that connects a local network to other local networks. At the Distribution Layer of the network, routers direct traffic and perform other functions critical to efficient network operation. Routers, like switches, are able to decode and read the messages that are sent to them. Unlike switches, which only decode (unencapsulate) the frame containing the MAC address information, routers decode the packet that is encapsulated within the frame.
The packet format contains the IP addresses of the destination and source hosts, as well as the message data being sent between them. The router reads the network portion of the destination IP address and uses it to find which one of the attached networks is the best way to forward the message to the destination.
Anytime the network portion of the IP addresses of the source and destination hosts do not match, a router must be used to forward the message. If a host located on network 1.1.1.0 needs to send a message to a host on network 5.5.5.0, the host will forward the message to the router. The router receives the message and unencapsulates it to read the destination IP address. It then determines where to forward the message. It re-encapsulates the packet back into a frame, and forwards the frame on to its destination.
How does the router determine what path to send the message to get to the destination network?
Each port, or interface, on a router connects to a different local network. Every router contains a table of all locally-connected networks and the interfaces that connect to them. These routing tables can also contain information about the routes, or paths, that the router uses to reach other remote networks that are not locally attached.
When a router receives a frame, it decodes the frame to get to the packet containing the destination IP address. It matches the address of the destination to all of the networks that are contained in the routing table. If the destination network address is in the table, the router encapsulates the packet in a new frame in order to send it out. It forwards the new frame out of the interface associated with the path, to the destination network. The process of forwarding the packets toward their destination network is called routing.
Router interfaces do not forward messages that are addressed to the broadcast MAC address. As a result, local network broadcasts are not sent across routers to other local networks.