In this video, learn how routers work to get packets from one network to another.
- Now I've got myself a little network right here running TCP/IP. I've got four computers, all connected to this switch. Now because it's TCP/IP, I had to give all of these computers, because they're on the same broadcast domain, a network ID, in this particular case it's 232.25.201, WAC 24. So all of the computers on this network, I could have up to 256 hosts, are gonna have to start with 232.25.201.
Now that's fantastic. But what if I wanna connect to other networks? What if there is another set of computers on the other side of the hall, or the other side of the world, and it has its own network ID and we wanna interconnect to it. Well, in order to do that, maybe if we had really long cables, but what we need to do is use a very special device called a router. A router is nothing more than a box that is designed to interconnect network IDs. Routers filter and forward based on IP address.
Remember, switches filter and forward based on MAC address, but routers filter and forward based on IP address. Now we've all seen routers. You've probably got something like this sitting around in your house, and just most of us do. Now the problem with these, we call these routers, and that's just a term I have to get used to. Most of these devices are routers, but they're also built-in switches, and built-in wireless access points, and built-in all kinds of other stuff. Now if you really wanna see a router, now this is a router.
Now this, this is an old, old router, but I love it so much. This is an old Cisco 2811. Routers can have lots and lots of connections on them. In order for a router to function, it's gonna have to have at least two connections. Remember what a router does, it interconnects network IDs. It basically interconnects between the two different network IDs, but it can have more than that. So to understand how routers really work, the best thing we can do right now is head over to my cool little pseudo-router place and let's do a little diagram.
Let's pretend for a moment that this little box here is a router. Now this router's gonna have two connections, so let me put two connections in here. In this case, we'll say they're ethernet, although routers really don't care. But we'll say I've got two ethernet connections. Now, this one right here is connected to the 192.168.15 network, and this one here is connected to the 232.25.201 network. So let me show you how that looks. So on one side here we've got the 192.168.15 network, so everything in here is gonna be 192.168.15 something, everybody's plugged into this switch.
On the other side, we have the 232.25.201 network. Everybody's gonna have a 232.25.201, and everybody's plugged into their switch. To interconnect these, what we do is we put a router in between them, and we run a cable from one port on the router, to each of the switches on the different network IDs. Now in order to make these guys part of these networks, these guys have to have IP addresses. So in this case we'll say this one is gonna be 192.168.15.1.
And here we'll say this connection's gonna be 184.108.40.206. Every router has some way for you to give these ports an IP address. So for example on a home router, here you can see where I'm just typing in an IP address. On a more advanced router, it can be a bit hairier. And while all these commands look strange, trust me, I'm giving one of the ports an IP address. So let's watch routing in action. So here comes a packet.
So this packet's coming in, it's heading over to 192.168.15.30, but it's from the 220.127.116.11. Now first of all you'll notice that all the ethernet stuff has been stripped away. Routers don't care about ethernet. Any way it comes in, it just strips it away. The second thing that routers don't care about is what port anything comes in. All it does is it reads this first piece of information. That first piece of information says it needs to go to 192.168.15.30, but how does he know how to get there? It knows because built into every router is what we call a routing table.
Now, let's look at this one up close so we can really see it. Now when we talk about a routing table, we're gonna have at least four columns. The first one, the address, says, now you'll look in this particular case, on the first line it says 192.168.15.0. That's 0, and that's why you can't have 0 in an IP address 'cause it's used by routers. It's identifying anything that says that is 192.168.15 network, with a WAC 24 subnet. Now those four zeroes in the gateway, that means this router is directly connected to that network.
Send it out on interface whatever that might be. So if we take a look at this particular example here, now, and we read that first line, it's gonna say anything for the 192.168.15 network on a WAC 24 subnet, you're directly connected, send it out this interface. Now the second one right here just has to do with pointing stuff this direction. So if anything's for the 232.25.201 network on a WAC 24, all zeroes means you're directly connected to that network, send it out on that interface.
So that's the most basic routing table. All routers have routing tables, and for most routers, the basic routing table is configured automatically. When you type an IP address into one of the ports on the router, it will assume that it has that route. So these things pretty much generate auto-magically for us. There's some exceptions to that, we'll get into that in other episodes. Now the example I just showed you is great except for one big problem, and that is there's a lot more than just two network IDs in the universe. So if there were only two network IDs, life would be great.
But the internet itself is composed of probably tens of millions of network IDs, and you never know who wants to connect to what. So we have to come up with a mechanism that allows our router to connect upstream, in essence, into the cloud if necessary. And that's actually fairly easy to do. What we do is that we have built into every router something called a default route. Now to watch how default routes work, what I wanna do is take the analogy we made a moment ago, and let's stretch it out a bit.
So here's our two network IDs, but let's change this a little bit. First of all, we're gonna go ahead and keep our 192.168.15 network, that's gonna be our local network here at the office, or here at home, or whatever it might be. But we're going to change the 232.25.201 network. What that's going to be now is actually coming from our internet service provider. So our internet service provider has what we would call an upstream router. And his address, 'cause he's part of that network ID also, is gonna be 18.104.22.168.
So we're .1, but maybe the customer next door is .2, and another customer is .3, and somebody else is .100. So this entire 232.25.201 network doesn't have any computers on it at all, it's just a bunch of routers. And that's what makes the internet beautiful. Now, what's interesting to us is how do we know that the upstream router's IP address is 22.214.171.124? Almost every router in existence has some methodology for you to go in, and query what its upstream router is, or sometimes called the default gateway.
So here's an example right here on my little home router. So to take advantage of this default route, we're going to update the routing table. So now it's gonna look something like this. So what we have now is a default route. The default route basically means if it doesn't meet any other criteria, if it doesn't know where to send it, always send it here. Default routes are really obvious. It's always gonna start with an address of all zeroes which means I don't care what the address is. All zeroes for the subnet, I don't care what the subnet is. Send it out on this interface, but send it directly to the next gateway up, 126.96.36.199.
Now you gotta be careful about this because a lot of people get confused the first time you see a default route. In particular, it seems that we have 188.8.131.52 be in an interface for two different things. Let's go ahead and get the routing table up here on the screen. So if you look, and actually there are two different routes where we send it out 184.108.40.206. Let's make sure you understand the difference, this is important. So for example, if I get a packet that needs to go to 220.127.116.11, say.
What's gonna happen is the router's gonna look at that routing table, and because it sees that the gateway is all zeroes, that tells the router that it is directly connected to 18.104.22.168. So your router knows, because the gateway is zero, it can ARP that system. So your router will go out on interface 22.214.171.124, and say hey, 126.96.36.199, what's your MAC address? He ARPs him, that device responds back, the router can now put on the ethernet information and shoots it out 188.8.131.52, and that computer gets the packet.
However, let's change it up a little bit. Let's say that your router gets a packet for 184.108.40.206. Now, obviously the only route that's gonna work in this case is the default route, so what your router does is that it goes ahead, the address all zeroes, doesn't care what the address is, subnet, all zeroes, doesn't care what the subnet is. However, things change a little bit here. Yes it will send that packet out on 220.127.116.11, but what it's gonna do is it's going to ARP the gateway. So it's gonna send out an ARP to 18.104.22.168 'cause that's what's in the routing table and it'll say hey, what's your MAC address? That upstream router's gonna respond, sends him his MAC address, now it knows how to send it, and it shoots it up to the router.
Isn't that absolutely cool? So many people get blown away by routers because they think of routers as doing all these changes, routers really almost never change the IP packet. Well there's a few exceptions where they do, but in general, the only thing routers do is read the destination IP address, and then they change the MAC address depending on where they wanna send it to, pretty cool huh? Well, there's one problem here. And the problem is is that the router I've shown you so far only has two connections.
We have one that's to our local area network, and then one that's upstream to our ISP. You see this a lot on these home routers, and in fact they'll call it like a LAN address, and a WAN address. But routers are a lot more than that. When you only have two connections, that router isn't really routing, it's just acting kinda like a gateway, as an entryway for you to get to the internet. In fact, we tend to call these types of routers gateway routers for that reason. But they can do a lot more. In my office, we have a much more industrial router, and my router has three connections.
The reason it has three connections is because I have two ISPs. I have one ISP that goes through my commercial cable account, and then I have another ISP that uses DSL. The reason I do that is because I don't wanna ever go out, and if one goes down, I automatically want to be able to use the other. And this is where routers really really get powerful. In order to show you all this coolness, let's first of all do a quick diagram. So let's add to our diagram. Now we still have our 192.168.15 network, that's our local area network.
But we're gonna say the 232.25.201 is our commercial cable connection. And now we're going to add a third connection, in this case, it's going to be 75.29.6 network, and that's gonna be my DSL connection. So we're gonna have to do a few things. First of all, we're still gonna have to give that third interface an IP address, and we're gonna go ahead and give it 22.214.171.124. And it's connected upstream to 126.96.36.199.
So let's see how all this works on our router. So to make this work, the first thing we're gonna have to do is add this third connection. And on more advanced routers, it's really easy to buy an extra ethernet connection, you just screw it in. Now to make this work in terms of a routing table, it's gonna have to look something like this. Now first of all, you'll see that I got my 75.29.6. So just as a reminder, this is my local area network connection, this is my connection to my commercial cable, and this is my connection to my commercial DSL.
So I've got a local connection in here for the 75.29.6, everything's great there. But you'll notice what I've done here is I have in essence, two default routes. So how does my computer know if I've got two default routes, which one am I going to use? And that's where this comes into play, what we call the metric. The metric is a relative value that gives your router an idea. If it has more than one choice to do something, which way does it go? Now I prefer to use my commercial cable connection 'cause it's faster than my DSL.
So you'll notice that I've given that a lower metric value than my DSL. If my router has something to send out on the default route, it's gonna use this one first. However if this connection goes down or something like that, then he can go ahead and auto-magically switch over to the secondary default route, and he uses that metric to make that decision. Now this is just the basics of routing, we're gonna be going into a lot more routing in other episodes. But at this point, what I'm trying to do is get you started on the concept of what routing does for us.
Just to wrap a few things up though, I wanna make sure you understand this. Number one, routers don't care where a packet came from, only where it's going. The other thing I want you to remember is that routers are not tied to ethernet. Now in these examples I've said we had two or three ethernet connections, but for a router, it can have a DSL connection, it can have a DOCSIS connection, it can have optical, it can have all kinds of different connections, and it simply doesn't care. And the reason it doesn't care is because routers only care about the IP packet.
And in most cases, that IP packet never changes.
- Dynamic and static IP addressing
- Rogue DHCP servers
- Network Address Translation (NAT)
- Forwarding ports
- Dynamic and static routing
- Routing protocols: RIP, OSPF, and BGP