IP address and subnet mask
We all know that IP addresses are composed of four digits. Here, let's take a look at three common types of IP addresses.
Class a ip segments 0.0.0.0 to 127.255.255.255
Class B IP segments 220.127.116.11 to 18.104.22.168
C-type IP segments 192.0.0.0 to 22.214.171.124
The default subnet mask allocated by XP is only 255 or 0 for each segment.
Class A default subnet mask 255.0.0.0 a subnet can accommodate up to 16.77 million computers
Default subnet mask of type B 255.255.0.0 a subnet can accommodate a maximum of 60 thousand computers
Class C default subnet mask 255.255.255.0 a subnet can accommodate a maximum of 254 computers
I used to think that if you want to put some computers in the same network segment, you only need to make the first three paragraphs of the IP address the same. Today, I know that I am wrong. If so, can a single subnet only accommodate 254 computers? It's a joke. Let's take a look at it in detail.
If you want to be in the same network segment, as long as the network ID is the same, what should you do with the network ID? The first thing to do is to convert the IP address of each segment to binary. (Some people say that I won't change it. It doesn't matter. We can use the built-in calculator in windows. Open the calculator, click View> scientific type, enter a decimal number, and click the "binary" Single-Choice Point to switch to binary .)
After switching the subnet mask to binary, we will find that all the subnet masks are composed of a string of consecutive 1 and a string of consecutive 0 (a total of 4 segments, each segment of 8 bits, 32 digits in total ).
This is the binary form of the default subnet mask of Class A/B/C. In fact, there are many subnet masks, as long as it is a string of continuous 1 and a string of continuous 0 (each segment is 8 bits ). For example, 11111111.111111.11111000.00000000, which is also a valid subnet mask. The subnet mask determines the number of computers in a subnet. The computer formula is 2 to the power of M. Here, we can see m as the number of digits following 0. For example, when 255.255.255.0 is converted to a binary value, it is 11111111.1111.1111.00000000. There are 8 digits behind it, and m is 8. The 255.255.255.0 subnet mask can accommodate 2 Power 8 computers, that is, 256 machines, but two IP addresses are not available, that is, the last segment cannot be 0 or 255. If the two IP addresses are subtracted, the number is 254. Let's try again.
201710000248.0 how many computers can this subnet mask accommodate?
Convert it to a four-digit binary number (each segment is 8 bits. If it is 0, it can be written as 8 zeros, that is, 00000000)
Then, there are several zeros behind the number, and there are 11 in total, that is, the power of 2's 11, equal to 2048. This subnet mask can accommodate a maximum of 2048 computers.
The maximum number of computers that a subnet can hold, you can forget it. Let's look at the reverse. Algorithm .
A company has 530 computers and forms a peer-to-peer lan. What is the most suitable subnet mask?
First of all, it is undoubtedly the most suitable class B ip address for 530 computers (class A, too many, and class C is not enough, it must be Class B ), however, the default subnet mask of Class B is 255.0.0, which can accommodate 60 thousand computers. Obviously, this is not suitable. How many subnet masks are suitable? Let's first list a formula.
2 to the power of M = 560
First, we confirm that 2 must be greater than the power of 8, because we know that the power of 2 is 256, that is, the maximum number of computers allowed by Class c ip addresses, we try to use the power of 9 to the power of 2 to the power of 512, less than 1024, and the power of 10 to 2 is. It seems that the power of 2 is the most suitable. The subnet mask consists of 32 bits. It has been determined that the next 10 bits are 0, and the first 22 bits are 1. The most suitable subnet mask is 11111111.111111.11111100.00000000, which is converted to 10 hexadecimal format, that is 255.255.252.0.
Assign and calculate the subnet mask. Next, let's look at the IP address CIDR block.
I believe many people share the same relationship with me. I think that the IP address is in the same network segment as long as the first three paragraphs are the same. In fact, this is not the case. Similarly, I convert each segment of the IP address into a binary number, take IP Address: 192.168.0.1, subnet mask: 255.255.255.0 as an example.
(Here, we will describe that, like the subnet mask, each segment has eight bits. If there are less than eight bits, add 0 to the front .)
Subnet Mask 11111111.111111.1111111111.00000000
Here, I would like to explain how the same network segment is considered.
In order to be in the same network segment, the network ID must be the same. How can this problem be solved? The network identification algorithms of various IP addresses are different. Class A is only the first segment. Class B, only the first and second sections. Class C: calculates the first, second, and third sections.
The algorithm only needs to set the IP address and subnet mask each digit and.
And method: 0 and 1 = 0 0 and 0 = 0 1 and 1 = 1
For example: And 192.168.0.1, 255.255.255.0, first converted to binary, And each and
Subnet Mask 11111111.111111.1111111111.00000000
Obtain the and result 112.1600.10101000.00000000.00000000.
Convert to 192.168.0.0 in decimal format. This is the network ID,
Then, the subnet mask is reversed, that is, the IP address and
The result is calculated as follows: 2017.hangzhou.hangzhou.00000001, which is converted to a 10-digit system, that is, 0.0.0.1,
0.0.0.1 indicates the host ID. To be in the same network segment, you must have the same network ID.
Let's take a look at the Class B IP address changed to the default subnet mask.
For example, IP Address: 126.96.36.199, 188.8.131.52, all subnet masks are set to 255.255.254.0. Are they in the same network segment?
First convert these to binary
Respectively and, get
The network IDs are different, that is, they are not in the same CIDR block.
Check whether the IP address is in the same CIDR block. Now, let's look at it.
A company has 530 computers to form a peer-to-peer lan. What is the most suitable subnet mask and IP address?
The subnet mask is not mentioned. The previous calculation result is 11111111.1111111100.00000000, that is, 255.255.255.252.0.
Now we need to determine how to allocate IP addresses. First, select a Class B IP segment. Here we will select 188.188.x.x.
In this way, the key to determining the first two IP segments is to determine the third segment, as long as the network ID is the same. Let's first determine the network number. (We set? Right up, 0 corresponds to *, as shown below :)
188.188.x.x 10111100.10111100 .?????? **.********
Network ID 10111100.10111100 .?????? 00.00000000
From this we can see ,? (Only 0 and 1 can be entered. Not all are 0 and 1.) Let's fill in 0, *. In this case, our IP address is
10111100.101100.000000 **. *********, a total of 530 computers, the last segment of the IP address 1 ~ 254 can be allocated to 254 computers, 530/254 = 2.086, using the method of entering 1, get an integer of 3, so we have determined that the third segment of the IP address should be divided into three different numbers, that is, set ** in 000000 ** to three numbers. You can only enter 1 and 0, and the numbers are different each time. As for what to fill in, it will be convenient, such as 00000011, convert it to binary, which is 1, 2, 3, so that the third segment is also determined. In this way, you can divide the IP address into 188.188.1.y, 188.188.2.y, 188.188.3.y, and Y ~ Within the range of 254, And the 530 computers are different from each other's IP addresses.
Some people may say that, since the algorithm is so troublesome, simply use the default subnet mask of Class a ip address and Class A. What I want to tell you is, because the number of hosts with a Class a ip address and a default subnet mask is too large, this is undoubtedly a haystack. If the LAN traffic is too frequent or too large, it will affect the efficiency, it is best to set your own IP address and subnet mask ^_^