Friday, November 20, 2015

Week 11: Day 032 - TCP/IP Basics #3


Lately my entries have not been as long, there have been many distractions, and hopefully I will be able to summarize them by the end of the week. But for now, I will continue to focus on this. So today, I'll start off by talking about "IP Addresses in Action" as that's what the textbook has next in store.

First, IP Addresses support both LAN and WAN. When a computer needs to send data to both, some problems can arise. To make it work it needs to do three things:

- Create a way of using IP addresses so each LAN has some form of identification.
- Interconnect the LANs with routers, and give a way for the said routers to use the network identification to send packets to the right network.
- Give every computer on the network a way to recognize a packet as one for LAN or a computer on the WAN so it knows where to send it.

Each computer on a single LAN shares similar IP addresses, some parts match, while others don't. Only the last number is different. To give an example, if I had an IP of 202.140.10.x the x part would be the host ID in the IP. The network ID would be 202.140.10.0, because no computer can have x = 0 in that scenario. A router therefore needs an IP address for the LANs that it serves, so it can route the packets correctly. That router is known as the "default gateway" which I already knew! Most network admins will give the LAN-sided NIC on the default gateway, the lowest host address in all the network, which would usually be 1. Routers use network IDs to assess the network traffic and activity. In a two-NIC router, you'll see one port (ex: 202.120.10.1) connects to LAN while the other port connects to the ISP (ex: 14.23.54.223) and the built in a router is a "routing table" which give instructions to the router on what to do with packets. Network IDs are flexible and as long as two devices don't have the same IP, you can give your device whatever IP you want! Network IDs allow you to connect multiple LANs onto a WAN. Routers will then connect everything with their routing tables.

Next, there's the subnet mask. Say you had three devices on a network, but two are on one LAN, while the third one is on another LAN, how do you communicate these computers? Getting a packet to a local device is much different than getting one to a faraway device. If one of the computers wants to send a packet to your computer, it would send a broadcast to try and get your MAC address. Now, a subnet mask is a string of binary which also totals to 32 bits. Here's the conversion process:

11111111111111111111111100000000

11111111.11111111.11111111.00000000

255.255.255.0

Quite similar to the IP conversion, eh? Basically each octet has a decimal. Before the computer sends data, it compares the destination's IP and its own, using the subnet mask. If the subnet masks match, then it knows that the destination computer is on the local network. Now, say that the IP address on the first computer of this hypothetical has an IP of "192.168.5.23" convert that to binary:

11000000.10101000.00000101.00010111

Get rid of the meaningless periods:

11000000101010000000010100010111

Then say that the first computer wants to send a packet to computer two. The subnet mask on the first computer is 255.255.255.0 while the IP address on computer two is "192.168.5.45". Convert that address to binary:

11000000101010000000010100101101

The first computer will compare its IP address to the destination's (computer two) IP using the subnet mask here's a diagram to show exactly how the computers use the subnet mask as a way to identify that they're both local:

Subnet mask: 111111111111111111111111|00000000
Computer 1:   110000001010100000000101|00010111
Computer 2:   110000001010100000000101|00101101

What do both IP have in common? the 1s match in the Subnet Mask and both of them! Thanks to that chart, I'm easily able to understand what the purpose of the subnet mask is (note to self: that chart is useful!) and that's pretty much it.

Now that computer one knows that it's a local call, it can send an ARP request, a broadcast to find the destination computer's MAC address. The ARP (Address Resolution Protocol) is the way a TCP/IP network determines the MAC address based on the destination's IP address. Then the destination computer responds by sending computer one an ARP response. When computer one gets the IP, then it sends the packets.

What about if computer one wanted to send a packet to computer three? Well it would do what I said before, and compare the subnet masks. It will then find out that the IP addresses don't match. When it does that, it then makes a "long-distance call". To send a packet to another LAN, the sending computer (computer one) knows to send it to the default gateway. It still sends an ARP request, not to the destination, but to the default gateway. When computer one gets the MAC address of the default gateway, it sends packets to it.

In conclusion, something to note is that subnet masks can come in different lengths. For example: 255.255.255.0, 255.255.0.0, and 255.0.0.0 (remember these are in 32 bit binary numbers.) At the end of the day, if you want to get your computer routed to the interwork, you must have an IP address which is part of the network, and must have a subnet mask, and a default gateway. On that bombshell, thanks for reading, and goodbye!


No comments:

Post a Comment