Friday, May 29, 2009

The Story of the Internet

You have a computer, any computer, that has an ethernet port. You connect a straight-through ethernet cable from the ethernet port on the computer to a switch or router. Your network card detects a connection and alerts the operating system. The operating system then instructs your computer to send a packet (a packet is nothing more than an electronic envelope containing electronic information...kinda like a letter in the postal system) that yells out to everyone on the network, "Hey! I'm here! Is there any one named Mr. DHCP out there?" (Mr. DHCP is the DHCP server, DHCP standing for Dynamic Host Client Protocol) The DHCP server running on the network (usually in a home network it is the internet router) sends a packet back saying, "Hello! Welcome to our network! I am Mr. DHCP! What can I do for you?" Your computer responds back with it's network card's God-given name. You see, every network card that is ever built has a programmed name, called the MAC address (Machine Access Control), that is dependent upon manufacturer. It looks something like 00:0C:41:C0:AB:23. As you can tell, that's a really long number. So your network card sends this God-given name to Mr. DHCP and Mr. DHCP responds with the nickname the network card will use on the network from now on, called the IP address (looks like 192.168.0.100). All further packets to and from your network card will be identified using this IP address. Mr. DHCP also responds with the nicknames of the DNS server and the gateway the network is using (along with the network net-mask--more about this in a bit). In a home network, the router actually also serves as the DNS server and the gateway, so these would be something like 192.168.0.1. So your computer now knows who the important guys are on the network: the gateway, the DNS server, and the DHCP server. These three guys control all of the information that your computer needs to access the internet.

Say you want to access a website. You type in to your computer browser, "http://www.google.com". Your computer, behind the scenes, contacts Mr. DNS server in a packet and says, "Hey, I need the IP address for www.google.com", and Mr. DNS responds in a packet with, "His nickname on the internet is 74.125.95.99". Now, your computer needs to talk to 74.125.95.99. Your computer knows that he's not on the local network, because the net-mask defines who is in the local network and who isn't. That is, the net-mask provides all the possible nicknames of guys who live inside the firewall. For example, if the net-mask is 255.255.255.0 and your computer has the IP address of 192.168.0.100, then the only computers that could possibly be behind the firewall with you have the nicknames 192.168.0.101-192.168.0.254. If the net-mask is 255.255.0.0, then the local computers also behind the firewall have only the nicknames 192.168.0.1 - 192.168.254.254. (254 is the highest number possible between the . .'s) So if your computer needs to talk to anyone having nicknames within that range, he can just talk with them. However, if the nickname of the computer that he needs to talk to is not in this range (such as www.google.com's nickname), he has to make a long-distance phone call using Mr. Gateway.

Mr. Gateway is very important. He makes sure all traffic able to get into the LAN was asked for. He doesn't allow packets from just anyone to make it in to the LAN. He is essentially the bouncer for the local area network. Mr. Gateway actually has two nicknames: he has one that he uses to talk with the guys on the LAN, and he has one that he uses to talk with the guys on the internet (or WAN). He can pass along messages from either side. Usually, he always passes information from the LAN to the WAN (so he always communicates on behalf of someone on the LAN if someone on the LAN wants packets to go out to someone on the internet). He will only pass packets from the internet into the LAN if those packets were asked for by someone on the LAN sending out a request. When you set a port forward on your router, you are actually telling Mr. Gateway to pass all packets coming in on port 22 to your server to deal with, instead of refusing them. Oh! ports! Ok, so ports are like multiple sorting bins for network traffic. Ports are used to distinguish packets used for different purposes. For example, port 80 is the standard HTTP port. All packets that are used for the HTTP (Hyper Text Transfer Protocol) are usually sent and received on port 80. Port 22 is SSH, port 23 is FTP. And that's about all I actually know off the top of my head. Now, these days, port numbers are not used as strictly as they once were. But they are still used in starting connections between clients and servers. When a packet arrives on port 80, though, your computer doesn't have to sit there an figure out, "ok, what kind of packet is this and where does it go?" It knows it is HTTP going to a browser. It simplifies things a little.

So! Back to trying to visit "http://www.google.com"! Your computer would send a packet containing a HTTP request on port 80 to the gateway with instructions to forward it on to 74.125.95.99. When the server 74.125.95.99 responds, your gateway knows it is for your computer and sends the response to you at 192.168.0.100. The server at google only ever sees your gateway. It does not know what your MAC address is of your actual computer. It provides some anonymity.

There is a lot more about routing and your actual router and ISP and such, but this is a good start toward understanding networking.

I hope all this makes sense! If not, ask me some questions and I'll hopefully be able to clarify them!

No comments: