如何使用 sipcalc Linux 命令行工具
我现在能记住的唯一网络号是具有 24 位网络掩码的 C 类网络,例如 192.168.1.0/24。我知道有 254 个可用的主机地址,广播地址为 192.168.1.255,网关/路由器地址为 192.168.1.1 或 192.168.1.254(取决于谁在运行网络),人性化的网络掩码为 255.255.255.0。这是我的标准网络。毕竟,254 台主机足以容纳任何子网,对吧?错了。几年前,当我决定使用 22 位网络掩码(255.255.252.0)来获得 1022 个可用地址空间时,我不得不走出标准的每个子网 254 台主机的方案。
我对这个地址空间知之甚少,如果不浏览充斥着闲聊和离题言论的论坛,我很难找到我需要的简单信息。我想有些人只是需要一个空间来表达他们对一切的不满。我跑题了。
问题
由于现在所有东西都有 IP 地址,我的 DHCP 服务器 IP 地址即将用完,我不得不做一些简单的事来缓解这种情况。我有一个荒谬的想法,认为 254 个地址足以满足我们两个地点的 130 名左右员工、30 台服务器、10 台打印机、两个路由器、10 个无线接入点和其他一些随机设备的需求。我忘了每个人都有一部连接到 WiFi 的电话。您可以看到,我的 254 个地址无法覆盖每个人的 PC 和他们的电话,也无法容纳我所需的其他设备。我接到了太多的电话和工单,描述了一些不容易排除故障的问题,直到我弄清楚我的 IP 地址已经用完。不幸的是,DHCP 服务器按先到先得的原则分配地址,而不考虑谁(或什么)获得了这些地址。
我发现这个sipcalc
命令可以让我的工作在确定 IP 地址范围、网络掩码和潜在网关地址时变得轻松一些。这个sipcalc
命令是一种命令行计算器,可以显示填写 DHCP 信息或设置静态 IP 地址所需的所有 IP 相关信息。
sipcalc 用法
这是一个使用的标准 24 位 C 类网络示例sipcalc
。
$ sipcalc 192.168.1.0/24
-[ipv4 : 192.168.1.0/24] - 0
[CIDR]
Host address - 192.168.1.0
Host address (decimal) - 3232235776
Host address (hex) - C0A80100
Network address - 192.168.1.0
Network mask - 255.255.255.0
Network mask (bits) - 24
Network mask (hex) - FFFFFF00
Broadcast address - 192.168.1.255
Cisco wildcard - 0.0.0.255
Addresses in network - 256
Network range - 192.168.1.0 - 192.168.1.255
Usable range - 192.168.1.1 - 192.168.1.254
以及等效的 22 位网络掩码示例。
$ sipcalc 192.168.1.0/22
-[ipv4 : 192.168.1.0/22] - 0
[CIDR]
Host address - 192.168.1.0
Host address (decimal) - 3232235776
Host address (hex) - C0A80100
Network address - 192.168.0.0
Network mask - 255.255.252.0
Network mask (bits) - 22
Network mask (hex) - FFFFFC00
Broadcast address - 192.168.3.255
Cisco wildcard - 0.0.3.255
Addresses in network - 1024
Network range - 192.168.0.0 - 192.168.3.255
Usable range - 192.168.0.1 - 192.168.3.254
如果您是喜欢查看大量信息的人之一,无论其价值如何,请尝试-a
在命令中添加 (all) 开关。
$ sipcalc -a 192.168.1.0/24
-[ipv4 : 192.168.1.0/24] - 0
[Classful]
Host address - 192.168.1.0
Host address (decimal) - 3232235776
Host address (hex) - C0A80100
Network address - 192.168.1.0
Network class - C
Network mask - 255.255.255.0
Network mask (hex) - FFFFFF00
Broadcast address - 192.168.1.255
[CIDR]
Host address - 192.168.1.0
Host address (decimal) - 3232235776
Host address (hex) - C0A80100
Network address - 192.168.1.0
Network mask - 255.255.255.0
Network mask (bits) - 24
Network mask (hex) - FFFFFF00
Broadcast address - 192.168.1.255
Cisco wildcard - 0.0.0.255
Addresses in network - 256
Network range - 192.168.1.0 - 192.168.1.255
Usable range - 192.168.1.1 - 192.168.1.254
[Classful bitmaps]
Network address - 11000000.10101000.00000001.00000000
Network mask - 11111111.11111111.11111111.00000000
[CIDR bitmaps]
Host address - 11000000.10101000.00000001.00000000
Network address - 11000000.10101000.00000001.00000000
Network mask - 11111111.11111111.11111111.00000000
Broadcast address - 11000000.10101000.00000001.11111111
Cisco wildcard - 00000000.00000000.00000000.11111111
Network range - 11000000.10101000.00000001.00000000 -
11000000.10101000.00000001.11111111
Usable range - 11000000.10101000.00000001.00000001 -
11000000.10101000.00000001.11111110
[Networks]
Network - 192.168.1.0 - 192.168.1.255 (current)
Personally, I think the Classless Inter-Domain Routing (CIDR) information is the most useful. It's the default output for the sipcalc
command. I'm not sure who uses bitmap information, but it's there for those of you who do. I've never had an instance in my career to know it or to use it. Maybe knowledge of it is useful for network certification exams, but beyond that, I'm not sure you'll ever see it in a real-life network or application. If you do, use sipcalc
to make it easy on yourself.
[ You might also enjoy: Running a quick NMAP scan to inventory my network ]
sipcalc options
If you've read any of my articles, you know that I use a subset of command options--just the ones I need, in fact. I rarely have the time or the patience to explore every option for a command. I generally hit the man page, find an option or two that gives me the information I require, and then I move on. For those of you who love to explore every nook and cranny, please enjoy all of sipcalc
's nooks and crannies (options list) from the man page:
OPTIONS
-a --all
Give all possible information about an adress or
interface, this is equivalent to giving the flags
-b -c -i -n 0 for IPv4 and -e -r -t for IPv6.
-b --cidr-bitmap (IPv4)
Display CIDR based bitmaps.
-c --classfull-addr (IPv4)
Display classfull address information.
-d --resolve
Enable name resolution.
-e --v4inv6 (IPv6)
Display v4inv6 address information.
-h --help
Display the commandline help.
-i --cidr-addr (default IPv4)
Display CIDR address information.
-I, --addr-int=INT
Explicitly add an interface. This can be used to
circumvent the sipcalc "smart parsing" of
addresses/interfaces on the commandline. This can
be useful if you for example for some reason have
an interface with the same name as an actual
address, eg. 127.0.0.1 or ::1 etc. See also: -4
-6.
-n --subnets=NUM
Display NUM extra subnets (starting from the cur-
rent subnet). Will display all subnets in the cur-
rent /24 if NUM is 0.
-r --v6rev (IPv6)
Display IPv6 reverse DNS information.
-s --v4split=MASK (IPv4)
Split the current network into subnets of MASK
size. MASK can be given in dotted quad, hex or CIDR
form.
-S, --v6split=MASK (IPv6)
Split the current network into subnets of MASK
size. MASK must be given in CIDR form, either with
or with the '/' character.
-t, --v6-standard (default IPv6)
Display IPv6 address information.
-u, --split-verbose
This will put network splitting into verbose mode.
This means that all the subnets generated when
splitting a network will be passed back to sipcalc
for explicit parsing giving the same output as if
the address had been given on the commandline. All
options passed to sipcalc on the commandline will
also be inherited when the subnet is passed back to
sipcalc for parsing, with one exception, the -s/-S
flag, we don't want an endless loop. Sending only
the -s/-S and -u flags to sipcalc will give the
default output (-i for ipv4 and -t for ipv6).
-v --version
Display version information.
-x --classful-bitmap (IPv6)
Display a classfull bitmap.
-4, --addr-ipv4=ADDR
Explicitly add an IPv4 address. See also: -I -6.
-6, --addr-ipv6=ADDR
Explicitly add an IPv6 address. See also: -I -4.
For me, the IPv6 information is almost worthless because if I ever convert one of my networks to it, DHCP will be my best friend. I'd rather not look at or attempt to type 128-bit addresses. Until then, sipcalc
and I will continue our minimalist IPv4-oriented relationship.
[ Looking for more on system automation? Get started with The Automated Enterprise, a free book from Red Hat. ]
Wrap up
The sipcalc
command is one of those commands that you keep in your personal sysadmin arsenal for when you need it. And you don't need it very often unless you deal with creating, managing, and assigning IP address spaces on a daily basis. Some sysadmins pipe sipcalc
's information to a text file and print it for future reference. I find that sending the information to an HTML page is far handier than keeping track of bits of paper for the rest of my days or pinning it to my already overcrowded cubicle wall.