Ip address, subnet mask, and address classification, ip subnet mask
Http://blog.csdn.net/bluishglc/article/details/47909593? Utm_source = tuicool & utm_medium = referral
There are not many opportunities to use network knowledge in actual work. Although I have learned it before, it will become unfamiliar without having to use it for a long time. Recently, I got several virtual machines on the cloud and needed to create a VPC for them (Virtual Private cloud is a virtual LAN). Thanks to the virtualization technology, as a user, we save most of the network configuration and debugging work. The only thing we need to host is the division of the network. Network Division requires three basic concepts: IP address, subnet mask, and address classification. These three elements determine the division of the entire IP address space. For more information, see the documents attached at the end of the article. The text of this article describes the problems to be solved when dividing a network based on the relationship between the three. Source of the original article: http://blog.csdn.net/bluishglc/article/details/47909593 prohibit any form of reprint, otherwise it will entrust CSDN official maintenance rights!
The 32-bit IP address space has a total of more than 4 billion available IP addresses. If you were the creator of the Internet, how would you allocate these IP addresses? You may say one by one, and request one by one. This is a solution, but is this "flat" management method really effective for so many IP addresses? What if a batch allocation of P is made to an organization or even a country? Just like managing more than 4 billion files in a folder, is this method really wise? Obviously, the designers did not adopt this simple and straightforward approach, but managed the information as we managed most of the information, which is also more than 4 billion files, if they are scattered to Multiple folders or subfolders according to certain rules or features, it will be very convenient for management.
So the question is: how to score?
If you think of an IP address as a home address, the home address is naturally divided by a province, city, street, or residential area, which is scaled down step by step and located on a house number. If we create numbers for the province, city, and street, and combine them with the street number, we can get a long string of numbers to uniquely identify a home address. Similarly, the IP address has a 32-bit length, so long as an encoding, why can't we retrieve the first few digits as a "region" address, which of the remaining digits is used as the "relative" address in this region? Such an IP address can be regarded as two parts. The front is its "region" Address, followed by its "relative" address in the "region", yes, this is exactly the problem to be solved by the subnet mask. According to the standard naming convention, the so-called "region" address identified by the subnet mask is the network address, also known as the network identifier, network ID or subnet address, the so-called "relative" address is the host address.
This looks a lot better, but I don't know if you are keenly aware that the subnet mask is significantly different from the home address in our example, that is, the former can only be divided into two levels: network address and host address, while the latter is divided into multiple levels. The subnet mask can only be divided at two levels, resulting in the same IP address: 126.96.36.199. Its subnet mask may be 255.0.0.0 or 255.255.0.0, it may also be another value. Therefore, when a given IP address, especially the public IP address, does not know the subnet mask, it may lead to different interpretations of the IP address, as in the above example, 188.8.131.52 may be a host under 184.108.40.206, or a host under subnet 67.101. Obviously, this ambiguity causes this IP address to be unavailable, yes, we have missed something to make this descriptive mechanism temporarily unavailable. We need to find the cause of the problem and block it.
The last vulnerability that needs to be addressed can be described as: Because the subnet mask can only be divided into "two levels" (network address and host address, the splitting granularity is variable. (that is, if the number of subnets to be split is small, the number of machines that the subnet can accommodate is large. If the number of subnets is large, the number of machines that the subnet can accommodate is small) this uncertain division method will inevitably lead to uncertainty in the meaning of the IP address. To solve this problem, you must specify the IP address whose subnet mask starts with 255.0.0.0 by default, the default subnet mask of an IP address starting with 255.255.0.0, and so on. This is actually the IP address category.
After completing the concept of address classification, We will compare the division of an IP address space with the Information Division with the typical hierarchical relationship such as home address. As described above, the biggest difference is that the IP address space can only be divided into two layers. To meet the IP Address allocation requirements of different scales (granularity), the IP address space must be divided into multiple scales (granularity) and specify the large-scale (granularity) Sub-spaces and small-scale (granularity) Sub-spaces. Then, you can use the IP address and subnet mask to locate the IP address accurately. It can be said that IP addresses, subnet masks, and address classifications can be divided and addressed together. The absence of any of the three elements will lead to logical vulnerabilities.
The last problem: Similarly, in a LAN, theoretically we also need to split subnets of varying sizes, which also need to classify IP addresses, for example, 10.0.0.0/8 is divided into 10.0.0.0/16 ~ 10.127.0.0/16 and 10.128.0.0/24 ~ 10.191.255.0/24, etc. Ask the network administrator about the feasibility and operation.
Finally, attach a very useful network calculator: http://www.123cha.com/cidr/
Reference Subnet Mask
The subnet mask is used to specify the IP addresses that identify the subnet (also called the network ID) of the host and the addresses in the network of the host. The subnet mask cannot exist independently. It must be used together with the IP address.
However, if there is only a subnet mask, we can determine the information: it can represent multiple subnets, and how many hosts can be under each subnet!
The subnet mask is usually expressed in the following two formats:
1. The IP address is represented by the point in decimal format.
For example, 255.0.0.0 or 255.255.255.255.128
2. Add a "/" symbol and a number ranging from 1 to 32 after the IP address. The number 1 to 32 indicates the length of the network identification bit in the subnet mask.
For example, the subnet mask of 192.168.1.1/24 can also be expressed as 255.255.255.0.
IP address category
In a LAN, we can split network addresses according to our own wishes and needs. It is also a definition of three elements,
Address category, subnet mask, and IP address.
The subnet mask assigned by the IP address is only 255 or 0 in each segment by default.
Value Range of the first field of Class a ip Address: 0-127 default subnet mask: 255.0.0.0
The value range of the first field of type B IP Address: 128-191 default subnet mask 255.255.0.0
The value range of the first field of the class c ip Address: 192-223 default subnet mask 255.255.255.0
If you know the IP address and subnet mask, use the IP address and subnet mask to obtain the network number.
There are several zeros at the end of the subnet mask, such as n. The number of hosts can be obtained: pow (2, n)-2 (all zeros are used for network addresses, and all 1 is used for broadcast addresses)
The number of 1 in the subnet mask can be used to calculate the number of subnetworks.
For example, if the IP address is 220.127.116.11 and the subnet mask is 255.255.255.255.255.255.34, this IP address is a Class B IP address,
Network No. 18.104.22.168
224 is expressed as 11100000 in binary format. If there are 5 zeros behind it, the number of hosts is pow ()-2, where all 0 is used as the network address, and all 1 is the broadcast address.
16-5 = 11, then the number of subnets is pow ()-2, where all 0 is used as the network address, and all 1 is used for the test.
The following python program can determine the IP category and request the corresponding network number:
s=raw_input();s=s.split(".");mask=raw_input();mask=mask.split(".");for i in range(0,4): s[i]=int(s[i]); mask[i]=int(mask[i]);if(s>=0 and s<=127): print "A IP"; flag=1;elif(s<=192): print "B IP"; flag=2;elif(s<=223): print "C IP"; flag=3;elif(s>255): print "error";if(flag is 1): i=0; res=; for i in range(0,4): res.append(mask[i]&s[i]); print "network number is %d.%d.%d.%d" %(res,res,res,res);if(flag is 2): res=; for i in range(0,4): res.append(mask[i]&s[i]); print "network number is %d.%d.%d.%d" %(res,res,res,res); if(flag is 3): res=; for i in range(0,4): res.append(mask[i]&s[i]); print "network number is %d.%d.%d.%d" %(res,res,res,res);
In the IP address field, three regions are reserved as private addresses. The address ranges are as follows:
||Number of networks
||10.0.0.0/8 (10. x)
||172.16.0.0/12 (172.16.x.x ~ 172.31.x.x)
||192.168.0.0, 16 (192.168.x.x ~ 192.168.x.x)