|
查看: 5150|回复: 12
|
Subnet Mask是如何算出来??
[复制链接]
|
|
|
各位大哥大姐,subnet Mask 到底是如何算出来的,我看了很多google,
但是百思不解。。。希望各位可以简易的翻译。。。在此感激不尽! |
|
|
|
|
|
|
|
|
|
|
发表于 21-4-2011 06:02 PM
|
显示全部楼层
在LAN里,MS给的Subnet Mask是看你的Private IP Address。Class A (10.0.0.0-10.255.255.255)的Subnet Mask Default是255.0.0.0,Class B(172.16.0.0-172.31.255.255)255.255.0.0,Class C(192.168.0.0-192.168.255.255)255.255.255.0。
其他高手帮忙补充~ |
|
|
|
|
|
|
|
|
|
|
发表于 22-4-2011 12:58 AM
|
显示全部楼层
IPv4 subnetting
The process of subnetting involves the separation of the network and subnet portion of an address from the host identifier. This is performed by a bitwise AND operation between the IP address and the (sub)network prefix. The result yields the network address or prefix, and the remainder is the host identifier.
[edit] Determining the network prefix
An IPv4 network mask consist of 32 bits, a sequence of ones (1) followed by a block of 0s. The last block of zeros (0) designate that part as being the host identifier.
The following example shows the separation of the network prefix and the host identifier from an address (192.168.5.130) and its associated /24 network mask (255.255.255.0). The operation is visualized in a table using binary address formats.
Binary form Dot-decimal notation
IP address 11000000.10101000.00000101.10000010 192.168.5.130
Subnet mask 11111111.11111111.11111111.00000000 255.255.255.0
Network prefix 11000000.10101000.00000101.00000000 192.168.5.0
Host part 00000000.00000000.00000000.10000010 0.0.0.130
The mathematical operation for calculating the network prefix is the binary and. The result of the operation yields the network prefix 192.168.5.0 and the host number 130 of a possible maximum of 256 addresses.
[edit] Subnetting
Subnetting is the process of designating some high-order bits from the host part and grouping them with the network mask to form the subnet mask. This divides a network into smaller subnets. The following diagram modifies the example by moving 2 bits from the host part to the subnet mask to form a smaller subnet one fourth the previous size:
Binary form Dot-decimal notation
IP address 11000000.10101000.00000101.10000010 192.168.5.130
Subnet mask 11111111.11111111.11111111.11000000 255.255.255.192
Network prefix 11000000.10101000.00000101.10000000 192.168.5.128
Host part 00000000.00000000.00000000.00000010 0.0.0.2
[edit] Special addresses and subnets
Internet Protocol version 4 uses specially designated address formats to facilitate recognition of special address functionality. The first and the last subnets obtained by subnetting have traditionally had a special designation and, early on, special usage implications.[5] In addition, IPv4 uses the all ones host address, i.e. the last address within a network, for broadcast transmission to all hosts on the link.
[edit] Subnet zero and the all-ones subnet
The first subnet obtained from subnetting has all bits in the subnet bit group set to zero (0). It is therefore called subnet zero.[6] The last subnet obtained from subnetting has all bits in the subnet bit group set to one (1). It is therefore called the all-ones subnet.[7]
The IETF originally discouraged the production use of these two subnets at one point due to possible confusion of having a network and subnet with the same address.[8] The practice of avoiding subnet zero and the all-ones subnet was declared obsolete in 1995 by RFC 1878, an informational, but now historical RFC.[9]
[edit] Subnet and host counts
The number of subnetworks available, and the number of possible hosts in a network may be readily calculated. In the example (above) two bits were borrowed to create subnetworks, thus creating 4 (22) possible subnets.
Network Network (binary) Broadcast address
192.168.5.0/26 11000000.10101000.00000101.00000000 192.168.5.63
192.168.5.64/26 11000000.10101000.00000101.01000000 192.168.5.127
192.168.5.128/26 11000000.10101000.00000101.10000000 192.168.5.191
192.168.5.192/26 11000000.10101000.00000101.11000000 192.168.5.255
The RFC 950 specification reserves the subnet values consisting of all zeros (see above) and all ones (broadcast), reducing the number of available subnets by two. However, due to the inefficiencies introduced by this convention it was abandoned for use on the public Internet, and is only relevant when dealing with legacy equipment that does not implement CIDR. The only reason not to use the all-zeroes subnet is that it is ambiguous when the prefix length is not available. All CIDR-compliant routing protocols transmit both length and suffix. RFC 1878 provides a subnetting table with examples.
The remaining bits after the subnet are used for addressing hosts within the subnet. In the above example the subnet mask consists of 26 bits, leaving 6 bits for the host identifier. This allows for 64 combinations (26), however the all zeros value and all ones value are reserved for the network ID and broadcast address respectively, leaving 62 addresses.
In general the number of available hosts on a subnet is 2n−2, where n is the number of bits used for the host portion of the address.
RFC 3021 specifies an exception to this rule when dealing with 31-bit subnet masks (i.e. 1-bit host identifiers). In such networks, usually point-to-point links, only two hosts (the end points) may be connected and a specification of network and broadcast addresses is not necessary.
A /24 network may be divided into the following subnets by increasing the subnet mask successively by one bit. This affects the total number of hosts that can be addressed in the /24 network (last column).
CIDR notation Network mask Available
subnets Available
hosts per subnet Total
usable hosts
/24 255.255.255.0 1 254 254
/25 255.255.255.128 2 126 252
/26 255.255.255.192 4 62 248
/27 255.255.255.224 8 30 240
/28 255.255.255.240 16 14 224
/29 255.255.255.248 32 6 192
/30 255.255.255.252 64 2 128
/31 255.255.255.254 128 2 * 256
*only applicable for point-to-point links |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 22-4-2011 02:52 PM
|
显示全部楼层
oh no...... any where... thanks!!! |
|
|
|
|
|
|
|
|
|
|
发表于 22-4-2011 04:20 PM
|
显示全部楼层
回复 3# 840812145195
要帮人解释,也请拿出诚意点。 |
|
|
|
|
|
|
|
|
|
|
发表于 22-4-2011 07:34 PM
|
显示全部楼层
本帖最后由 840812145195 于 22-4-2011 07:37 PM 编辑
oh no...... any where... thanks!!!
volrite 发表于 22-4-2011 14:52 
好吧。。我就试下解释在华语吧。。。有错不好插哦。。。。。
通常subnet的算是这样的
24/ 255.255.255.0 这一行的subnet是24bit , 一个255就等于8个bit,在8个bit里面怎样形成 255。。。他的算法就是 1+2+4+8+16+32+64+128=255
1 1 1 1 1 1 1 1
每一个1就等于1个bit.
假如这个ip是 : 192.168.10.1 /24 就等于
128+64+32+16+8+4+2+1
11000000 。 10101000。 00001010。 00000001
128+64=192 128+32+8=162 8+2=10 1
他的算差不多就是这样算。。本人不大会解释。。。假如解释的不清楚,请原谅。。。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 23-4-2011 11:45 AM
|
显示全部楼层
本帖最后由 volrite 于 23-4-2011 11:56 AM 编辑
其实ip address 我会算啦。。。只不过那些用什么IP来算出配合用什么Subnet Mask!搞到我傻了。。。
没关系啦。。。谢谢各位大哥大。。。 |
|
|
|
|
|
|
|
|
|
|
发表于 23-4-2011 02:17 PM
|
显示全部楼层
IP和子网掩码
我们都知道,IP是由四段数字组成,在此,我们先来了解一下3类常用的IP
A类IP段 0.0.0.0 到127.255.255.255
B类IP段 128.0.0.0 到191.255.255.255
C类IP段 192.0.0.0 到223.255.255.255
XP默认分配的子网掩码每段只有255或0
A类的默认子网掩码 255.0.0.0 一个子网最多可以容纳1677万多台电脑
B类的默认子网掩码 255.255.0.0 一个子网最多可以容纳6万台电脑
C类的默认子网掩码 255.255.255.0 一个子网最多可以容纳254台电脑
我以前认为,要想把一些电脑搞在同一网段,只要IP的前三段一样就可以了,今天,我才知道我错了。如果照我这说的话,一个子网就只能容纳254台电脑?真是有点笑话。我们来说详细看看吧。
要想在同一网段,只要网络标识相同就可以了,那要怎么看网络标识呢?首先要做的是把每段的IP转换为二进制。(有人说,我不会转换耶,没关系,我们用Windows自带计算器就行。打开计算器,点查看>科学型,输入十进制的数字,再点一下“二进制”这个单选点,就可以切换至二进制了。)
把子网掩码切换至二进制,我们会发现,所有的子网掩码是由一串[red]连续[/red]的1和一串[red]连续[/red]的0组成的(一共4段,每段8位,一共32位数)。
255.0.0.0 11111111.00000000.00000000.00000000
255.255.0.0 11111111.11111111.00000000.00000000
255.255.255.0 11111111.11111111.11111111.00000000
这是A/B/C三类默认子网掩码的二进制形式,其实,还有好多种子网掩码,只要是一串连续的1和一串连续的0就可以了(每段都是8位)。如11111111.11111111.11111000.00000000,这也是一段合法的子网掩码。子网掩码决定的是一个子网的计算机数目,计算机公式是2的m次方,其中,我们可以把m看到是后面的多少颗0。如255.255.255.0转换成二进制,那就是11111111.11111111.11111111.00000000,后面有8颗0,那m就是8,255.255.255.0这个子网掩码可以容纳2的8次方(台)电脑,也就是256台,但是有两个IP是不能用的,那就是最后一段不能为0和255,减去这两台,就是254台。我们再来做一个。
255.255.248.0这个子网掩码可以最多容纳多少台电脑?
计算方法:
把将其转换为二进制的四段数字(每段要是8位,如果是0,可以写成8个0,也就是00000000)
11111111.1111111.11111000.00000000
然后,数数后面有几颗0,一共是有11颗,那就是2的11次方,等于2048,这个子网掩码最多可以容纳2048台电脑。
一个子网最多可以容纳多少台电脑你会算了吧,下面我们来个逆向算法的题。
一个公司有530台电脑,组成一个对等局域网,子网掩码设多少最合适?
首先,无疑,530台电脑用B类IP最合适(A类不用说了,太多,C类又不够,肯定是B类),但是B类默认的子网掩码是255.255.0.0,可以容纳6万台电脑,显然不太合适,那子网掩码设多少合适呢?我们先来列个公式。
2的m次方=560
首先,我们确定2一定是大于8次方的,因为我们知道2的8次方是256,也就是C类IP的最大容纳电脑的数目,我们从9次方一个一个试2的9次方是512,不到560,2的10次方是1024,看来2的10次方最合适了。子网掩码一共由32位组成,已确定后面10位是0了,那前面的22位就是1,最合适的子网掩码就是:11111111.11111111.11111100.00000000,转换成10进制,那就是255.255.252.0。
下面又是我原创的哦:
由上面的方法计算得知:你的子网掩码有27位(11111111.11111111.11111111.11100000),网内最大主机数为5位(11111),换算成十进制就是30台主机(也就是有30个IP好分配的咯),那么0-255可以分成几个网段呢........算一下8点多个,当然还要除去子网和广播地址,也就等于八个咯。由此可见你的131.65.12.0/24的IP段可以分为
子网 , 有效的主机
131.65.12.0 , 131.65.12.1 到 131.65.12.30
131.65.12.32 , 131.65.12.33 到 131.65.12.62
131.65.12.64 , 131.65.12.65 到 131.65.12.94
131.65.12.96 , 131.65.12.97 到 131.65.12.126
131.65.12.128 , 131.65.12.129 到 131.65.12.158
131.65.12.160 , 131.65.12.161 到 131.65.12.190
131.65.12.192 , 131.65.12.193 到 131.65.12.222
131.65.12.224 , 131.65.12.225 到 131.65.12.254
当然还有八个广播地址不要忘了哦
广播地址
131.65.12.31
131.65.12.63
131.65.12.95
131.65.12.127
131.65.12.159
131.65.12.191
131.65.12.223
131.65.12.255
以上的IP对应的子网掩码一律是 255.255.255.224
楼主可以自己找一下你所说的IP在那个子网里哦!
http://zhidao.baidu.com/question/48897837.html |
|
|
|
|
|
|
|
|
|
|
发表于 23-4-2011 03:42 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 27-4-2011 04:32 PM
|
显示全部楼层
回复 8# alvinyoong2003
娃哈哈哈哈哈。。。。。我真的很谢你了。。。。我终于会如何运用了。。。非常的感谢你们大家的教导,小弟在这敬礼!!!
 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 27-4-2011 04:40 PM
|
显示全部楼层
那就是说。。如果我的区域网只有30架电脑公用,那我可以subnet mask最小值为255.255.255.224 对吗?
因为我看了书说,应用最小值的subnet mask会使网络传输率较顺畅! |
|
|
|
|
|
|
|
|
|
|
发表于 27-4-2011 05:50 PM
|
显示全部楼层
回复 11# volrite
照理是可以,不过你得考虑你是否需要加新的电脑。 |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 28-4-2011 03:20 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|