中国网管论坛's Archiver

hzf990504 发表于 2008-6-10 17:14

教你如何在一个有500台PC以上的局域网配置IP、子网掩码

[b][color=red][font=Times New Roman]IP[/font][/color][/b][b][color=red][font=宋体]和子网掩码[/font][/color][color=red][/color][/b]
[font=宋体]我们都知道,IP是由四段数字组成,在此,我们先来了解一下[/font][font=Times New Roman]3[/font][font=宋体]类常用的IP[/font]
[font=宋体]  [/font][font=Times New Roman]A[/font][font=宋体]类[/font][font=Times New Roman]IP[/font][font=宋体]段  0.0.0.0 到[/font][font=Times New Roman]127.255.255.255 [/font]
[font=宋体]  [/font][font=Times New Roman]B[/font][font=宋体]类[/font][font=Times New Roman]IP[/font][font=宋体]段 [/font][font=Times New Roman] 128.0.0.0 [/font][font=宋体]到[/font][font=Times New Roman]191.255.255.255 [/font]
[font=宋体]  [/font][font=Times New Roman]C[/font][font=宋体]类[/font][font=Times New Roman]IP[/font][font=宋体]段 [/font][font=Times New Roman] 192.0.0.0 [/font][font=宋体]到[/font][font=Times New Roman]223.255.255.255 [/font]
[font=Times New Roman] [/font]
[font=宋体]  XP默认分配的子网掩码每段只有[/font][font=Times New Roman]255[/font][font=宋体]或[/font][font=Times New Roman]0[/font]
[font=宋体]  A类的默认子网掩码 [/font][font=Times New Roman]255.0.0.0[/font][font=宋体]     一个子网最多可以容纳[/font][font=Times New Roman]1677[/font][font=宋体]万多台电脑[/font]
[font=宋体]  B类的默认子网掩码 [/font][font=Times New Roman]255.255.0.0[/font][font=宋体]    一个子网最多可以容纳[/font][font=Times New Roman]6[/font][font=宋体]万台电脑[/font]
[font=宋体]  C类的默认子网掩码 [/font][font=Times New Roman]255.255.255.0[/font][font=宋体]   一个子网最多可以容纳[/font][font=Times New Roman]254[/font][font=宋体]台电脑[/font]
[font=宋体]  我以前认为,要想把一些电脑搞在同一网段,只要IP的前三段一样就可以了,今天,我才知道我错了。如果照我这说的话,一个子网就只能容纳[/font][font=Times New Roman]254[/font][font=宋体]台电脑?真是有点笑话。我们来说详细看看吧。[/font]
[font=宋体]  要想在同一网段,只要网络标识相同就可以了,那要怎么看网络标识呢?首先要做的是把每段的IP转换为二进制。(有人说,我不会转换耶,没关系,我们用Windows自带计算器就行。打开计算器,点查看[/font][font=Times New Roman]>[/font][font=宋体]科学型,输入十进制的数字,再点一下“二进制”这个单选点,就可以切换至二进制了。)[/font]
[font=宋体]  把子网掩码切换至二进制,我们会发现,所有的子网掩码是由一串[/font][font=Times New Roman][red][/font][font=宋体]连续[/font][font=Times New Roman][/red][/font][font=宋体]的[/font][font=Times New Roman]1[/font][font=宋体]和一串[/font][font=Times New Roman][red][/font][font=宋体]连续[/font][font=Times New Roman][/red][/font][font=宋体]的[/font][font=Times New Roman]0[/font][font=宋体]组成的(一共[/font][font=Times New Roman]4[/font][font=宋体]段,每段[/font][font=Times New Roman]8[/font][font=宋体]位,一共[/font][font=Times New Roman]32[/font][font=宋体]位数)。[/font]
[font=宋体]  [/font][font=Times New Roman]255.0.0.0[/font][font=宋体]   [/font][font=Times New Roman]11111111.00000000.00000000.00000000[/font]
[font=宋体]  [/font][font=Times New Roman]255.255.0.0[/font][font=宋体]  [/font][font=Times New Roman]11111111.11111111.00000000.00000000[/font]
[font=宋体]  [/font][font=Times New Roman]255.255.255.0[/font][font=宋体] [/font][font=Times New Roman]11111111.11111111.11111111.00000000[/font]
[font=宋体]  这是[/font][font=Times New Roman]A/B/C[/font][font=宋体]三类默认子网掩码的二进制形式,其实,还有好多种子网掩码,只要是一串连续的[/font][font=Times New Roman]1[/font][font=宋体]和一串连续的[/font][font=Times New Roman]0[/font][font=宋体]就可以了(每段都是[/font][font=Times New Roman]8[/font][font=宋体]位)。如[/font][font=Times New Roman]11111111.11111111.11111000.00000000[/font][font=宋体],这也是一段合法的子网掩码。子网掩码决定的是一个子网的计算机数目,计算机公式是[/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]m[/font][font=宋体]次方,其中,我们可以把[/font][font=Times New Roman]m[/font][font=宋体]看到是后面的多少颗[/font][font=Times New Roman]0[/font][font=宋体]。如[/font][font=Times New Roman]255.255.255.0[/font][font=宋体]转换成二进制,那就是[/font][font=Times New Roman]11111111.11111111.11111111.00000000[/font][font=宋体],后面有[/font][font=Times New Roman]8[/font][font=宋体]颗[/font][font=Times New Roman]0[/font][font=宋体],那[/font][font=Times New Roman]m[/font][font=宋体]就是[/font][font=Times New Roman]8[/font][font=宋体],[/font][font=Times New Roman]255.255.255.0[/font][font=宋体]这个子网掩码可以容纳[/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]8[/font][font=宋体]次方(台)电脑,也就是[/font][font=Times New Roman]256[/font][font=宋体]台,但是有两个IP是不能用的,那就是最后一段不能为[/font][font=Times New Roman]0[/font][font=宋体]和[/font][font=Times New Roman]255[/font][font=宋体],减去这两台,就是[/font][font=Times New Roman]254[/font][font=宋体]台。我们再来做一个。[/font]
[font=宋体]  [/font][font=Times New Roman]255.255.248.0[/font][font=宋体]这个子网掩码可以最多容纳多少台电脑?[/font]
[font=宋体]  计算方法:[/font]
[font=宋体]  把将其转换为二进制的四段数字(每段要是[/font][font=Times New Roman]8[/font][font=宋体]位,如果是[/font][font=Times New Roman]0[/font][font=宋体],可以写成[/font][font=Times New Roman]8[/font][font=宋体]个[/font][font=Times New Roman]0[/font][font=宋体],也就是[/font][font=Times New Roman]00000000[/font][font=宋体])[/font]
[font=宋体]  [/font][font=Times New Roman]11111111.1111111.11111000.00000000[/font]
[font=宋体]  然后,数数后面有几颗[/font][font=Times New Roman]0[/font][font=宋体],一共是有[/font][font=Times New Roman]11[/font][font=宋体]颗,那就是[/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]11[/font][font=宋体]次方,等于[/font][font=Times New Roman]2048[/font][font=宋体],这个子网掩码最多可以容纳[/font][font=Times New Roman]2048[/font][font=宋体]台电脑。[/font]
[font=宋体]  一个子网最多可以容纳多少台电脑你会算了吧,下面我们来个逆向算法的题。[/font]
[font=宋体]  一个公司有[/font][font=Times New Roman]530[/font][font=宋体]台电脑,组成一个对等局域网,子网掩码设多少最合适?[/font]
[font=宋体]  首先,无疑,[/font][font=Times New Roman]530[/font][font=宋体]台电脑用B类IP最合适(A类不用说了,太多,C类又不够,肯定是B类),但是[/font][font=Times New Roman]B[/font][font=宋体]类默认的子网掩码是[/font][font=Times New Roman]255.255.0.0[/font][font=宋体],可以容纳[/font][font=Times New Roman]6[/font][font=宋体]万台电脑,显然不太合适,那子网掩码设多少合适呢?我们先来列个公式。[/font]
[font=宋体]  [/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]m[/font][font=宋体]次方=[/font][font=Times New Roman]560[/font]
[font=宋体]  首先,我们确定[/font][font=Times New Roman]2[/font][font=宋体]一定是大于[/font][font=Times New Roman]8[/font][font=宋体]次方的,因为我们知道[/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]8[/font][font=宋体]次方是[/font][font=Times New Roman]256[/font][font=宋体],也就是C类IP的最大容纳电脑的数目,我们从[/font][font=Times New Roman]9[/font][font=宋体]次方一个一个试[/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]9[/font][font=宋体]次方是[/font][font=Times New Roman]512[/font][font=宋体],不到[/font][font=Times New Roman]560[/font][font=宋体],[/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]10[/font][font=宋体]次方是[/font][font=Times New Roman]1024[/font][font=宋体],看来[/font][font=Times New Roman]2[/font][font=宋体]的[/font][font=Times New Roman]10[/font][font=宋体]次方最合适了。子网掩码一共由[/font][font=Times New Roman]32[/font][font=宋体]位组成,已确定后面[/font][font=Times New Roman]10[/font][font=宋体]位是[/font][font=Times New Roman]0[/font][font=宋体]了,那前面的[/font][font=Times New Roman]22[/font][font=宋体]位就是[/font][font=Times New Roman]1[/font][font=宋体],最合适的子网掩码就是:[/font][font=Times New Roman]11111111.11111111.11111100.00000000[/font][font=宋体],转换成[/font][font=Times New Roman]10[/font][font=宋体]进制,那就是[/font][font=Times New Roman]255.255.252.0[/font][font=宋体]。[/font]
[font=宋体]  分配和计算子网掩码你会了吧,下面,我们来看看IP地址的网段。[/font]
[font=宋体]  相信好多人都和偶一样,认为IP只要前三段相同,就是在同一网段了,其实,不是这样的,同样,我样把IP的每一段转换为一个二进制数,这里就拿IP:[/font][font=Times New Roman]192.168.0.1[/font][font=宋体],子网掩码:[/font][font=Times New Roman]255.255.255.0[/font][font=宋体]做实验吧。[/font]
[font=宋体]  [/font][font=Times New Roman]192.168.0.1[/font]
[font=宋体]  [/font][font=Times New Roman]11000000.10101000.00000000.00000001[/font]
[font=宋体]  (这里说明一下,和子网掩码一样,每段[/font][font=Times New Roman]8[/font][font=宋体]位,不足[/font][font=Times New Roman]8[/font][font=宋体]位的,前面加[/font][font=Times New Roman]0[/font][font=宋体]补齐。)[/font]
[font=宋体]  IP    [/font][font=Times New Roman]11000000.10101000.00000000.00000001[/font]
[font=宋体]  子网掩码  [/font][font=Times New Roman]11111111.11111111.11111111.00000000[/font]
[font=宋体]  在这里,向大家说一下到底怎么样才算同一网段。[/font]
[font=宋体]  要想在同一网段,必需做到网络标识相同,那网络标识怎么算呢?各类IP的网络标识算法都是不一样的。A类的,只算第一段。B类,只算第一、二段。C类,算第一、二、三段。[/font]
[font=宋体]  算法只要把IP和子网掩码的每位数[/font][font=Times New Roman]AND[/font][font=宋体]就可以了。[/font]
[font=宋体]  [/font][font=Times New Roman]AND[/font][font=宋体]方法:[/font][font=Times New Roman]0[/font][font=宋体]和[/font][font=Times New Roman]1[/font][font=宋体]=[/font][font=Times New Roman]0[/font][font=宋体] [/font][font=Times New Roman]0[/font][font=宋体]和[/font][font=Times New Roman]0[/font][font=宋体]=[/font][font=Times New Roman]0[/font][font=宋体] [/font][font=Times New Roman]1[/font][font=宋体]和[/font][font=Times New Roman]1[/font][font=宋体]=[/font][font=Times New Roman]1[/font]
[font=宋体]  如:[/font][font=Times New Roman]And[/font][font=宋体] [/font][font=Times New Roman]192.168.0.1[/font][font=宋体],[/font][font=Times New Roman]255.255.255.0[/font][font=宋体],先转换为二进制,然后[/font][font=Times New Roman]AND[/font][font=宋体]每一位[/font]
[font=宋体]  IP      [/font][font=Times New Roman]11000000.10101000.00000000.00000001[/font]
[font=宋体]  子网掩码    [/font][font=Times New Roman]11111111.11111111.11111111.00000000[/font]
[font=宋体]  得出[/font][font=Times New Roman]AND[/font][font=宋体]结果 [/font][font=Times New Roman] 11000000.10101000.00000000.00000000[/font]
[font=宋体]  转换为十进制[/font][font=Times New Roman]192.168.0.0[/font][font=宋体],这就是网络标识,[/font]
[font=宋体]  再将子网掩码反取,也就是[/font][font=Times New Roman]00000000.00000000.00000000.11111111[/font][font=宋体],与[/font][font=Times New Roman]IP[/font][font=宋体] [/font][font=Times New Roman]AND[/font]
[font=宋体]  得出结果[/font][font=Times New Roman]00000000.00000000.00000000.00000001[/font][font=宋体],转换为[/font][font=Times New Roman]10[/font][font=宋体]进制,即[/font][font=Times New Roman]0.0.0.1[/font][font=宋体],[/font]
[font=宋体]  这[/font][font=Times New Roman]0.0.0.1[/font][font=宋体]就是主机标识。要想在同一网段,必需做到网络标识一样。[/font]
[font=宋体]  我们再来看看这个改为默认子网掩码的B类IP[/font]
[font=宋体]  如IP:[/font][font=Times New Roman]188.188.0.111[/font][font=宋体],[/font][font=Times New Roman]188.188.5.222[/font][font=宋体],子网掩码都设为[/font][font=Times New Roman]255.255.254.0[/font][font=宋体],在同一网段吗?[/font]
[font=宋体]  先将这些转换成二进制[/font]
[font=宋体]  [/font][font=Times New Roman]188.188.0.111[/font][font=宋体] [/font][font=Times New Roman]10111100.10111100.00000000.01101111[/font]
[font=宋体]  [/font][font=Times New Roman]188.188.5.222[/font][font=宋体] [/font][font=Times New Roman]10111100.10111100.00000101.11011010[/font]
[font=宋体]  [/font][font=Times New Roman]255.255.254.0[/font][font=宋体] [/font][font=Times New Roman]11111111.11111111.11111110.00000000[/font]
[font=宋体]  分别[/font][font=Times New Roman]AND[/font][font=宋体],得[/font]
[font=宋体]  [/font][font=Times New Roman]10111100.10111100.00000000.00000000[/font]
[font=宋体]  [/font][font=Times New Roman]10111100.10111100.00000100.00000000[/font]
[font=宋体]  网络标识不一样,即不在同一网段。[/font]
[font=宋体]  判断是不是在同一网段,你会了吧,下面,我们来点实际的。[/font]
[font=宋体]  一个公司有[/font][font=Times New Roman]530[/font][font=宋体]台电脑,组成一个对等局域网,子网掩码和IP设多少最合适?[/font]
[font=宋体]  子网掩码不说了,前面算出结果来了[/font][font=Times New Roman]11111111.11111111.11111100.00000000[/font][font=宋体],也就是[/font][font=Times New Roman]255.255.252.0[/font]
[font=宋体]  我们现在要确定的是IP如何分配,首先,选一个B类IP段,这里就选[/font][font=Times New Roman]188.188.x.x[/font][font=宋体]吧[/font]
[font=宋体]  这样,IP的前两段确定的,关键是要确定第三段,只要网络标识相同就可以了。我们先来确定网络号。(我们把子网掩码中的[/font][font=Times New Roman]1[/font][font=宋体]和[/font][font=Times New Roman]IP[/font][font=宋体]中的[/font][font=Times New Roman]?[/font][font=宋体]对就起来,[/font][font=Times New Roman]0[/font][font=宋体]和[/font][font=Times New Roman]*[/font][font=宋体]对应起来,如下:)[/font]
[font=宋体]  [/font][font=Times New Roman]255.255.252.0[/font][font=宋体] [/font][font=Times New Roman]11111111.11111111.11111100.00000000[/font]
[font=宋体]  [/font][font=Times New Roman]188.188.x.x[/font][font=宋体]  [/font][font=Times New Roman]10111100.10111100.??????**.********[/font]
[font=宋体]  网络标识   [/font][font=Times New Roman]10111100.10111100.??????00.00000000[/font]
[font=宋体]  由此可知,[/font][font=Times New Roman]?[/font][font=宋体]处随便填(只能用[/font][font=Times New Roman]0[/font][font=宋体]和[/font][font=Times New Roman]1[/font][font=宋体]填,不一定全是[/font][font=Times New Roman]0[/font][font=宋体]和[/font][font=Times New Roman]1[/font][font=宋体]),我们就用全填[/font][font=Times New Roman]0[/font][font=宋体]吧,[/font][font=Times New Roman]*[/font][font=宋体]处随便,这样呢,我们的IP就是[/font]
[font=宋体]  [/font][font=Times New Roman]10111100.10111100.000000**.********[/font][font=宋体],一共有[/font][font=Times New Roman]530[/font][font=宋体]台电脑,IP的最后一段[/font][font=Times New Roman]1[/font][font=宋体]~[/font][font=Times New Roman]254[/font][font=宋体]可以分给[/font][font=Times New Roman]254[/font][font=宋体]台计算机,[/font][font=Times New Roman]530/254[/font][font=宋体]=[/font][font=Times New Roman]2.086[/font][font=宋体],采用进[/font][font=Times New Roman]1[/font][font=宋体]法,得整数[/font][font=Times New Roman]3[/font][font=宋体],这样,我们确定了IP的第三段要分成三个不同的数字,也就是说,把[/font][font=Times New Roman]000000**[/font][font=宋体]中的[/font][font=Times New Roman]**[/font][font=宋体]填三次数字,只能填[/font][font=Times New Roman]1[/font][font=宋体]和[/font][font=Times New Roman]0[/font][font=宋体],而且每次的数字都不一样,至于填什么,就随我们便了,如[/font][font=Times New Roman]00000001[/font][font=宋体],[/font][font=Times New Roman]00000010[/font][font=宋体],[/font][font=Times New Roman]00000011[/font][font=宋体],转换成二进制,分别是[/font][font=Times New Roman]1[/font][font=宋体],[/font][font=Times New Roman]2[/font][font=宋体],[/font][font=Times New Roman]3[/font][font=宋体],这样,第三段也确定了,这样,就可以把IP分成[/font][font=Times New Roman]188.188.1.y[/font][font=宋体],[/font][font=Times New Roman]188.188.2.y[/font][font=宋体],[/font][font=Times New Roman]188.188.3.y[/font][font=宋体],[/font][font=Times New Roman]y[/font][font=宋体]处随便填,只要在[/font][font=Times New Roman]1[/font][font=宋体]~[/font][font=Times New Roman]254[/font][font=宋体]范围之内,并且这[/font][font=Times New Roman]530[/font][font=宋体]台电脑每台和每台的IP不一样,就可以了。[/font]
[font=宋体]  有人也许会说,既然算法这么麻烦,干脆用A类IP和A类默认子网掩码得了,偶要告诉你的是,由于A类IP和A类默认子网掩码的主机数目过大,这样做无疑是大海捞针,如果同时局域网访问量过频繁、过大,会影响效率的,所以,最好设置符合自己的IP和子网掩码[/font][font=Times New Roman]^_^[/font]

吴文卿 发表于 2008-6-11 10:59

看了,有点收获!YCT74YCT

andy2007 发表于 2008-6-11 20:37

顶你下!~慢慢看看!~

starghost 发表于 2008-6-12 17:21

不如说是教别人ip address

zmh3937 发表于 2008-6-16 22:49

好文章,顶。。。

diekwang 发表于 2008-6-16 23:07

计算机原理里的东西

chgb1966 发表于 2008-6-18 15:13

很受启发,谢谢!!!!!!!!!

galry 发表于 2008-6-21 16:03

搞了这么久,才算是弄明白点。
谢谢了!

wdwwdw 发表于 2008-6-23 07:30

简单,192.168.0.1/255.255.252.0
就可以上530台,再多点用192.168.0.1/255.255.250.0.

pipsi 发表于 2008-6-24 13:54

收获不小

netoscar 发表于 2008-6-26 16:07

见识了,,好深的东西,,

qazsedcft 发表于 2008-6-26 16:50

又增长了知识,谢谢了

huangyuetian 发表于 2008-6-27 15:46

看了,有点收获!

页: [1]

Powered by Discuz! Archiver 6.1.0  © 1999-2008 bbs.bitsCN.com