TCP/IP Basics - II

Continuing from the previous post, in this blog, I will talk about routing and subnets.
Subnets
Subnets can be considered as a collection of machines that can communicate with each other without going via a router. Router's job is to connect different subnets. Subnets is defined by the combination of IP address and subnet mask. Subnet mask is usually defined similar to IP but it has certain bits turned off. For ex. a typical subnet mask would look like 255.255.255.0. Here the fourth octate is turned off. Now if the IP is 114.124.134.144 combining with subnet mask we know that the first 3 octates 114.124.134 define the network and 144 defines the node. So with this configuration in this subnet, we can have the IPs ranging from 114.124.134.0 to 114.124.134.255. Any two machines in the same subnet can talk directly by knowing the node value. 
We can use the tracert command and the pathping command to trace the route of a request. pathping command provides more reliable info as it sends multiple requests to each hop to calculate statistics.


Route
Now we know that how computers reach each other if they are in the same subnet. But how does a computer determine how to reach other subnets? For this the Routes table comes into picture. We can see the route table by using the command route print. The request tries to find the entry in the table that matches the most to figure out the gateway to contact. Usually the first entry in the table has a destination of 0.0.0.0, netmask of 0.0.0.0 and default gateway IP address as defined in the ipconfig. This means that for any IP the request should be routed to the default gateway. If you see the gateway as "On-link" that means the same machine. There is also another entry, usually in the end which has a destination of 255.255.255.255, netmask 255.255.255.255 and gateway as "On-link". This means that its a broadcast. Broadcasts don't cross routers. Broadcast is to send traffic destined only for the subnet.


Private IP
Since there is shortage of IPs, mostly at homes the ISP provides you with only  one IP. Then lets say at home you have your mobile phone, laptop, xbox and tv connected to internet, they all have 4 IPs taken from a private range. Whenever these devices communicate with outer world, a process called network address translation (NAT) converts them to the IP ISP provided. Simimlarly when the response comes back the ISP IP is converted to the private IP. The private IP/subnet range is 10.0.0.0/255.0.0.0, 172.16.0.0/255.240.0.0, 192.168.0.0/255.255.0.0.