导读 | 本文档介绍如何利用ubuntu18.04.1和rhel7快速计算IP信息,使用到的命令是ipcalc |
ipcalc命令
ipcalc命令是一个简单的ip地址计算器,可以完成简单的IP地址计算任务。
Ubuntu
安装 ipcalc 后直接使用对应的命令即可
实例
root@ubuntu18.04.1:~# apt‐get install ‐y ipcalc Reading package lists... Done Building dependency tree Reading state information... Done The following NEW packages will be installed: ipcalc 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 27.8 kB of archives. After this operation, 66.6 kB of additional disk space will be used. Get:1 http://apt.x.netease.com:8660/debian stretch/main amd64 ipcalc all 0.41‐5 [27.8 kB] Fetched 27.8 kB in 0s (35.6 kB/s) Selecting previously unselected package ipcalc. (Reading database ... 58084 files and directories currently installed.) Preparing to unpack .../archives/ipcalc_0.41‐5_all.deb ... Unpacking ipcalc (0.41‐5) ... Setting up ipcalc (0.41‐5) ... Processing triggers for man‐db (2.7.6.1‐2) ... root@ubuntu18.04.1:~# ipcalc 10.78.20.0/24 Address: 10.78.20.0 00001010.01001110.00010100. 00000000 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 10.78.20.0/24 00001010.01001110.00010100. 00000000 HostMin: 10.78.20.1 00001010.01001110.00010100. 00000001 HostMax: 10.78.20.254 00001010.01001110.00010100. 11111110 Broadcast: 10.78.20.255 00001010.01001110.00010100. 11111111 Hosts/Net: 254 Class A, Private Internet root@ubuntu18.04.1:~# ipcalc 10.78.20.0/25 Address: 10.78.20.0 00001010.01001110.00010100.0 0000000 Netmask: 255.255.255.128 = 25 11111111.11111111.11111111.1 0000000 Wildcard: 0.0.0.127 00000000.00000000.00000000.0 1111111 => Network: 10.78.20.0/25 00001010.01001110.00010100.0 0000000 HostMin: 10.78.20.1 00001010.01001110.00010100.0 0000001 HostMax: 10.78.20.126 00001010.01001110.00010100.0 1111110 Broadcast: 10.78.20.127 00001010.01001110.00010100.0 1111111 Hosts/Net: 126 Class A, Private Internet root@ubuntu18.04.1:~# ipcalc 10.78.20.0/26 Address: 10.78.20.0 00001010.01001110.00010100.00 000000 Netmask: 255.255.255.192 = 26 11111111.11111111.11111111.11 000000 Wildcard: 0.0.0.63 00000000.00000000.00000000.00 111111 => Network: 10.78.20.0/26 00001010.01001110.00010100.00 000000 HostMin: 10.78.20.1 00001010.01001110.00010100.00 000001 HostMax: 10.78.20.62 00001010.01001110.00010100.00 111110 Broadcast: 10.78.20.63 00001010.01001110.00010100.00 111111 Hosts/Net: 62 Class A, Private Internet root@ubuntu18.04.1:~# ipcalc 192.168.10.0/24 Address: 192.168.10.0 11000000.10101000.00001010. 00000000 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.10.0/24 11000000.10101000.00001010. 00000000 HostMin: 192.168.10.1 11000000.10101000.00001010. 00000001 HostMax: 192.168.10.254 11000000.10101000.00001010. 11111110 Broadcast: 192.168.10.255 11000000.10101000.00001010. 11111111 Hosts/Net: 254 Class C, Private Internet root@ubuntu18.04.1:~# ipcalc 192.168.10.0/25 Address: 192.168.10.0 11000000.10101000.00001010.0 0000000 Netmask: 255.255.255.128 = 25 11111111.11111111.11111111.1 0000000 Wildcard: 0.0.0.127 00000000.00000000.00000000.0 1111111 => Network: 192.168.10.0/25 11000000.10101000.00001010.0 0000000 HostMin: 192.168.10.1 11000000.10101000.00001010.0 0000001 HostMax: 192.168.10.126 11000000.10101000.00001010.0 1111110 Broadcast: 192.168.10.127 11000000.10101000.00001010.0 1111111 Hosts/Net: 126 Class C, Private Internet root@ubuntu18.04.1:~# ipcalc 192.168.10.0/26 Address: 192.168.10.0 11000000.10101000.00001010.00 000000 Netmask: 255.255.255.192 = 26 11111111.11111111.11111111.11 000000 Wildcard: 0.0.0.63 00000000.00000000.00000000.00 111111 => Network: 192.168.10.0/26 11000000.10101000.00001010.00 000000 HostMin: 192.168.10.1 11000000.10101000.00001010.00 000001 HostMax: 192.168.10.62 11000000.10101000.00001010.00 111110 Broadcast: 192.168.10.63 11000000.10101000.00001010.00 111111 Hosts/Net: 62 Class C, Private Internet
RHEL7
语法
ipcalc (选项) 选项 ‐b:由给定的IP地址和网络掩码计算出广播地址; ‐h:显示给定UP地址所对应的主机名; ‐m:由给定的IP地址计算器网络掩码; ‐p:显示给定的掩码或IP地址的前缀; ‐n:由给定的IP地址和网络掩码计算网络地址; ‐s:安静模式; ‐‐help:显示帮助信息。
实例
[root@rhel7 ~]# ipcalc ‐p 192.168.10.1 255.255.255.0 PREFIX=24 [root@rhel7 ~]# ipcalc ‐n 192.168.10.1 255.255.255.0 NETWORK=192.168.10.0 [root@rhel7 ~]# ipcalc ‐h 127.0.0.1 HOSTNAME=rhel7 [root@rhel7 ~]# ipcalc ‐m 192.168.10.1 NETMASK=255.255.255.0 [root@rhel7 ~]# ipcalc ‐pnbm 192.168.10.1 255.255.255.0 NETMASK=255.255.255.0 PREFIX=24 BROADCAST=192.168.10.255 NETWORK=192.168.10.0
总结
以上就是ubuntu18.04.1和rhel7快速计算IP信息的方法,操作命令略有区别,希望能给大家带来帮助。
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/123488.html