当前位置:网站首页>Code farmers should also understand the IPv4 subnet division of point networks
Code farmers should also understand the IPv4 subnet division of point networks
2022-06-24 22:33:00 【Zhuge iron and steel cloud】
The original author : A promise CTO
CTO Daily reference wechat official account
Link to the original text : https://mp.weixin.qq.com/s/qViFY0VTaRwUMcMWC9adhQ
stay IP In the world of , Mask is a very important concept , Make an inappropriate metaphor :IP The relationship between address and mask is like that between person and shadow , Unmasked IP It doesn't work .
current IPv4 The address is a 32 bit The integer of , In a computer, a long integer variable can be used to express . Value range :0~4294967295(2^32-1). For the human brain , Whether it is expressed in decimal or binary 32 bit Is not a good method . therefore ,IPv4 Addresses are usually expressed in dotted decimal . Here is the same IP Address :122.70.156.25 Different representations of :
dotted decimal :122.70.156.25
Decimal system : 2051447833
Binary system : 01111010.01000110.10011100.00011001
Obviously fractional decimal is easier to remember .
IP The address is divided into two parts , Network address ( Also known as “ Prefix ”) And host address . It's like our postal address , for example : Chang an avenue 10 Number , In this address , Chang'an Street is equivalent to IP The network address in the address ,10 No. is equivalent to IP Host address in address , The two add up to an address that clearly describes a place .
Mask and IP Equal length , It's also 32 bit The integer of , It is mainly used to distinguish IP Network address and host address in the address , From left to right , Part of the network address is full 1, Part of the host address is full 0, And then IP Address and mask are performed bit by bit “ And ” operation , namely :1 & 1 = 1,1 & 0 = 0.
From this we can get :
Formula 1 : network address = IP Address & Mask
Formula 2 : The host address = IP Address – network address
Masks are usually described in terms of mask length , such as , The mask length is 24 Then it means mask :255.255.255.0, The principle is that every 255 Are equal to binary 8 A continuous 1, namely :11111111.3 individual 255 together , Equivalent to 24 A continuous 1. Similarly, the mask length is 25 Then it means mask :255.255.255.128, front 3 individual 255 amount to 24 individual 1, Next to it 128 It's binary 10000000, Just like the one in front 24 individual 1 Together make up 25 individual 1.
From this we can get :
Formula 3 : The network contains IP Number of addresses = 2 ^ (32- Mask length )
meanwhile IP Provisions of the agreement , The last of each network segment IP The address is the broadcast address of the network segment , That is, the host address part is all 1 The address of . Network address and advertising address cannot be assigned to the host for use .
From this we can get :
Formula four : The network contains available ( Distribute )IP Number of addresses = 2 ^ (32- Mask length ) – 2
Apply the above formula , We get IP Address :192.168.100.100/255.255.255.0 The network address of is 192.168.100.0, The host address is 100, The network segment has 2 ^ ( 32 – 24 ) = 2 ^ 8 = 256 individual IP Address , Remove the network address and broadcast address , There are also available IP Address 256-2 = 254 individual .
Above is IP And mask , The following is how to control and divide subnets through masks , This is also IP The essence of planning …
As I said before ,IP Address includes network address and host address , In fact, through the control of mask , It can realize the hierarchical network address , That is, the concept of subnet .
Please look at this IP Address : Beijing . Xicheng district . Chang an avenue .10 Number /255.255.255.0, Through the mask, we know that IP My network address is :“ Beijing . Xicheng district . Chang an avenue .0”. Now let's set the mask to :255.255.0.0, Then the network address becomes :“ Beijing . Xicheng district .0.0”, Obviously the former is part of the latter , That is to say, the former is a subnet of the latter . If you will , You can adjust the mask to :255.0.0.0, So the network address becomes :“ Beijing .0.0.0” It can be used to express the whole of Beijing .
So we get this hierarchical IP The Internet :
Beijing .0.0.0 / 8
Beijing . Xicheng district .0.0 / 16
Beijing . Xicheng district . Chang an avenue .0 /24
Beijing . Xicheng district . Fuyou Street .0 /24
Beijing . Dongcheng District .0.0 /16
…….
Empathy , Replace the above ground with numbers to get :
192.0.0.0 / 8
192.168.0.0 / 16
192.168.100.0 /24
192.168.200.0 /24
192.169.0.0 /16
…….
It can be seen that , The division of subnets , Nothing more than adjusting the size of the network address by controlling the length of the mask , The following is an example of subnet partition .
A provincial company of a unit applies for a network segment from the headquarters 10.100.0.0/16, Provincial companies have branches in every prefecture and city , One 13 Branches . Now it is required that each prefecture and city should distribute the , The provincial company shall properly retain some IP.
specific working means :
13 Branches + Provincial company , altogether 14 Net segment ,8<14<16, Therefore, it is necessary to divide into 16 Share (2^4);
The length of the parent network segment mask is 16, Then this network segment contains 2^(32-16)= 65536 An address , All are divided into 16 Subnet , Then each subnet contains 65536 / 16 = 4096 individual IP The earth ;
4096 = 2^12, So the subnet mask is 32-12=20; meanwhile 4096 Expressed in dotted decimal as :0.0.16.0
in summary , Get the following subnet list :
10.100.0.0/20 10.100.16.0/20 10.100.32.0/20 10.100.48.0/20
10.100.64.0/20 10.100.80.0/20 10.100.96.0/20 10.100.112.0/20
10.100.128.0/20 10.100.144.0/20 10.100.160.0/20 10.100.176.0/20
10.100.192.0/20 10.100.208.0/20 10.100.224.0/20 10.100.240.0/20
We can see , The latter subnet is added to the former subnet “0.0.16.0”. Here we are , We can assign the first three network segments to provincial companies , be left over 13 Network segments are allocated to branches . The branch office gets IP after , You can also continue to subdivide . for example , A branch office got the address :10.100.160.0/20, It can be further divided into :10.100.160.0/22,10.100.164.0/22,10.100.168.0/22,10.100.168.0/22 Four network segments .
Reference resources
IPV4 And subnet partition _ Xiao Lu's blog -CSDN Blog _ipv4 Subnet partition
边栏推荐
- New features of go1.18: efficient replication, new clone API for strings and bytes standard library
- NIO多路复用之Selector的使用
- NIO、BIO、AIO
- first-order-model实现照片动起来(附工具代码) | 机器学习
- String exercise summary 2
- 【软件工程】期末重点
- 堆內存分配的並發問題
- Description of software version selection of kt6368a Bluetooth dual-mode transparent chip
- Learning notes 23-- basic theory of multi-sensor information fusion (Part I)
- YGG recent game partners list
猜你喜欢

The ktp900f mobile download program of the fail safe mobile panel prompts that the download cannot be performed, and the target device is running or not in the transmission mode

DAO 中常见的投票治理方式

ansible基本配置

字符串习题总结2

Principles of Ethernet port mirroring, link aggregation and VLAN Technology

Genesis公链与美国一众加密投资者齐聚Consensus 2022

In the multi network card environment, the service IP registered by Nacos is incorrect, resulting in inaccessible services

Future development of education industry of e-commerce Express

HTTP的缓存控制

Yyds dry goods inventory junit5 learning II: assumptions class
随机推荐
first-order-model实现照片动起来(附工具代码) | 机器学习
Firewall working principle and detailed conversation table
Selection and comparison of message oriented middleware MQ
60 divine vs Code plug-ins!!
系统测试主要步骤
How to automatically remove all . orig files in Mercurial working tree?
Genesis公链与美国一众加密投资者齐聚Consensus 2022
Huada 04A operating mode / low power consumption mode
Principles of Ethernet port mirroring, link aggregation and VLAN Technology
Idea close global search box
In the first year of L2, arbitrum nitro was upgraded to bring more compatible and efficient development experience
OA system -- save the verification code to session
Huada 4a0gpio settings
Embedded development: tips and tricks -- clean jump from boot loader to application code
字符串习题总结2
Certificate photo processing
短视频商城系统,scroll-view如何自适应页面剩余高度
A pit in try with resources
The logic of "Ali health" has long changed
leetcode:515. 在每个树行中找最大值【无脑bfs】