IP subnet division, which is a headache for network workers, is actually as simple as that

Good afternoon, my network worker friend.

Recently, the Internet worker group is still as lively as ever, with heated discussions about the industry, technology, and workplace.

Some time ago, a group of friends chatted about subnetting in it, and a few network workers friends who didn’t understand came to chat with Mr. Yang privately, expressing their desire to add more knowledge in this area.

After looking at it, I can indeed add more points about the content of this aspect.

Subnetting technology is actually a key and difficult point in the foundation of computer networks. Today I will give you an article, a detailed explanation of IP subnetting VLSM.

Today's article reading benefits: "National Internet Workers Exchange Group Entrance Quota (Limited Time Open)"

Mr. Yang’s network worker exchange group is about to break 100+. Do you want to chat about technology, industry, workplace or go to work in the group?

Private message me, send the password "Join the group", the top 30 friends who private message will be eligible to join the group.

01 What is an IP address

Old rules, let me tell you a wave of theoretical foundation first.

An IP address is used to identify a node (or interface on a network device) in a network.

The addressing of data packets in IP networks is based on IP addresses, so IP addresses are like addresses in real life.

The IP protocol defines the format of the data packet and also defines the addressing method of the data packet. At present, there are mainly two versions of IP commonly used in our business environment :

IPv4 and IPv6 .

At this stage, the main body of the network is still IPv4, but in the foreseeable future, it will gradually transition to IPv6. Today only IPv4 is introduced.

An IPv4 address has 32 bits (in binary format).

Of course, it is impossible for us to write IPv4 addresses in binary, which is inefficient. We usually use decimal format to write IP addresses, but when computers perform calculations related to IP addresses, they undoubtedly do so in binary form.

Therefore, it is necessary to master the number system conversion from decimal to binary.

IPv4 addresses are usually expressed in "dotted decimal" to adapt to human reading and writing habits, such as 192.168.1.1.

02 Conversion between decimal and binary

The "dotted decimal" representation of IP addresses can help us use the network better, but network devices use binary operations when calculating IP.

For example:

The following is the number 192, and the corresponding binary algorithm, so I won’t go into details here, this is a basic skill.

03 Classification of IP addresses

The IPv4 address space ranges from 0.0.0.0 to 255.255.255.255 . If such a huge space is not differentiated and planned, it is bound to be inconvenient for overall management.

Therefore, we classify the IPv4 address space into five categories:

The distinction between the types of addresses is mainly reflected in the first octet (an IP address has 4 octets):

The first octet is always 0, then we get a range:

1.0.0.0 all the way to 127.255.255.255.

This is a class A address, where 127.0.0.0/8 is used as a local loopback. For example, if you ping 127.0.0.1, you are actually pinging the local machine.

So if you see an IP whose first octet falls in the range 1-126, then it's a class A address.

The highest two digits of the first octet are constant at 10, and an interval is obtained:

128.0.0.0-191.255.255.255, which is a class B address.

The highest three bits of the first octet are constant at 110, and an interval is obtained:

192.0.0.0 – 223.255.255.255, which is a class C address.

The highest four bits of the first octet are constant at 1110, and an interval is obtained:

224.0.0.0 – 239.255.255.255, this is a class D address, this class of address is specially used for multicast.

The rest are Class E addresses, which are reserved for research use.

04 Netmask Netmask

An IP address consists of two parts: the network part and the host part.

The network part is used to indicate the "space" in which the IP address is located. For a router, when addressing data packets, it usually only cares about the network part of the IP address.

So how do you distinguish the network and host parts of an IP address?

Naturally, it is a network mask (netmask for short), which is used to correspond to an IP address, thereby identifying the network and host parts of the IP address.

● The network mask is 32 bits, which is the same as the number of bits in an IPv4 address.

● The binary representation of the netmask is a bunch of consecutive 1s followed by consecutive 0s.

● A bit with a network mask value of 1 corresponds to the network bit in the IP address; a bit with a value of 0 corresponds to the host bit in the IP address, so as to help us identify the network and host bits in an IP address, as shown in the figure below:

For the convenience of writing, we often use the mask length to represent an IP address + mask:

192.168.1.1 255.255.255.0 is equivalent to 192.168.1.1/24.

Because 255.255.255.0 is written in binary, there are 24 1s from left to right, so we also say that its mask length is 24.

By default, for a class A IP address, the first octet is the network bit, and the other bits are the host bit, so the default mask of the class A address is 255.0.0.0, or the length is /8.

The first two octets of a class B IP address are network bits, and the last two octets are host bits, so the default mask of a class B address is 255.255.0.0 or /16.

The first three octets of a class C address are network bits, and the last octet is a host bit, so the default mask of a class C address is 255.255.255.0, or /24.

From here we can see that if you apply for a Class A address space:

123.0.0.0/8, then this is a rather large address space, because this space has 2 to the 24th power of IP addresses.

In contrast, a class B IP network address space has 2 to the 16th power of IP addresses by default, while class C addresses are less.

05 IP address type

Here are the three types below.

● Network address:

Identifying a network is equivalent to a concept of "face". It is an address with all 0 host bits in an IP address. For example 192.168.10.0/24.

● Broadcast address:

A special address used to send data to all hosts on the network. The broadcast address is the address in which all the bits of the host part are 1. For example 192.168.10.255/24.

● Host address:

An address that can be assigned to an end device in a network. For example 192.168.10.1/24 to 192.168.10.254/24.

Example: 192.168.1.0 What are the network number, broadcast number and assignable IP of this Class C network?

06 Why divide subnets

Suppose you have a class B address: 172.16.0.0, since the default mask of class B address is 255.255.0.0, it means that there are 216 addresses in this network.

And the IP addresses that can be assigned to PCs have 2 to the 16th power -2 so many IPs, why subtract 2?

Because the broadcast address and network number cannot be assigned to the PC.

Imagine if you really have so many PCs, so many IP addresses are in the same network, the same network segment, and the same broadcast domain, as shown in the figure above.

Then once a broadcast occurs in the network, the impact will be great.

Furthermore, in the actual business environment, we often divide a business unit into a network segment, and different business units have different network segments.

So if you have 10 business units, and each business unit only has hundreds of devices, one business unit consumes one class B address, which causes a waste of address space.

Therefore, we propose the concept of subnetting. The term for subnetting is called VLSM (Variable Length Subnet Mask, variable length subnet mask). In fact, it is a trick with the subnet mask.

In the above figure, we have five network segments and need five IP address segments.

And if you only have one class B address (172.16.0.0/16) available, you can divide this class B address into smaller subnets by subnetting.

In this way, a huge broadcast domain can be divided into small units, and the use of IP addresses is more scientific and reasonable.

07 How to divide the subnet

Now suppose we have a class B address: 172.16.0.0/16.

By default, this class B address has a mask of 255.255.0.0, with the first two octets being the network bits and the last two octets being the host bits.

Then in this single network, there are 2 to 16 IP addresses, as shown in the figure above, which is very large.

Now, the original 16-bit network bit is "borrowed" from the host bit, so that the network bit is expanded to 17 bits, and the corresponding host bit becomes 15 bits.

Then the borrowed bit is the subnet bit , as shown in the figure above.

Since we borrowed this bit, the mask changes from the default 255.255.0.0 to 255.255.128.0 or /16 to /17.

So from the original large network segment of only 172.16.0.0/16, it now has two smaller network segments of 172.16.0.0/17 and 172.16..128.0/17.

This is subnetting.

It is important to pay attention to the role the netmask plays in this process.

Next, I will tell you about two cases of subnetting.

08 Subnetting - Case 1

Now there is an IP address: 192.168.1.0, which is a class C address, and the default mask is /24.

I want to subnet it, and borrow a bit from the host as the subnet bit, that is, the mask becomes /25, so how many subnets can I get?

What is the network number of each subnet? What is the broadcast number for each subnet? What are the available IPs per subnet?

Proceed as follows:

01 Determine the category and find the default mask

First of all, this is a class C address, so the default mask length is /24, you can draw a vertical line to help the calculation. The left side of the line is the network bit, and the right side is the host bit, as shown in the figure above.

02 Change the mask and find the subnet

On the basis of the original /24 mask, one bit is borrowed from the host, and the mask becomes /25.

The borrowed bit is the subnet bit. As shown in the figure above, we only need to move the dotted line to the right by one space.

This subnet bit is either 0 or 1, two possibilities.

This creates two subnets (2 to the power of 1). When the subnet bit is 0, the resulting network number is 192.168.1.0/25, and when the subnet bit is 1, the network number of another subnet is 192.168. 1.128/25.

As shown below:

03 Get the broadcast number

The broadcast numbers of subnet 1 and subnet 2 are listed above, which is actually very simple, just set all the host bits of each subnet to 1.

Therefore, the broadcast number of subnet 192.168.1.0/25 is 192.168.1.127; the broadcast number of subnet 192.168.1.128/25 is 192.168.1.255;

04 Get the number of available IP addresses for each subnet

After the above calculation, the network number and broadcast number of subnet 1 and subnet 2 are obtained, then the available IP address of each subnet will come out, because the available IP is actually the network number and broadcast number of the subnet Those IPs sandwiched between.

So in fact, we use a variable-length subnet: /25 for the class C address of 192.168.1.0, that is, borrow 1 bit from the host to generate 2 subnets, and each subnet has 126 available IP addresses.

Here is a formula:

09 Subnetting - Case 2

Suppose now you have an IP address: 192.168.1.64/27, and want to configure this address on a PC, is it feasible?

The default mask is /24, and the new mask is /27, so the network bit borrows 3 bits from the host bit, resulting in 8 subnets, each with 30 available IP addresses;

The corresponding size of each subnet block is 32, which is 2 to the 5th power (5 is the number of remaining host bits).

Now start to list each subnet, and it turns out that the IP address 192.168.1.64/27 is actually the network number of a subnet.

Since it is a network number, of course it cannot be assigned to a PC.

Finishing: Lao Yang 丨 10-year senior network engineer, more network workers to improve dry goods, please pay attention to the official account: Network Engineer Club

Guess you like

Origin blog.csdn.net/SPOTO2021/article/details/132081723