If you need to calculate subnet under Linux use an IP Netmask/broadcast calculator called ipcal. You can calculate IPv4 or IPv6 address. Supported features:
=> Multiple address and netmask input formats.
=> Retrieving of address information from interfaces.
=> Classfull and CIDR output.
=> Multiple address and netmask output formats (dotted quad, hex, number of bits).
=> Output of broadcast address, network class, Cisco wildcard, hosts/range, network range.
=> Output of multiple types of bitmaps.
=> Output of a user-defined number of extra networks.
=> Multiple networks input from commandline.
=> DNS resolutions of hostnames.
=> Compressed and expanded input addresses.
=> Compressed and expanded output.
=> Standard IPv6 network output.
=> v4 in v6 output.
=> Reverse dns address generation.
=> The ability to “split” a network based on a smaller netmask, also with recursive runs on the generated subnets.
Install sipcalc and ipcalc
Use apt-get command:
$ sudo apt-get install sipcalc ipcalc
Please note that ipcalc is installed by default under RHEL / CentOS / Fedora Linux using initscripts package.
Examples
Let us see how to calculate subnets for 192.168.0.1/24:
$ ipcalc 192.168.0.1/24
Output:
Address: 192.168.0.1 11000000.10101000.00000000. 00000001 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.0.0/24 11000000.10101000.00000000. 00000000 HostMin: 192.168.0.1 11000000.10101000.00000000. 00000001 HostMax: 192.168.0.254 11000000.10101000.00000000. 11111110 Broadcast: 192.168.0.255 11000000.10101000.00000000. 11111111 Hosts/Net: 254 Class C, Private Internet
You can also try sipcalc:
$ sipcalc 192.168.0.1/24
Output:
-[ipv4 : 192.168.0.1/24] - 0 [CIDR] Host address - 192.168.0.1 Host address (decimal) - 3232235521 Host address (hex) - C0A80001 Network address - 192.168.0.0 Network mask - 255.255.255.0 Network mask (bits) - 24 Network mask (hex) - FFFFFF00 Broadcast address - 192.168.0.255 Cisco wildcard - 0.0.0.255 Addresses in network - 256 Network range - 192.168.0.0 - 192.168.0.255 Usable range - 192.168.0.1 - 192.168.0.254
More examples:
$ sipcalc 192.168.0.1 255.255.128.0 255.255.192.0
Output:
-[ipv4 : 192.168.0.1 255.255.128.0] - 0 [CIDR] Host address - 192.168.0.1 Host address (decimal) - 3232235521 Host address (hex) - C0A80001 Network address - 192.168.0.0 Network mask - 255.255.128.0 Network mask (bits) - 17 Network mask (hex) - FFFF8000 Broadcast address - 192.168.127.255 Cisco wildcard - 0.0.127.255 Addresses in network - 32768 Network range - 192.168.0.0 - 192.168.127.255 Usable range - 192.168.0.1 - 192.168.127.254 - -[ipv4 : 255.255.192.0] - 0 [CIDR] Host address - 255.255.192.0 Host address (decimal) - 4294950912 Host address (hex) - FFFFC000 Network address - 255.255.192.0 Network mask - 255.255.255.255 Network mask (bits) - 32 Network mask (hex) - FFFFFFFF Broadcast address - 255.255.192.0 Cisco wildcard - 0.0.0.0 Addresses in network - 1 Network range - 255.255.192.0 - 255.255.192.0
Display results as HTML
$ ipcalc -h 192.168.0.1/255.255.128.0
For more options, please refer to man page:
$ man ipcalc
$ man sipcalc
🐧 Get the latest tutorials on Linux, Open Source & DevOps via:
- RSS feed or Weekly email newsletter
- Share on Twitter • Facebook • 6 comments... add one ↓
Category | List of Unix and Linux commands |
---|---|
File Management | cat |
Firewall | Alpine Awall • CentOS 8 • OpenSUSE • RHEL 8 • Ubuntu 16.04 • Ubuntu 18.04 • Ubuntu 20.04 |
Network Utilities | dig • host • ip • nmap |
OpenVPN | CentOS 7 • CentOS 8 • Debian 10 • Debian 8/9 • Ubuntu 18.04 • Ubuntu 20.04 |
Package Manager | apk • apt |
Processes Management | bg • chroot • cron • disown • fg • jobs • killall • kill • pidof • pstree • pwdx • time |
Searching | grep • whereis • which |
User Information | groups • id • lastcomm • last • lid/libuser-lid • logname • members • users • whoami • who • w |
WireGuard VPN | Alpine • CentOS 8 • Debian 10 • Firewall • Ubuntu 20.04 |
The ipcalc that comes with red-hat and derivatives sucks.
The ipcalc for Linux Mint (the one in this article) is fantastic. They are not the same sadly.
How can I replace the one in red-hat/centos with this one?
Any tutorial’s for calculating subnets? and to learn the casics of ip classification?
I LIKE-IT ….
Actually I just realized that you don’t even need this tool to get range easily. You just look at how many host bits and then your ranges are there counting with however many host bits there are.
Woa Sk Shahin Rahman, this article is helpful. Guess what, you work with subnets you really should know how to do binary to decimal and calculate all different type of subnets without these tools if needed, right? They are just for convenience and speed, besides you can use these to calculate ranges.
i am very much help full by this program but in i need another option for IP Range calculate