# Networking – Why is a router needed

dhcphubnetworkingrouterswitch

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.)