Why is a router needed?
I‘ve been trying to figure out why a router is needed. I know a router can be used for DHCP and some other things, but I’m just thinking of networking with static IPs. So the following:
Is it possible to do the following with static IPs:
Modem -> Switch -> PCs
Or do you need to go:
Modem -> Router -> Switch -> PCs
So what exactly does a router do and why is it needed?
I think generally routers serve as an access point, DHCP, firewall and switch as an easy solution for people who don't know much about networking
No, routers are a separate kind of device from APs and switches. "Router" is not just a generic name – it describes a specific function, routing IP packets between networks.
In other words, you're describing a router + switch + AP combination, which might be better called a "SOHO (Small Office/Home Office) router" or a "home gateway".
(However, many dedicated routers do have an integrated firewall and sometimes even a DHCP server.)
I'd like to know why routers are needed generally
IP routing is needed because pure Ethernet-level switching wouldn't scale well.
Ethernet device addresses are assigned by the manufacturer – there's no useful structure in them; they're random as far as the network is concerned. So an Ethernet switch only has two choices: keep a list of every single device connected to every port (as modern switches do), or simply broadcast every packet to every port (as in the original Ethernet).
Both methods work well only up to a certain network size, but if there are more devices than a switch can remember, the network will quickly melt down. (Related topics: CAM exhaustion)
Thus, similar to zipcodes or phone numbering, IP gives the network a structure – each network, sub-network, super-network is assigned a chunk of addresses, and you can describe routes such as "addresses starting with [10.7.x.x] can be reached via [port 3]". Now the rest of the world doesn't need to know about millions of Comcast customers, it only needs a few routes towards Comcast itself.
IP routers hold the knowledge of these routes, and forward all packets accordingly.
(This separation between Ethernet and IP is actually useful because it gives flexibility – the same Ethernet can carry several different protocols, such as IPv4, IPv6, perhaps IPX... Some other protocols did not have such separation, such as DECnet or NetBIOS, and they couldn't survive the network growth.)
Is it possible to go: Modem -> Switch -> PCs with static IPs
Sure, technically it's possible. Static IPs aren't even required.
Indeed, at an ISP next to my workplace, some 20 business customers around the city actually don't have their own routers – their 'external' switches are connected directly to a single router in the ISP's building (which even serves DHCP to all of them), just as you describe.
But there are reasons why it's not usually done this way. (Admittedly, a few of them come from the shortage of IPv4 addresses – such as NAT. But many would still be important even in a pure-IPv6 world.)
-
As it is right now, the ISP routes a single "global" IP address towards your network. So, certainly, you can connect your PC directly to the modem, and configure it with your "global" address. (Chances are, it would even autoconfigure that via DHCP.)
Indeed, this used to be a very common configuration here until late 2000's. Most home customers only had one computer, and that computer would often talk directly through the modem to the ISP's routers – first using an actual dial-up modem, later an ADSL one.
But every device needs its own address. Since you only get one IPv4 address from your ISP, you can directly connect one computer, but not two – unless you pay extra for the second address.
That's why your home router has a "network address translation" function (aka NAT) which gives you a block of "private" 192.168.x addresses and hides them behind a single "global" one.
(CGNAT is also worth mentioning, but research is left to the reader.)
-
Alongside NAT, your "router" also has other functions like a firewall, a DHCP server, a DNS cache. Yes, those all could be done by the ISP's routers, but it would cost the ISP a fair bit and it would inconvenience all customers, without giving any advantages to any of them.
The firewall would have to be configured via your ISP's provided interface, and most ISPs would only provide the bare minimum of options. (When configuring my own router I have full control – I can apply firewall rules to uncommon protocols; I can create multiple subnets; I can experiment with IPv6 tunnels or RIP or OSPF...)
Both the firewall and NAT need resources for tracking connections – some amount of memory, some CPU power. Currently these resources are spread out, since your router only has to track your own connections. But if everything was done by the ISP, their routers would need as much memory & CPU as all customers' routers together, which is expensive.
The DHCP server works much better when it's on your side. Even if the Internet cable is cut, your own devices can still get IP addresses and communicate locally. (Yes, yes, static addresses are possible, but believe me, they're a pain in the ass to keep track of.)
The DNS cache works because it's at your home. Your ISP has its own DNS cache anyway, but your router still has its own small cache, simply because it's closer to you, serves fewer devices, and therefore can answer much faster. (Slow DNS is very noticeable.)
So the reasons for having your own home router are, 1) it's faster, 2) it's cheaper, 3) it's simpler for both you and the ISP.
(The ISP I described earlier? I don't know why they do that. Perhaps it's different when you have only a dozen customers, than when you have many thousands.)
A home modem usually only gives you one IP address. The router does NAPT (Network Address Port Translation), allowing you to have multiple private IP addresses on your network.
If your ISP gives you multiple IP addresses, you could possibly go without a router on your side.
At your home you likely have only one path to take to reach the Internet, out through a device provided by your Internet Service Provider (ISP). The ISP needs a router at the other end of its connection to you, though, which can decide where data from your system goes next. Does it need to go to one of the ISP's web servers, one of its other customer's systems, or does it need to go to a Google or Microsoft server, or does your destination IP address point to a system in Norway, etc. The ISP will have routers that have multiple connections coming into them. It could have a router with a circuit that connects to a network in Europe, one that connects to a network in South America, etc. And at the other end of those circuits are other routers likely with multiple connections of their own. So how does your ISP's router know which router it should forward your data to? It has a routing table that tells it which other router is the next "hop" to which it should send your data. It won't know all of the intervening routers from your system to the destination address, since it doesn't know the full path from your system to the destination system, just which one is the best choice to move your data further along the path to its destination. The next router will look in its own routing table to decide where it should send your data. It could, conceivably, send your data out any of several connections it has; it will decide on which one to use based on a "routing metric". The connection with the lowest routing metric will be chosen. But if that connection goes down or becomes congested, it can pick the next best connection based on its routing metrics. Your ISP's routers don't need to be in communication at all times with every other router in the Internet, they just need to know what is the next best network "hop" at the time your data is received; it can rely on that next router to make similar decisions and all the other routers in the path to do likewise.
By use of routing tables to pick the next hop, if your data might normally go through a router in France to reach a destination in Norway, even if there was no longer a path through France, some other router along the way that connected to the router in France would be aware of the outage and reroute your data through another path, e.g., perhaps through Germany. The Internet is an outgrowth of ARPANET; one of the requirements for ARPANet was that it be resilient and able to tolerate the failure of particular pieces of equipment in the network by routing around the failed equipment. In the days of ARPANET, the precursors of today's routers was called an Interface Message Processor (IMP).
In regards to your home network, it would be possible to have a direct connection from a device at your home that isn't a router. If you were using the Internet back in the days of dial-up modems you wouldn't have been using a router at home. Your computer would have, instead, dialed into a device belonging to the ISP. Some business and organizations still use ISDN, which operates in a similar fashion to the old dial-up modems, though they might have an ISDN router, if they have multiple systems that need to share the ISDN connection.
And even in the days when dial-up networking was the method used by almost all home users and small businesses to access the Internet, if a home user or small business had a limited number of phone lines, but needed Internet access for multiple computers, a solution that was available was to configure one PC that had a dial-up modem to function as a router for all the other computers on the local area network at the home or business. I remember installing a router that had a 56 Kbs modem in it to provide dial-up access to the Internet for several computers at a small business.
Today, people expect to be able to have both wired and wireless connections at their home that can all connect to the ISP simultaneously and, since Internet Protocol version 4 (IPv4) addresses are limited, most home users get but one public IP address, so need a device that can perform network address translation between that one public IP address and the multiple private IP addresses they will be using for their own systems. And they want to be able to control who has access from the outside into their internal systems. For that you will need your router or a firewall; most home routers have at least some limited firewall capabilities built into them.
Technically, the ISP might be able to handle the function for you, but that approach wouldn't scale well for thousands or perhaps even millions of customers. E.g., if you have your own router, you can use the private IP address 192.168.0.5 for one of your systems and so can a thousand of the ISP's other customers. The ISP doesn't have to ensure that when private IP address space is used that different customers don't pick the same addresses. The ISP's equipment external to your home only needs to concern itself with the one IP address you were provided by the ISP. And if you want to allow inbound connectivity on port 5000 to one of your systems, you can manage that yourself; you don't have to call the ISP's tech support department, which would put an additional burden on the ISP's support staff.
I suppose you don't need it
You can take a modem and plug a switch in and use the public IP the ISP provides.
Or you can take a router-modem and turn off the router by putting it in bridge mode(a bridge is basically switch but with some weird arbitrary distinctions people sometimes make*), and use the public IP from your ISP
Outside your home they have to use Routers, because switches don't deal with a hierarchical addressing system like IPs. A decide like a switch that can only deal with a flat addressing scheme, is too slow for a large number of devices.
Like consider if everybody in the world had a unique number, but the numbers weren't grouped together, you'd have to look up the person's whole number in the list, in order to find out which hole/socket/port/direction/angle to send the data out to. Whereas if you could see straight away they're in Tokyo / their IP address starts with blah blah blah, and everybody in Tokyo/with IP address starting with blah blah blah, has data sent out this hole/socket/port/direction/angle then it's quicker to get it to them.
But back to your personal case, your home.
You don't need DHCP server on your device because the IP can come from the ISP(via DHCP). So a switch is fine for that.
You don't need NAPT if you have only one device. A plain old switch is fine.
It's not necessarily as secure(unless you secure it yourself), and you can only connect one device if the ISP doesn't give you multiple IPs. But you can do it / it can be done.
A point re terminology. The device you call a router, is a box. It does functions. Routing, DHCP,NAPT some have a modem too. You can turn off DHCP and NAT on a box and do plain routing. And the box also has a switch built into it. You can hence put it in bridge mode, turning off the router.
-* functionally a bridge is a switch.. a few distinction people make sometimes is a switch should have multiple ports.. a bridge is for when the networks are on different mediums. maybe some say the chips in a switch are a faster design. But functionally they do switching/bridging(same thing), use a MAC address table(or perhaps some other "layer 2" protocol), and MAC addresses are a flat address scheme, probably anything at "layer 2" is.