A router is a device for connecting computer networks to one another, used for handling the routing of packets between two networks, or to determine the path that a data packet shall take.
When a user enters a URL, the Web client (the browser) queries the domain name server, which shows it the IP address of the desired machine.
The workstation sends the request to the nearest router, i.e. to the default gateway on the network it is located on. This router determines the next machine to which the data will be forwarded, in such a way as to choose the best pathway possible. To do so, the routers keep up-to-date routing tables, which are like maps showing the paths that can be taken to get to the destination address. There are numerous protocols designed to handle this process.
In addition to their routing function, routers are also used to manipulate data travelling in the form of datagrams so that they can go from one kind of network to another. As not all networks are able to handle the same size of data packets, routers are tasked with fragmenting packets so they can travel freely.
Physical design of routers
The first routers were simply computers with multiple network cards, with each one linked to a different network. Current routers are mostly hardware designed for routing, generally in the form of 1U servers.
A router has several network interfaces, with each one connected to a different network. Therefore, it has one IP address for every network it is connected to.
A wireless router is the same in principle as a traditional router, the difference being that it lets wireless devices (such as WiFi stations) connect to the networks which the router is connected to by wired connections (usually Ethernet).
There are two major types of routing protocols:
- Distance vector routers generate a routing table that calculates the "cost" (in terms of the number of hops) of each route, then sends that table to nearby routers. Each time a connection request is made, the router chooses the least costly route.
- Link state routers listen to the network continuously, in order to identify the various elements surrounding it. With this information, each router calculates the shortest pathway (in terms of time) to each neighboring router, and sends this information in the form of update packets. Finally, each router builds its own routing table by calculating the shortest pathways to all other routers (using the Dijkstra algorithm).