在Linux 中如何使用 Sipcalc 来计算 IP 子网-阿里云开发者社区

开发者社区> 开发与运维> 正文
登录阅读全文

在Linux 中如何使用 Sipcalc 来计算 IP 子网

简介: Sipcalc 是一个命令行 ip 子网计算器,支持 IPv4 和 IPv6,它会显示你填写 DHCP 信息或设置静态 IP 地址所需的所有 IP 相关信息。Sipcalc 的开发始于 2001 年,它具有我们想要的 ip 计算器的大部分功能。

安    装


Centos8中安装sipcalc之前,需要先安装epel源。:

[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install sipcalc




sipcalc 使用方式



下面使用 sipcalc 列出一个标准 24 位的 C 类网络示例:

[root@localhost ~]# sipcalc 192.168.10.0/24
-[ipv4 : 192.168.10.0/24] - 0
[CIDR]
Host address  - 192.168.10.0
Host address (decimal) - 3232238080
Host address (hex) - C0A80A00
Network address  - 192.168.10.0
Network mask  - 255.255.255.0
Network mask (bits) - 24
Network mask (hex) - FFFFFF00
Broadcast address - 192.168.10.255
Cisco wildcard  - 0.0.0.255
Addresses in network - 256
Network range  - 192.168.10.0 - 192.168.10.255
Usable range  - 192.168.10.1 - 192.168.10.254

可以看到列出了192.168.10.0/24网段中广播地址、反掩码、网络范围和可用的IP地址范围。


下面添加-a查看一下:

[root@localhost ~]# sipcalc -a 192.168.10.0/24
-[ipv4 : 192.168.10.0/24] - 0
[Classful]
Host address  - 192.168.10.0
Host address (decimal) - 3232238080
Host address (hex) - C0A80A00
Network address  - 192.168.10.0
Network class  - C
Network mask  - 255.255.255.0
Network mask (hex) - FFFFFF00
Broadcast address - 192.168.10.255
[CIDR]
Host address  - 192.168.10.0
Host address (decimal) - 3232238080
Host address (hex) - C0A80A00
Network address  - 192.168.10.0
Network mask  - 255.255.255.0
Network mask (bits) - 24
Network mask (hex) - FFFFFF00
Broadcast address - 192.168.10.255
Cisco wildcard  - 0.0.0.255
Addresses in network - 256
Network range  - 192.168.10.0 - 192.168.10.255
Usable range  - 192.168.10.1 - 192.168.10.254
[Classful bitmaps]
Network address  - 11000000.10101000.00001010.00000000
Network mask  - 11111111.11111111.11111111.00000000
[CIDR bitmaps]
Host address  - 11000000.10101000.00001010.00000000
Network address  - 11000000.10101000.00001010.00000000
Network mask  - 11111111.11111111.11111111.00000000
Broadcast address - 11000000.10101000.00001010.11111111
Cisco wildcard  - 00000000.00000000.00000000.11111111
Network range  - 11000000.10101000.00001010.00000000 -
11000000.10101000.00001010.11111111
Usable range  - 11000000.10101000.00001010.00000001 -
11000000.10101000.00001010.11111110
[Networks]
Network   - 192.168.10.0    - 192.168.10.255 (current)

可以看到可以看到192.168.10.0网段的有类路由和无类路由的二进制形式。

微信图片_20210925005305.png

下面使用一个27为掩码的网段:

[root@localhost ~]# sipcalc 192.168.10.0/27
-[ipv4 : 192.168.10.0/27] - 0
[CIDR]
Host address  - 192.168.10.0
Host address (decimal) - 3232238080
Host address (hex) - C0A80A00
Network address  - 192.168.10.0
Network mask  - 255.255.255.224
Network mask (bits) - 27
Network mask (hex) - FFFFFFE0
Broadcast address - 192.168.10.31
Cisco wildcard  - 0.0.0.31
Addresses in network - 32
Network range  - 192.168.10.0 - 192.168.10.31
Usable range  - 192.168.10.1 - 192.168.10.30

可以看到可用地址为192.168.10.1-192.168.10.30

微信图片_20210925005422.png

添加-a选项,可以看到可用的网段有哪些:

[root@localhost ~]# sipcalc 192.168.10.0/27 -a
-[ipv4 : 192.168.10.0/27] - 0
[Classful]
Host address  - 192.168.10.0
Host address (decimal) - 3232238080
Host address (hex) - C0A80A00
Network address  - 192.168.10.0
Network class  - C
Network mask  - 255.255.255.0
Network mask (hex) - FFFFFF00
Broadcast address - 192.168.10.255
[CIDR]
Host address  - 192.168.10.0
Host address (decimal) - 3232238080
Host address (hex) - C0A80A00
Network address  - 192.168.10.0
Network mask  - 255.255.255.224
Network mask (bits) - 27
Network mask (hex) - FFFFFFE0
Broadcast address - 192.168.10.31
Cisco wildcard  - 0.0.0.31
Addresses in network - 32
Network range  - 192.168.10.0 - 192.168.10.31
Usable range  - 192.168.10.1 - 192.168.10.30
[Classful bitmaps]
Network address  - 11000000.10101000.00001010.00000000
Network mask  - 11111111.11111111.11111111.00000000
[CIDR bitmaps]
Host address  - 11000000.10101000.00001010.00000000
Network address  - 11000000.10101000.00001010.00000000
Network mask  - 11111111.11111111.11111111.11100000
Broadcast address - 11000000.10101000.00001010.00011111
Cisco wildcard  - 00000000.00000000.00000000.00011111
Network range  - 11000000.10101000.00001010.00000000 -
11000000.10101000.00001010.00011111
Usable range  - 11000000.10101000.00001010.00000001 -
11000000.10101000.00001010.00011110
[Networks]
Network   - 192.168.10.0    - 192.168.10.31 (current)
Network   - 192.168.10.32   - 192.168.10.63
Network   - 192.168.10.64   - 192.168.10.95
Network   - 192.168.10.96   - 192.168.10.127
Network   - 192.168.10.128  - 192.168.10.159
Network   - 192.168.10.160  - 192.168.10.191
Network   - 192.168.10.192  - 192.168.10.223
Network   - 192.168.10.224  - 192.168.10.255



版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章
最新文章
相关文章