読者です 読者をやめる 読者になる 読者になる

sipcalcについてのメモ

Linux TIPS

IPアドレスのサブネット計算とかやる必要が時にはあります。


計算に慣れてしまえばいいんでしょうが、結構面倒な時もあります。


そんな時の「sipcalc」コマンドです。
「ipcalc」というコマンドもありますが、こっちのほうが良さげ。

使い方

# sipcalc -a -4 10.0.1.100/24
-[ipv4 : 10.0.1.100/24] - 0

[Classfull]
Host address		- 10.0.1.100
Host address (decimal)	- 167772516
Host address (hex)	- A000164
Network address		- 10.0.0.0
Network class		- A
Network mask		- 255.0.0.0
Network mask (hex)	- FF000000
Broadcast address	- 10.255.255.255

[CIDR]
Host address		- 10.0.1.100
Host address (decimal)	- 167772516
Host address (hex)	- A000164
Network address		- 10.0.1.0
Network mask		- 255.255.255.0
Network mask (bits)	- 24
Network mask (hex)	- FFFFFF00
Broadcast address	- 10.0.1.255
Cisco wildcard		- 0.0.0.255
Addresses in network	- 256
Network range		- 10.0.1.0 - 10.0.1.255
Usable range		- 10.0.1.1 - 10.0.1.254

[Classfull bitmaps]
Network address		- 00001010.00000000.00000000.00000000
Network mask		- 11111111.00000000.00000000.00000000

[CIDR bitmaps]
Host address		- 00001010.00000000.00000001.01100100
Network address		- 00001010.00000000.00000001.00000000
Network mask		- 11111111.11111111.11111111.00000000
Broadcast address	- 00001010.00000000.00000001.11111111
Cisco wildcard		- 00000000.00000000.00000000.11111111
Network range		- 00001010.00000000.00000001.00000000 -
			  00001010.00000000.00000001.11111111
Usable range		- 00001010.00000000.00000001.00000001 -
			  00001010.00000000.00000001.11111110

[Networks]
Network			- 10.0.1.0        - 10.0.1.255 (current)


CIDR表記変えれば計算も変わりますね。

# sipcalc -a -4 10.0.1.100/19
-[ipv4 : 10.0.1.100/19] - 0

[Classfull]
Host address		- 10.0.1.100
Host address (decimal)	- 167772516
Host address (hex)	- A000164
Network address		- 10.0.0.0
Network class		- A
Network mask		- 255.0.0.0
Network mask (hex)	- FF000000
Broadcast address	- 10.255.255.255

[CIDR]
Host address		- 10.0.1.100
Host address (decimal)	- 167772516
Host address (hex)	- A000164
Network address		- 10.0.0.0
Network mask		- 255.255.224.0
Network mask (bits)	- 19
Network mask (hex)	- FFFFE000
Broadcast address	- 10.0.31.255
Cisco wildcard		- 0.0.31.255
Addresses in network	- 8192
Network range		- 10.0.0.0 - 10.0.31.255
Usable range		- 10.0.0.1 - 10.0.31.254

[Classfull bitmaps]
Network address		- 00001010.00000000.00000000.00000000
Network mask		- 11111111.00000000.00000000.00000000

[CIDR bitmaps]
Host address		- 00001010.00000000.00000001.01100100
Network address		- 00001010.00000000.00000000.00000000
Network mask		- 11111111.11111111.11100000.00000000
Broadcast address	- 00001010.00000000.00011111.11111111
Cisco wildcard		- 00000000.00000000.00011111.11111111
Network range		- 00001010.00000000.00000000.00000000 -
			  00001010.00000000.00011111.11111111
Usable range		- 00001010.00000000.00000000.00000001 -
			  00001010.00000000.00011111.11111110

[Networks]
Network			- 10.0.0.0        - 10.0.31.255 (current)


NICを指定するとNICに割り当てられているIPアドレスに対して計算するようです。

 # sipcalc eth0
-[int-ipv4 : eth0] - 0

[CIDR]
Host address		- 192.168.xxx.xxx
Host address (decimal)	- xxxxxxxxxx
Host address (hex)	- xxxxxxxx
Network address		- 192.168.xxx.xxx
Network mask		- 255.255.255.0
Network mask (bits)	- 24
Network mask (hex)	- xxxxxxxx
Broadcast address	- 192.168.xxx.xxx
Cisco wildcard		- 0.0.0.255
Addresses in network	- 256
Network range		- 192.168.xxx.xxx - 192.168.xxx.xxx
Usable range		- 192.168.xxx.xxx - 192.168.xxx.xxx

-


同様にIPv6アドレスも計算できます。


手元のVMに割り当てられてたIP見たらこんな感じでした。

# sipcalc -6 fe80::a00:27ff:fe93:6526/64
-[ipv6 : fe80::a00:27ff:fe93:6526/64] - 0

[IPV6 INFO]
Expanded Address	- fe80:0000:0000:0000:0a00:27ff:fe93:6526
Compressed address	- fe80::a00:27ff:fe93:6526
Subnet prefix (masked)	- fe80:0:0:0:0:0:0:0/64
Address ID (masked)	- 0:0:0:0:a00:27ff:fe93:6526/64
Prefix address		- ffff:ffff:ffff:ffff:0:0:0:0
Prefix length		- 64
Address type		- Link-Local Unicast Addresses
Network range		- fe80:0000:0000:0000:0000:0000:0000:0000 -
			  fe80:0000:0000:0000:ffff:ffff:ffff:ffff

-


コマンドで計算できるのがすばらしいですね。


その他詳しい使い方は、「sipcalc --help」もしくはmanで。


今日はこんなところで。