{"id":1010,"date":"2018-10-21T00:11:58","date_gmt":"2018-10-21T00:11:58","guid":{"rendered":"https:\/\/www.appservgrid.com\/paw92\/?p=1010"},"modified":"2018-10-23T01:09:29","modified_gmt":"2018-10-23T01:09:29","slug":"networking-basics-ip-address-netmasks-and-subnets","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/21\/networking-basics-ip-address-netmasks-and-subnets\/","title":{"rendered":"Networking Basics &#8211; IP address, netmasks and subnets"},"content":{"rendered":"<p>In this tutorial, we will cover some networking basics. We won&#8217;t be hacking anything, but by the end of the tutorial you&#8217;ll learn a lot of things which will be useful later, especially when you&#8217;ll use <a href=\"https:\/\/en.wikipedia.org\/wiki\/Nmap\" target=\"_blank\" rel=\"noopener\">nmap<\/a>. Please note that it is advised that you go through wikipedia pages of all the concepts covered here since the discussion won&#8217;t be exhaustive in any way.<\/p>\n<p>IP address<\/p>\n<p>An IP address is simply a 32 bit address that every device on any network (which uses IP\/TCP protocol) must have. It is usually expressed in the decimal notation instead of binary because it is less tedious to write it that way. For example,<br \/>\n<a href=\"\/\/3.bp.blogspot.com\/-snI_3xRtYhQ\/VhjP9IK1ypI\/AAAAAAAABjY\/b2FXuQvWYLA\/s1600\/IP%2Baddress.jpg\"><img decoding=\"async\" src=\"\/\/3.bp.blogspot.com\/-snI_3xRtYhQ\/VhjP9IK1ypI\/AAAAAAAABjY\/b2FXuQvWYLA\/s1600\/IP%2Baddress.jpg\" \/><\/a>Decimal notation &#8211; 192.168.1.1<\/p>\n<p>Binary &#8211; 11000000.10101000.00000001.00000001It is clear from the binary form that the IP is indeed 32 bits. It can range from 0.0.0.0 to 255.255.255.255 (for the binary all 0s and all 1s respectively) [A lot of time, the first octet usually goes upto 127 only. However, we aren&#8217;t concerned with that here.]<\/p>\n<p>&nbsp;<\/p>\n<h3>Parts of an IP address<\/h3>\n<p>Now this IP address has 2 parts, the network address and host address. A lot of wireless routers keep the first 3 octets (8 bits, hence octets) for the network address and the last octet as host address. A very common configuration being 192.168.1.1 . Here, 192.168.1.0 is the network address and 0.0.0.1 is host address. I hope you can see that the host address can vary from 0.0.0.0 to 0.0.0.255 (though usually 0 and 255 are reserved for the network and broadcast respectively).<br \/>\n<b><br \/>\n<\/b><br \/>\n<b><br \/>\n<\/b><\/p>\n<h3>Need for Netmasks<\/h3>\n<p>But different networks have different needs. The previous configuration lets you have a lot of different possible networks (the first 3 octets are for the network and can take different values, not just 192.168.1.0) but only 256 (254 actually) hosts. Some networks may want more hosts (more than 255 hosts per network). This is why there is no &#8220;hardcoded&#8221; standard enforced on networks for the network and host addresses, and instead, they can specify their own configuration. The first 3 octets being network address and last octet being host address is common, but in no way mandatory. Using <b>Netmasks<\/b>, we can have very versatile set of configurations, for each and every need.<\/p>\n<h2>Netmask<\/h2>\n<p>A netmask is used to divide the IP address in subnets.<\/p>\n<p>We&#8217;ll start with a basic example. Suppose we want to define a netmask which configures our network like wireless router in the previous example. We want the first 3 octets to correspond to the network and next 1 octet for host address. Let&#8217;s think of an operation which we can use to separate the network and host part of the IP address. For simple purposes, we could have just defined after which octet does the host part start [basically saying that anything after the third period(.) is host address]. While this is a simple solution, it is not very versatile. A more elegant and mathematical solution was proposed.<\/p>\n<h3>Netmask &#8211; Working<\/h3>\n<p>First I&#8217;ll tell you the mathematical functionality of a netmask. Assume <b>A <\/b>to be an IP address and <b>M <\/b>to be a netmask. Then,<\/p>\n<p><b>A &amp; M<\/b> gives the Network address<b>A &amp; (~M) <\/b>gives the Host address.Where,<b>&amp; <\/b>is<b> bitwise And<\/b><b>~ <\/b>is<b> bitwise Not<\/b> (i.e. complement, <b>1s complement<\/b> to be more precise)So, basically a netmask is another 32 bit binary number (just like an IP address), but with the purpose of giving Host address and network address when the operation <b>bitwise and<\/b> is carried out on it (and it&#8217;s complement) with A.<\/p>\n<p>&nbsp;<\/p>\n<h3>Example<\/h3>\n<p>You&#8217;ll understand better with example.<\/p>\n<p>A = 192.168.1.1 is you IP addressM = 255.255.255.0We convert it to binary, and then carry out the desired operations.<\/p>\n<p><b>A = <\/b> 11000000.10101000.00000001.00000001 (192.168.1.1)<\/p>\n<p><b>M = <\/b> 11111111.11111111.11111111.00000000 (255.255.255.0)<b>A&amp;M =<\/b> 11000000.10101000.00000001.00000000 (192.168.1.0)A&amp;M is <b>network IP <\/b>that we desired<br \/>\n<b>A =<\/b> 11000000.10101000.00000001.00000001 (192.168.1.1)<\/p>\n<p><b>~M =<\/b> 00000000.00000000.00000000.11111111 (0.0.0.255)<b>A&amp;~M= <\/b> 00000000.00000000.00000000.00000001 (0.0.0.1)A&amp;~M is <b>host IP <\/b>that we desired<\/p>\n<p>&nbsp;<\/p>\n<h3>Explanation<\/h3>\n<p>Basically, if you realize that 11111111 is 255 in decimal, then you can see that for the parts of the IP address that you want for networks, you set the subnet to 255, and for the ones you want for host, you set it to 0.<\/p>\n<p>So, if you want to reserve 2 octets for networks and 2 for hosts, then the subnet will be-M = 255.255.0.0If you want 3 octets for host, thenM = 255.0.0.0<br \/>\nHence, we can see that using netmasks we can achieve what we wanted, i.e. to define networks with whatever number of hosts we require. Now we go a bit further.<\/p>\n<p>&nbsp;<\/p>\n<h2>Subnets<\/h2>\n<p>Now suppose you want to divide your network into parts. It is the sub-networks that are known as subnets (it is correct to call them subnetwork as well).<\/p>\n<p>We&#8217;ll jump right to it, consider the netmask MM = 11111111.11111111.11111111.11000000Now, the first 3 octets describe the network. But the 4th octet, which is supposed to be for the host, has the 2 most significant bits (i.e. leftmost bits) as 1. Thus, the 2 most significant (leftmost) bits of the 4th octet will show up when we carry out the bitwise AND operation. They will, thus, be a part of the network address. However, they belong to the host octet. Thus, these 2 bits, which belong to the host octet but show up in the network IP address divide the network into subnets. The 2 bits can represent 4 possible combinations, 00, 01, 10 and 11, and hence the network will have 4 subnets.<\/p>\n<p>&nbsp;<\/p>\n<h4>Example of Subnetwork<\/h4>\n<p>Back to our previous &#8220;A&#8221;,<\/p>\n<p><b>A =<\/b> 11000000.10101000.00000001.xx000001 (192.168.1.1)<b>M =<\/b> 11111111.11111111.11111111.<b>11<\/b>000000 (255.255.255.192)<b>A&amp;M =<\/b> 11000000.10101000.00000001.xx000000 (192.168.1.0)<\/p>\n<p>Earlier, irrespective of what was there in 4th octet of A, we would have got all 0s in 4th octet of A&amp;M i.e. network address. This time we will get the 2 most significant bits in the network address. Four subnets will be formed depending on the value of xx (which can be 00,01,10 or 11). Now, we will see which subnet has which set of hosts.<\/p>\n<p>&nbsp;<\/p>\n<h3>Which subnet has which hosts<\/h3>\n<p>11000000.10101000.00000001.<b>00<\/b>000000<\/p>\n<p>has hosts 192.168.1.<b>0-63<\/b> (<b>00<\/b>000000 to <b>00<\/b>111111)<br \/>\n11000000.10101000.00000001.<b>01<\/b>000000<\/p>\n<p>has hosts 192.168.1.<b>64-127<\/b> (<b>01<\/b>000000 to <b>01<\/b>111111)<br \/>\n11000000.10101000.00000001.<b>10<\/b>000000<\/p>\n<p>has host 192.168.1.<b>128-191<\/b> (<b>10<\/b>000000 to <b>10<\/b>111111)<br \/>\n11000000.10101000.00000001.<b>11<\/b>000000<\/p>\n<p>has host 192.168.1.<b>192-255<\/b> (<b>11<\/b>000000 to <b>11<\/b>111111)<br \/>\nSo the netmask M divided the network into 4 equal subnets with 64 hosts each. There are some subnets which are much more complicated and have their applications in certain specific areas. I recommend going through <a href=\"https:\/\/en.wikipedia.org\/wiki\/Subnetwork\" target=\"_blank\" rel=\"noopener\">Wikipedia page on Subnetworks<\/a> to get some more idea. I have covered enough and now you can understand Wikipedia;s content on the topic without any difficulty.<\/p>\n<p>&nbsp;<\/p>\n<h3>Some Special IPs<\/h3>\n<p>0.0.0.0 = All IPs on local machine. Anything hosted on this IP is available to all devices on the network.<\/p>\n<p>127.0.0.1 = LocalHost, this loops back to the machine itself.<\/p>\n<p>255.255.255.255 = Broadcast, anything sent to this IP is broadcasted (like radio is broadcasted to everyone) to all hosts on the network.<\/p>\n<h3>Finally<\/h3>\n<p>You see the notation in this pic?<\/p>\n<p><a href=\"\/\/4.bp.blogspot.com\/-RD-Od8aL8DY\/Vhfzv77zaPI\/AAAAAAAABjI\/2L8WYFzZ-KM\/s1600\/Subnet.png\"><img loading=\"lazy\" decoding=\"async\" src=\"\/\/4.bp.blogspot.com\/-RD-Od8aL8DY\/Vhfzv77zaPI\/AAAAAAAABjI\/2L8WYFzZ-KM\/s640\/Subnet.png\" width=\"640\" height=\"400\" \/><\/a><\/p>\n<p>This way of representing subnets using \/24, \/25, \/26, etc. is quite useful while doing vulnerability scans on networks (using nmap, etc.). \/24 represents the netmask 255.255.255.0 , the first example we took of Wireless router. It is the most common configuration you&#8217;ll use while doing nmap scan. The one we discussed later, in the subnets section, is \/26. It has 4 subnetworks. \/25 has 2 subnets. \/27 has 8. \/31 has 128 subnets! In this subnet, only 2 host can be there per network, and it is used for 1 to 1 or point to point links. I hope the next time you have to deal with networks, you won&#8217;t be having difficulties. There are topic like Multicast etc. which build up on this, and you can do further reading on them. That was all for this tutorial. Good luck.<\/p>\n<p><a href=\"https:\/\/www.kalitutorials.net\/2015\/10\/networking-basics-ip-address-netmasks.html\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this tutorial, we will cover some networking basics. We won&#8217;t be hacking anything, but by the end of the tutorial you&#8217;ll learn a lot of things which will be useful later, especially when you&#8217;ll use nmap. Please note that it is advised that you go through wikipedia pages of all the concepts covered here &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2018\/10\/21\/networking-basics-ip-address-netmasks-and-subnets\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Networking Basics &#8211; IP address, netmasks and subnets&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1010","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1010","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=1010"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1010\/revisions"}],"predecessor-version":[{"id":1385,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/1010\/revisions\/1385"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=1010"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=1010"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=1010"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}