对于ip地址的设置与子网掩码的使用是网络中最容易出错的地方,很多项目之所有故障不断,原因皆在于此,在我们vip技术群中也经常讨论到。

本期弱电行业网与大家来做个大总结,详解ip地址与子网掩码的关系,顺带着也把子网划分一并给出常用的几个实例。
一、掩码位数与ip数对应
子网掩码,一共是32位,每加一位,可用的ip数都成指数减少。


二、掩码位数与对应的子网掩码
根据掩码位数,确定ip总数以及具体子网掩码。

三、子网如何划分
C类ip地址用的最多,主要用于内网,那么如何对C类ip地址划分子网呢?
C类ip地址,默认子网掩码:255.255.255.0
转换为二进制为:
11111111.11111111.11111111.00000000
我们来看下,根据不同的需求,划分子网与ip地址的情况:
可以划分1个子网

这种情况就是相当于不划分子网了,默认存在一个子网,子网掩码就是255.255.255.0,可用地址254个。
表示:192.168.1.0/24
可以划分2个子网

划分2个子网,子网掩码就是255.255.255.128,每个子网有126个可用地址。
表示:
192.168.1.0/25
192.168.1.128/25
可以划分4个子网

划分4个子网,子网掩码就是255.255.255.192,每个子网里有62个可用地址。
表示:
192.168.1.0/26
192.168.1.64/26
192.168.1.128/26
192.168.1.192/26
可以划分8个子网

划分8个子网,子网掩码就是255.255.255.224,每个子网有30个可用地址。
表示:
192.168.1.0/27
192.168.1.32/27
192.168.1.64/27
192.168.1.96/27
192.168.1.128/27
192.168.1.160/27
192.168.1.192/27
192.168.1.224/27
划分16个子网

划分16个子网,子网掩码就是255.255.255.240,每个子网里有14个可用地址。
表示:
192.168.1.0/28
192.168.1.16/28
192.168.1.32/28
192.168.1.48/28
、、、、
192.168.1.224/28
192.168.1.240/28