After learning and mastering the previous two parts of "Binary Counting" and "Detailed Explanation of
IP Address", to learn subnetting, you must first know the subnet mask. Only when you have mastered the subnet mask can you Good understanding and division of subnets.
Simple Application Server
USD1.00 New User Coupon
* Only 3,000 coupons available.
* Each new user can only get one coupon(except users from distributors).
* The coupon is valid for 30 days from the date of receipt.
1. Subnet mask
The IP address is the network number and host number to identify the host on the network. We call the host with the same network number as the
local network, and the host with different network numbers is called the remote network host. The host in the local network can be directly Communication with each other; hosts in the remote network must communicate with each other through the local gateway (Gateway) to transfer and forward data.
1. The concept and function of subnet mask
① Subnet Mask is also called network mask and address mask, which must be used in conjunction with IP address.
②. Only through the subnet mask can the relationship between the subnet where a host is located and other subnets be shown, and the network can work normally.
③ The subnet mask and the IP address are "anded" to separate the network address and host address in the IP address, which is used to determine whether the IP address is on the local network or on the remote network.
④. The subnet mask is also used to further divide the network into several subnets to avoid excessive host congestion or too few IP waste.
2. The composition of the subnet mask
① Like the IP address, the subnet mask is an address composed of a 32-bit binary number.
② The 32-bit subnet mask corresponds to the 32-bit IP address. If a certain bit of the IP address is a network address, the subnet mask is 1, otherwise it is 0.
③, give a chestnut: such as: 11111111.11111111.11111111.00000000
Note: The number of consecutive 1s on the left represents the length of the network number (it must be continuous when used, or not in theory), and the number of consecutive 0s on the right represents the length of the host number.
3. Representation of subnet mask
①, dotted decimal notation
Binary conversion to decimal, every 8 bits are separated by dot
For example: Subnet mask binary 11111111.11111111.11111111.00000000, expressed as 255.255.255.0
②, CIDR slash notation
IP address/n
Example 1: 192.168.1.100/24, its subnet mask is represented as 255.255.255.0, and its binary representation is 11111111.11111111.11111111.00000000
Example 2: 172.16.198.12/20, its subnet mask is represented as 255.255.240.0, and its binary representation is 11111111.11111111.11110000.00000000
It is not difficult to find that there are 24 1s in Example 1 and 20 1s in Example 2, so n comes from this way. Operators ISP often use this method to assign IP addresses to customers.
Note: n is a number from 1 to 32, which represents the length of the network number in the subnet mask. The number of hosts in the subnet is determined by the number of n=2^(32-n)-2 (cause of -2: host bit) All 0 means the network address of this network, and host bits all 1 means the broadcast address of this network. These are two special addresses).
4. Why use subnet mask?
As mentioned earlier, the subnet mask can separate the network address and the host address in the IP address, so why separate? Because two hosts want to communicate, they must first determine whether they are in the same network segment, that is, whether the network addresses are the same. If it is the same, then the data packet can be sent directly to the target host, otherwise the routing gateway is required to forward the data packet to the destination.
It can be understood as simple as that: Host A wants to communicate with Host B, and the respective IP addresses of A and B are Anded with the subnet mask of Host A, and the results can be seen:
1. If the results are the same, it means that the two hosts are in the same network segment, so that A can find B's MAC address through ARP broadcast, and B can also find A's MAC address to realize normal communication.
2. If the results are different, the ARP broadcast will end at the local gateway. At this time, A will send the data packet sent to B to the local gateway first, and the gateway will query the routing table according to the IP address of the B host, and then continue to pass the data packet Forward, and finally reach destination B.
The gateway of the computer is the exit to other network segments, which is the IP address of the router interface. The IP address used by the router interface can be any address in the network segment, but usually the first available address or the last available address of the network segment is used. This is to avoid as much as possible with the host address in this network segment. conflict.
In the example of the following topology diagram, A and B, C and D, can communicate directly with each other (all belong to the same network segment, without going through the router), but A and C, A and D, B and C, B and D They do not belong to the same network segment, so they communicate through the local gateway, and then the router searches the routing table for the direct route that matches the IP address of the other side according to the IP address of the other side, and then forwards it from the other side gateway interface Realize interconnection.
5. Classification of subnet mask
①, the default subnet mask
Also called the default subnet mask, that is, if the subnet is not divided, the bits of the corresponding network number are all set to 1, and the host number is set to 0.
IP address without subnetting: network number + host number
Default subnet mask of Class A network: 255.0.0.0, expressed as /8 by CIDR
Default subnet mask of Class B network: 255.255.0.0, expressed as /16 by CIDR
The default subnet mask of class C network: 255.255.255.0, expressed as /24 by CIDR
②, custom subnet mask
After dividing a network into subnets, part of the original host number position is given to the subnet number, and the rest is the host number for the subnet. Its form is as follows:
IP address after subnetting: network number + subnet number + subnet host number
Give a chestnut:
For example: 192.168.1.100/25, its subnet mask means: 255.255.255.128
This means that the highest 1 bit of the host bits in the 192.168.1.0 network segment is divided into subnets. The subnetting will be discussed in the next article, so I won't explain it here.
6. The relationship between subnet mask and IP address
The subnet mask is used to judge whether the IP addresses of any two hosts belong to the same network. It is the AND operation of the IP addresses of both hosts and the subnet mask of your own host. If the result is the same network, you can directly Communication.
And bitwise AND operation:
And operation is a basic logical operation method in computers, and the symbol is expressed as &, and can also be expressed as and.
The two data participating in the calculation are ANDed by binary bits.
Operation rules: 0&0=0; 0&1=0; 1&0=0; 1&1=1;
That is: the two bits are "1" at the same time, the result is "1", otherwise it is 0
How to calculate the network address based on the IP address and subnet mask:
①. Convert the IP address and subnet mask into binary numbers.
②. The binary form of the IP address and the subnet mask are ANDed.
③. Convert the obtained result into decimal system to get the network address.
Network address calculation tips: do the AND operation of the IP address and the subnet mask, and directly reset the host bit of the IP address to 0 to quickly get the network address. So as long as you see the IP address and subnet mask, you can immediately confirm the network address.
2. CIDR and VLSM
After understanding and mastering the knowledge of the subnet mask, we need to add CIDR and VLSM here. For the subnet division we will describe in the next part, it is simply an enlarged trick!
1. Class and classless networks, supernets and subnets
Let us first understand these concepts, which are very useful for CIDR, VLSM, and subnetting.
◆ Classy network: also called main class network or standard network, it refers to the class A, class B, and class C IP that can be attributed to the IP address, using the standard default subnet mask.
◆ Classless network: Compared with the classful network, the mask of the classless network IP address is variable. On the basis of the classful network, a part of the host ID is used as the subnet ID.
◆ Supernetting: Combining multiple small networks into a large network is called SuperNetting. It can also be said that the subnet mask length is less than the corresponding classy network is called SuperNetting.
◆ Subnet: A classful network is divided into smaller networks called subnets. It can also be said that a subnet whose length is greater than the corresponding classful network is called a subnet.
2. CIDR classless inter-domain routing
CIDR (Classless Inter-Domain Routing, classless inter-domain routing) essentially eliminates the traditional concept of class A, class B, and class C addresses and subnetting, and aggregates multiple address blocks to create a larger network , Thereby including more hosts.
Take a chestnut: How much is the subnet mask 255.255.255.192 in CIDR?
①. The first thing to confirm is that this is a class C network address (the default subnet mask of class C is 255.255.255.0)
②. The first three bytes are all 255, and they are all 1 when converted to binary, that is, 11111111.11111111.11111111, that is, 24-bit 1.
③. The next byte is 192, converted into binary to 11000000, that is, 1 occupies 2 bits.
④ The subnet mask occupies 26 bits 1, so it is expressed as /26 by CIDR.
⑤. If the network address is 192.168.10.0, plus CIDR, the final expression is 192.168.10.0/26.
CIDR supports route aggregation, which can combine many routing entries in the routing table into a smaller number, so it can limit the increase of the routing table in the router, reduce route advertisements, and reduce the burden on the router.
Remarks: There is a doubt here. According to this definition, VLSM: The subnet mask moves to the right, and the netmask increases. The C type address mask is 24 bits, the example uses 26 bits, it is shifted to the right, not CIDR, but VLSM
3. VLSM variable length subnet mask
VLSM (Variable Length Subnet Mask, variable length subnet mask) specifies the ability to include multiple subnet masks in a class (A, B, C) network, and to subnet a subnet Ability.
Each IP address contains two parts: network number and host number. In a classful network, the 32-bit IP address is divided into 4 segments, each segment represented by 8 bits. This makes the prefix of the network number must be 8 bits, 16 bits or 24 bits. When the network number is 24 bits, the host number has only 8 bits, that is to say, the smallest address block that can be allocated is 256 (2^8=256, and the actual host address that can be allocated is reduced by two. One is a network address, one is a broadcast address, and finally 254), this number is not enough for most enterprises.
When the IP address block larger than this is 16 bits, the address block that can be allocated at this time is 65536 (2^16=65536), which is too much for most companies. This leads to a large amount of waste of IP addresses no matter which type of network the company chooses.
If the IP address is only classified by class (A, B, C), it will cause a lot of waste or not enough. The birth of VLSM effectively solves this problem. On the basis of a classful network, by subdividing the host number of the IP address, a part of the network number can be divided into various types of networks. The network number is no longer limited to the numbers of 8, 16, and 24 bits, but a flexible size.