当前位置:网站首页>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
边栏推荐
- Publicity of the second batch of shortlisted enterprises! Annual Top100 smart network supplier selection
- Concurrency of heap memory allocation
- Information update on automatic control principle
- 代理模式详解
- Embedded development: tips and tricks -- clean jump from boot loader to application code
- 学习笔记23--多传感器信息融合基础理论(上)
- Problèmes de concurrence dans l'allocation de mémoire en tas
- Idea global search replace shortcut key
- Ansible basic configuration
- Description of software version selection of kt6368a Bluetooth dual-mode transparent chip
猜你喜欢
随机推荐
Redis hop table
如何抓手机的包进行分析,Fiddler神器或许能帮到您!
NiO, bio, AIO
DAO 中常见的投票治理方式
VRRP skills topic
Publicity of the second batch of shortlisted enterprises! Annual Top100 smart network supplier selection
Ideal L9, new trend of intelligent cockpit
New features of go1.18: efficient replication, new clone API for strings and bytes standard library
无心剑汉英双语诗003. 《书海》
如何提取网页中的日期?
Web攻击之CSRF和SSRF
Disk structure
Chapter 10 project communication management
Docker installs MySQL 8.0. Detailed steps
Process communication mode
Zero code can apply data visualization to enterprise management
Raspberry pie preliminary use
Firewall working principle and detailed conversation table
Uncover the secret of station B. is it true that programmers wear women's clothes and knock code more efficiently?
字符串习题总结2








