Welcome to Chris Sutton’s networking tutorial.
The first thing we need to talk about are IP Addresses. Every computer on the internet needs an IP Address. They look like this 10.4.2.2. Basically 4 numbers separated by periods. Can these be any numbers you ask, like 1235.6789.98234.123556? Nope. The numbers must be from 0 to 254. So you can have something like 18.104.22.168.
Generally each computer needs a unique IP Address. Think of it like a phone number. If we want to talk to that computer, we need to know how to dial it up.
The next thing we need to learn about are Subnet Masks. Here is an example: 255.255.255.0. Wow, that looks a whole lot like an IP address. Yes, it does and it works with an IP Address to help define the size of the local network a computer belongs to. When your computer is assigned an IP address, it also must be assigned a Subnet Mask.
Lets go back to our first example of IP address 10.4.2.2 with a subnet mask of 255.255.255.0. The 255’s in the subnet basically block out the first 3 numbers and say “dont worry about these for now”, and the 0 says don’t block out any of the last number.
Now, remember when we said each part of an IP address can be from 0 to 254. The last part of the subnet mask says that this computer is on a local network that can talk to all the IP addresses from 10.4.2.0 to 10.4.2.254.
So if your computer was 10.4.2.2 and my computer was 10.4.2.3 and we both had a subnet mask of 255.255.255.0 then we would be able to talk to each other.
Now, lets bring in Sam’s computer, which has an address of 10.4.0.3 and subnet mask of 255.255.255.0. Can we talk to Sam? Nope, because our subnet mask is blocking him out. We can only talk to those people in the 10.4.2.(0-254) network, not someone on the 10.4.0.(0.254) network.
So, how do we talk to Sam? We need a gateway (actually default gateway)! And this is the last piece you need for a network configuration, someplace to go when you need to travel outside your local network of 254 friends. For our example our default gateway is going to be 10.4.2.1 (which luckily is in our network that we can talk to, otherwise we would have big problems). This default gateway is actually just another computer, and for simplicity lets call this Arla.
Now, some computers can have more than one network interface. Think of it like 2 phone jacks. And each network interface must have it’s own settings.
So, we already know the network settings for our first interface (which we will call eth0), 10.4.2.1/255.255.255.0. Now, the other network interface (called eth1) is on Sam’s network and has an address of 10.4.0.2/255.255.255.0.
With me so far…ya, coffee break time, and time for a sidebar.
Can you just make up and use an old IP Address you want? Generally no, you need to talk to your ISP, and they can give you an address, or a block of addresses to use. But, there are a few ranges of IP addresses that are available to anyone to use without asking for permission. One of these ranges is the addresses from 10.0.0.0 to 10.255.255.255. Another range you may have seen is from 192.168.0.0 to 192.168.255.255. More information can be found on wikipedia about these private networks. This tutorial uses the 10.0.0.0 network.
Now, back to our program. We were trying to talk to Sam on the network next door, and we do this through our default gateway Arla. Here is a little text graphic showing the path. The square brackets show that Arla that has 2 interfaces and 2 different IP Addresses.
(You) 10.4.2.2 -> (Arla)[ 10.4.2.1 — 10.4.0.2 ] -> 10.4.0.3 (Sam)
Now, we defined the default gateway on our computer as 10.4.2.1. But Arla also needs her own default gateway, as does Sam, and in this case it’s 10.4.0.1.
Quick side note: Each computer can only have 1 default gateway.
So, to review. Your settings are 10.4.2.2/255.255.255.0/10.4.2.1 (IP Address/Subnet/Gateway). Arla is 10.4.2.1/255.255.255.0 and 10.4.0.2/255.255.255.0 with a 10.4.0.1 gateway. Sam is 10.4.0.3/255.255.255.0/10.4.0.1
So, why do we need this other gateway? Well, we need it so Sam can talk back to us. Lets put that gateway in the picture, and we will call it Tom.
(You) 10.4.2.2 -> (Arla)[ 10.4.2.1 — 10.4.0.2 ] -> 10.4.0.3 (Sam) -> (Tom)[ 10.4.0.1 ]
You can talk to Sam because your computer says, Sam is not on your network, we need to talk to the default gateway Arla. Arla then says, hey, Sam is on my other network, I can talk to him directly.
But, when Sam needs to talk to you at 10.4.2.2, his network settings say you are not on my network, so I need to talk to my gateway Tom (at 10.4.0.1).
And here is the last part which are Routes!
Routes are a way to tell who you need to talk to next to get somewhere. Routes use something that looks like an IP Address and a subnet mask, and then an IP Address. For this example we are going to start with a route on Tom that looks like this:
This says, “if you want to talk to the 10.4.2.0 network, talk to 10.4.0.2”. So, we have this route on Tom. Sam asks Tom, “I need to get to 10.4.2.2″, and Tom says, talk to Arla(10.4.0.2)”.
Then Sam turns around says to Arla, I need to talk to 10.4.2.2 and Arla says, hey, I can do that because it’s on my other network.
Now, remember that default gateway we talked about. This is actually just a route. And it looks like this:
This says, if we have not already told you who to talk to with other routes, then EVERYONE ELSE you should go to 10.4.2.1.