Article with you to understand what is the subnet mask

What is the subnet mask

The subnet mask represents the partitioning scheme between the "+ subnet number network number" and host number.

Very obscure?

He said subnet mask, we must first talk about the IP address.

What is an IP address

Each host or router ports on the Internet must have a unique IP address. Because IP addresses on the network that we can recognize each other, we can exchange accurate information or resources.

IP address is divided into IPV6 addresses and IPV4 address, the most widely used is IPV4 address, where we first discussion of IPV4 addresses.

IPV4 address is a 32-bit binary number, i.e. four bytes , is generally employed in dotted decimal notation , i.e. each byte expressed as a decimal. 1 byte = 8 bits, each byte may represent a decimal range of 0 to 255.

IPV4 address is divided into two parts, namely a network number and host number. Determines the length of the entire network number can accommodate many Internet network, host number length determines how many hosts (number ip) each network can accommodate.

Network number Host number

IPV4 address has been classified into A, B, C, D, E class address
Here Insert Picture Description

  • Class A addresses the network account number 1 byte , 3 bytes representing host number. Fixed network number of the most significant bit is 0, i.e. there are 7 bits can be used to identify the network, i.e. 2 ^ 7 = 128 network numbers. 127 and 0, respectively, present as an identifier and a network address of loopback test, the network may assign the actual numbers are 128-2 = 126. Because the host No. 3 bytes, so a 24-bit binary, i.e. 2 ^ 24, the host network address representative of the whole number 0, represents the whole broadcast address corresponding to all hosts on the network, ie, the actual number may be assigned to the host a bit 2 ^ 24-2
  • B类地址的网络号占2字节,主机号占另外2字节。网络号字段中最高两位固定为10。网络号字段中只有14位可供使用。但实际上B类网络地址128.0.y.z 是不指派的,因此实际可指派的B类网络号共有2^14-1=16383个。在每个B类网络中,同样要考电的和全1这两个特殊的IP地址,因此每个B类子网包含20 ^16 -2=65 534个可用IP地址
  • C类地址的网络号占3字节,主机号占剩余的1字节。网络号字段中最高三位留因此网络号字段中有21位可供使用。而192.0.0.z 通常也不指派给因特网上的主机他指派的C类网络号共有2^21 -1=2097151个,每个C类子网只能包含2 ^8=254个可IP地址。
  • D类地址并不用于标识主机或网络,而是用于多播信息的传输。最高四位为1110,其余28位不再划分网络号和主机号。
  • E类地址最高5位是11110,保留未用。
网络类别 可用网络数目 第一个可用的网络号 最后一个可用的网络号
A 126 1 126
B 16383 128.1 191.255
C 2097151 192.0.1 223.255.255

通过上面的分析,我们可以看到ip地址是有限的。而且这么用的话有两个问题:

  • IP地址利用率过低。 拿A类地址来说,一个A类地址可包含1600万主机,根本不可能把1600万主机用在一个网络中。
  • 网络号-主机号这样的两级IP地址不够灵活。 有些情况下,用户希望在网络中划分新的网络出来,例如一个公司有一栋办公楼,它想给每一层都设置一个网络。

所以我们要划分子网!

划分子网

就是从主机号里借几位来当标识子网。当然这样主机号位数就少了,但是,也足够用了。

这样一个ip地址就可以划分为多个子网络来用,大大的提高了IP地址的利用率。

这时候回顾概念,子网掩码代表了“网络号+子网号”与主机号之间的分割方案。
子网掩码中对应网络号和子网号的二进制位为1,主机号为0,由此可知,A类网络的默认子网掩码是255.0.0.0,B类网络的默认子网掩码是255.255.0.0,C类网络的默认子网掩码是255.255.255.0。
子网掩码也可以用点分十进制来表示,例如:

11111111 11111111 11111111 00000000

就可以用255.255.255.0来表示。

假如给定IP地址位206.95.106.130,子网掩码为255.255.255.192,子网掩码换算为二进制就是

11111111 11111111 11111111 11000000

我们可以判断出这是个C类地址,C类地址网络号的范围是192.0.1~223.255.255,所以130对应的主机号+网络号,因此子网号占用了2位

如何获取子网的网络地址呢?

将子网掩码与IP地址相与就可以。

所以如果要判断两个IP地址是否在同一个子网中,只需要讲过两个IP地址与其对应的子网掩码做运算。

习题练习

例如:

主机一

IP地址"222.21.160.6即:11011110.00010101.10100000.00000110

子网掩码:255.255.255.192即:11111111.11111111.11111111.11000000

按位逻辑与运算结果为:11011110.00010101.10100000.00000000

十进制形式为(网络地址):222.21.160.0
主机二

IP Address : 222.21.160.73 namely: 11011110.00010101.10100000.01001001

Subnet Mask : 255.255.255.192 namely: 11111111.11111111.11111111.11000000

Bitwise logical AND operation result: 11011110.00010101.10100000.01000000

Decimal form (network address): 222.21.160.64

Analyzing the top three Class C addresses are the same, to determine whether the two IP addresses in the same network segment, but the present embodiment is not 222.21.160.73 222.21.160.6 with the same network segment, because the Class C IP addresses has two do a subnetting can not only determine whether the first three bytes of the same two IP to confirm whether the same network segment.

Which 222.21.160.6 in 222.21.160.1-222.21.160.62 segment, 222.21.160.73 in 222.21.160.65-222.21.160.126 segment, not in the same network segment, if you want to communicate needs to be forwarded through the router.

A host IP address 202.97.47.69, subnet mask is 255.255.255.240, the network address of the network in which it is seeking to ___________

The answer 202.97.47.64

Speak ip address and subnet mask is converted to binary phase can be.

Published 200 original articles · won praise 99 · views 40000 +

Guess you like

Origin blog.csdn.net/weixin_43889841/article/details/103514829