IP address, subnet mask, and address classification

Source: Internet
Author: User

Http://blog.csdn.net/bluishglc/article/details/47909593?utm_source=tuicool&utm_medium=referral

The actual work used in the network knowledge of the opportunity is not much, although the previous study, but a long time without natural also unfamiliar. Recently received a few virtual machines on the cloud, need to build a VPC for them (virtual private cloud, is a virtual LAN), thanks to virtualization technology, as a user, we save the vast majority of network configuration and debugging work, the only thing we need to do in person is the division of the network. Dividing the network requires a clear three basic concepts: IP address, subnet mask, and address classification, which are the three elements that determine the division of the entire IP address space. About these can refer to the article at the end of the information attached, the text of this article is from the relationship between the three thinking of a network to solve what the problem. This article source: http://blog.csdn.net/bluishglc/article/details/47909593 prohibited any form of reprint, or will entrust CSDN official maintenance rights!

32-bit IP address space Total has 40多亿个 available IP address, if you are the beginning of the Internet creation of the designer, how will you assign these IP? You might say one by one, ask one for one. This is a solution, but in the face of so many IP addresses, this "flat" management method really effective? What if it was given to an organization or even a country for mass distribution of p? Like managing a 40多亿个 file under a folder, is this a really sensible way to handle it? Obviously, the designers did not take this simple and straightforward approach, but as we manage most of the information to "classify" the information, as well as the 40多亿个 file, if the rules or characteristics scattered in a number of folders or sub-folders will be greatly convenient to manage.

So the question came: how to divide?

If the IP address is regarded as a home address, then in the home address of the natural province, city, street, community such hierarchical division, gradually narrowed down to a house number. If we give the provinces, cities, streets are numbered, and then together with the number, we get such a long list of numbers can uniquely identify a home address, similarly, the IP address has 32 bits of length, so long a code, why can not remove the first few as a "region" address, What about the remaining few as its "relative" address in this area? Such an IP address can be regarded as two parts, the front is its "area" address, followed by its "relative" address in this "area", yes, this is the subnet mask to solve the problem, according to the specification, through the subnet mask identified by the so-called "zone" address on the network address, also known as the network identity, The network ID or subnet address, and the so-called "relative" address on the host address.

This looks a lot better, but I don't know if you are acutely aware that the division of IP addresses between subnet masks and our example of Home address division has a distinct difference, that is, the former can only be divided into two levels: Network address and host address, while the latter is multi-level division. A subnet mask can only achieve level two partitioning poses a problem, That is the same ip:67.101.121.131, its subnet mask may be 255.0.0.0, it may be 255.255.0.0, it may be something else, so, for a given IP, especially the public network IP, when not aware of the subnet mask will lead to a number of different interpretations of the IP, Like the example above, 67.101.121.131 may be a host under the subnet 67.0.0.0, or a host under subnet 67.101, it is clear that this ambiguity caused this IP is still not available, yes, we still missed something, let this set of description mechanism temporarily unable to work, we need to find the cause of the problem and plugging in this hole.

This last need to address the vulnerability can be described as: because the subnet mask only has "level two" (Network address and host address) Division capability, and its granularity of segmentation is variable (that is, if the number of subnets cut out, then the subnet can accommodate more machines, if the subnet more, The number of machines that can be accommodated is small) this uncertain partitioning method will inevitably lead to the uncertainty of IP meaning, so to solve this problem must be defined: Which value is the IP that begins with its subnet mask default is 255.0.0.0, Which value begins with the IP its subnet mask defaults to 255.255.0.0, and so on. This is actually the IP address classification.

After filling in the concept of address classification, let's re-compare the partitioning of an IP address space with a typical hierarchical relationship between the types of home addresses we use to illustrate the difference. As mentioned above, the biggest difference is that the IP address space can only be divided into two levels, in order to be able to adapt to different sizes (granularity) of IP allocation requirements, IP address space must be divided into a number of different sizes (granularity) of the sub-space, and specify which are large-scale (granular) subspace, which are small-scale (granular) sub-spaces. Then, the combined IP address and subnet mask can be accurately positioned. It can be said that the IP address, subnet mask and address classification of the three elements together to achieve the IP address space Division and addressing, the absence of any one of the three elements will bring a logical loophole.

The last question: Similarly, in a LAN, theoretically we also need to cut out the size of the sub-network needs, which also need to classify the IP address, such as in the 10.0.0.0/8 network partition 10.0.0.0/16 ~ 10.127.0.0/ 16 and 10.128.0.0/24 ~10.191.255.0/24 etc. as to whether it is feasible and how to operate the opportunity to consult with the network administrator.

Finally, a very useful network calculator is attached: http://www.123cha.com/cidr/

Reference Subnet Mask

The subnet mask is used to indicate which of the IP addresses identifies the subnet (also called the Network Identity) on which the host resides, and which bits identify the host's address in the network. The subnet mask cannot exist alone, it must be used in conjunction with an IP address.

But if there is only a subnet mask, we can tell the information is: it can represent multiple subnets, and how many hosts can be in each subnet!

The subnet mask typically has the following 2 format representations:

1. By dotted decimal notation that is the same as the IP address format
such as: 255.0.0.0 or 255.255.255.128
2. Add the "/" symbol to the IP address followed by a number of 1-32, where 1-32 of the number represents the length of the network identity bit in the subnet mask
such as: 192.168.1.1/24 subnet mask can also be expressed as 255.255.255.0

IP Address Classification

In a LAN, we can completely according to their own wishes and needs to divide the network address, as well as the definition of 3 elements,
Address classifications, subnet masks, and IP addresses.

IP default subnet mask assigned is only 255 or 0 per segment

Class A IP address the value range of the first field: 0-127 default subnet mask: 255.0.0.0

The value range of the first field of Class B IP address: 128-191 default subnet Mask 255.255.0.0

The value range of the first field of Class C IP address: 192-223 default subnet Mask 255.255.255.0

Known IP address and subnet mask, with IP address and subnet mask to get network number

The last face of the subnet mask has several zeros, such as N, to find the host number: POW (2,n)-2 (all 0 for network address, all 1 for broadcast address)

1 of the subnet mask can be used to find the number of subnets

For example, the IP address is 151.244.20.34 The subnet mask is 255.255.255.224, this IP is a class B IP, both phases,

Network number is 151.244.20.32

224 is represented as 11100000 with a binary, followed by 5 0, then the number of hosts is POW (2,5)-2, where all 0 is used as the network address and all 1 is the broadcast address

16-5=11, the number of subnets is POW (2,11)-2 where all 0 is used as the network address, and all 1 is used for exchange-back testing

The following Python program can determine the IP category and ask for the corresponding network number:

S=raw_input ();s=S.Split"."); Mask=raw_input (); Mask=mask.Split".");For I in range (0,4): s[i]=intS[i]);mask[i]=Int (mask[i]);Ifs[0]>=0ands[0]<=127): Print"A IP";flag=1;elif (s[0]<=192): Print"B-IP";flag=2;elif (s[0]<=223): Print"C-IP";flag=3;elif (s[0]>255): Print"Error";if (flag is1):I=0;Res=[]; For I in range (0,4): Res.append (mask[i]&S[i]); PrintThe network number is%d.%d.%d.%d% (res[0],res[1],res[2],res[3]);if (flag is2):Res=[]; For I in range (0,4): Res.append (mask[i]&S[i]); PrintThe network number is%d.%d.%d.%d% (Res[0],res[1],res[2], Res[3]);  if (flag is 3):  Res=[]; for i in range (0,4):   Res.append (mask[i]&s[i]);  print  "network number is %d.%d.%d "% (res[< Span class= "number" >0],res[1],res[2],res[3]);   

Reserved address

Three zones are reserved exclusively as private addresses in the IP address, and their address ranges are as follows:

type Network Address Number of networks
A 10.0.0.0/8 (10.x.x.x) 1
B 172.16.0.0/12 (172.16.x.x ~ 172.31.x.x) 16
C 192.168.0.0, (192.168.x.x ~ 192.168.x.x) 256

IP address, subnet mask, and address classification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.