IPCALC(1)

πŸ’– NAME πŸ’–

ipcalc β€” do lil operations on IP addresses and networks, bestie πŸ’…


✨ SYNOPSIS ✨

ipcalc [OPTION]... IP address[/prefix] [netmask]

🌸 DESCRIPTION 🌸

okay so ipcalc is literally your group-chat bestie for figuring out IP info for a host or a whole network. depending on which options you pass, it can hand you IP network info in human readable format (so you can actually read it, no cap), in a format that's built for scripts to parse, generate random private addresses, resolve an IP address, or vibe-check whether an address is even valid. ✨

the options decide what ipcalc prints: by default, or with --info or --all-info, you get a summary of the network; with specific info options (like --prefix), you get only those values. the --format option picks how it gets printed, which is fully explained in the Output format section. Multiple options may be specified. And you must give an IP address β€” several operations need a netmask or a CIDR prefix too, so don't ghost them. 🫢


πŸŽ€ OUTPUT FORMAT πŸŽ€

the --format=FORMAT option picks one of these, and they're all iconic in their own way:

  • human β€” Titled lines, as in the summary. Colors are used only when the output is a terminal and the NO_COLOR environment variable is not set. This is the default for the summary and for --split, --split-hosts, --deaggregate and --binary. 🌈
  • shell β€” VAR=VALUE lines that can be passed to the shell's eval; a value that contains characters special to the shell, such as a space, is quoted and escaped. This is the default for the specific info options. 🐚
  • json β€” A JSON object, whose values are all strings or arrays of strings. 🧚
  • value β€” The values only, one per line; a value that would be quoted in the shell format keeps its quotes. periodt.

Each format applies to whatever is selected: the summary, or exactly the values of the specific info options, e.g., ipcalc --format=json -n -m 192.168.1.5/24 prints only NETWORK and NETMASK. The specific info options accept all four formats; the formats each operation accepts are given in its description.

bestie listen πŸ‘‘ Scripts should always pass --format, so that their output does not depend on the defaults. don't be out here rawdogging the defaults in prod fr fr 😭

πŸ’… OPTIONS πŸ’…

  • -c, --check β€” Checks whether this is a valid IP address. When an IP family is specified only the addresses of that family are accepted. A zero exit status indicates a well formed address and a non-zero exit status indicates a malformed address. --format is ignored. (yes you can use this to gatekeep bad addresses πŸ’€)
  • --equals=NET, --subnet-of=NET, --overlaps=NET β€” Compare the provided network with NET and print the result, such as The networks overlap or 192.168.0.0/24 is a subnet of 192.168.0.0/23; nothing is printed with --silent. --equals holds if both have the same network address and prefix, --subnet-of if every address of the network is in NET (equal networks included), and --overlaps if the two share at least one address; for CIDR networks the latter holds exactly when one is a subnet of the other. Host bits are ignored, and NET is given in the same form as the provided address, with an optional prefix or netmask after a slash. Networks of different families never compare true. The exit status is 0 when the comparison holds, 1 when it does not, and 2 on any error, such as a malformed address. Only one comparison may be given, and not together with --check. The only format accepted is human. Example ipcalc 192.168.0.1/24 --subnet-of=192.168.0.0/23. πŸ”₯
  • -i, --info β€” Display basic information on the provided network in human readable format, in a short summary, plus the fields of any specific info options given (e.g., --reverse-dns). This is the default option if no other options are provided. The formats accepted are human, shell and json; with --format, the specific info options other than --lookup-host cannot be given. ✨
  • --all-info β€” Display all the information ipcalc can determine on the provided network and addresses in human readable format, which may be long. That includes geographic information, but not the hostname, which requires a DNS lookup (see --hostname). The formats accepted are as for --info. it's giving "tell me everything" energy πŸ’–

For an IPv6 unicast address it also prints the interface identifier, i.e., the low 64 bits of the address, unless they are all zero or the address lies in ::/3. When the interface identifier is a Modified EUI-64 (it contains ff:fe in its middle octets), it prints the EUI-64, the MAC address it was derived from, whether that MAC address is universally (UAA) or locally (LAA) administered (MAC scope: universal or local), and whether it is an individual or group address (MAC type). These fields are not derived from other interface identifiers, such as stable privacy or temporary addresses, whose bits carry no such meaning (RFC 7136). πŸ¦‹

  • -S, --split=[COUNT:]PREFIX β€” Split the provided network using the specified prefix or netmask. That is, split up the network into smaller chunks of a specified prefix. The formats accepted are human, json and value; with value, only the split networks are printed, one per line. Example:
ipcalc -S 26 192.168.1.0/24

The option can be repeated to split the network into subnets of different sizes, also known as a VLSM (variable-length subnet mask) split. Each request of the form COUNT:PREFIX asks for COUNT subnets of the given prefix or netmask, and at most one request without a count takes all the space that remains. Requests are allocated from the start of the network, the largest subnets first, while the subnets are printed in the order of the requests. Space that is not allocated to any request is printed as unused networks, except with --format=value. If the network is too small for the requests, nothing is printed and the exit status is 1. Example:

ipcalc -S 1:58 -S 64 2001:db8:1c88:6000::/56
  • --split-hosts=N1,N2,... β€” Split the provided network into subnets that hold N1, N2, ... hosts, one subnet for each count. Each subnet is the smallest that holds the hosts; for IPv4 that includes the network and broadcast addresses (e.g., 10 hosts need a /28). The subnets are allocated as with --split and printed with their details, followed by the needed size, the used network and the unused networks. The values are those of the split of the Debian ipcalc (its -s option), except that IPv6 networks are supported, a host count of 0 is rejected, and if the network is too small for the requests, nothing is printed and the exit status is 1. It cannot be combined with --split. The formats accepted are as for --split. Example:
ipcalc --split-hosts=10,20,30 192.168.0.0/24
  • -d, --deaggregate β€” Deaggregates the provided address range. That is, print the networks that cover the range. The range is given using the - separator, e.g., 192.168.1.3-192.168.1.23. The formats accepted are human, json and value; with value, only the networks are printed, one per line. 🌈
  • --binary β€” Displays the bits of the provided address or, when a prefix is given, the bits of the network part of the network; any host bits set in the address are ignored. By default it prints each octet of an IPv4 address, or each 16-bit group of an IPv6 address, above its bits, marks the host bits with x, and brackets the network and host parts with UTF-8 box-drawing characters. An IPv6 address is printed in two halves, or on a single line when the output is at least 135 columns wide (see COLUMNS). All four formats are accepted; with value, only the bits of the network are printed, as in NETWORK, e.g., 11000000101010000000000000000000 for 192.168.0.0/16. The variables exposed are the addresses of the output, each as all of its bits: ADDRESS when no prefix shorter than the address is given; otherwise PREFIX followed, for IPv4, by ADDRESS, NETMASK, NETWORK, HOSTMIN, HOSTMAX and BROADCAST (for a /31, without NETWORK and BROADCAST), and for IPv6 by NETWORK. The bits are not part of the summary, and the option cannot be combined with other operations or with the specific info options. πŸ’€
  • -r, --random-private β€” Generate a random private address using the supplied prefix or mask. By default it displays output in human readable format, but may be combined with other options (e.g., --network) to display specific information in VAR=VALUE format. 🎲
  • -h, --hostname β€” Display the hostname for the given IP address. The address must be a single address; a network (e.g., 127.0.0.1/8) is rejected. The variable exposed is HOSTNAME. πŸ”
  • -o, --lookup-host=NAME β€” Display the IP address for the given hostname. With --info or --all-info, display the summary of that address instead. The variable exposed is ADDRESS. 🫢
  • -4, --ipv4 β€” Explicitly specify the IPv4 address family. 🟦
  • -6, --ipv6 β€” Explicitly specify the IPv6 address family. πŸŸͺ
  • -b, --broadcast β€” Display the broadcast address for the given IP address and netmask. The variable exposed is BROADCAST (if available). πŸ“£
  • -a, --address β€” Display the IP address for the given input. The variable exposed is ADDRESS (if available). πŸ’–

  • -g, --geoinfo β€” bestie this one is the ✨geography✨ option, it shows you geographic info for the IP address you handed over. Heads up though: it needs libmaxminddb to exist on your system, and if ipcalc was built without it, it just won't accept this flag, periodt. The variables it exposes are CONTINENT, COUNTRYCODE, COUNTRY, CITY, POSTALCODE, COORDINATES (latitude,longitude), ACCURACYRADIUS, TIMEZONE (like Europe/Athens), ASN, ASORG, ASNETWORK and GEONETWORK (when it's available). So ASN is the number of the autonomous system that routes the address on the Internet β€” think the network of one single operator, like an ISP, a hosting provider or a company β€” and ASORG is the name of the org running it (e.g., ASN=1241 and ASORG=Forthnet; those show up as "Routed by AS" and "Operated by" in the summary). They come from the GeoLite2 ASN database, when it's installed. ASNETWORK is the network, in CIDR notation, that the database holds them for; and since that database is built from routing data, it approximates the network the autonomous system announces β€” e.g., the allocation of the ISP that your address belongs to. GEONETWORK is the network, in CIDR notation, the database holds the printed values for. When the database has no country for the address, COUNTRY and COUNTRYCODE become the country its users represent (like, say, a military base 🫑) or, if there isn't one of those either, the country where the network is registered. ACCURACYRADIUS is how accurate COORDINATES are β€” a radius in kilometers around them where the address is likely to be. The summary prints it with its unit, e.g., "Accuracy: 200 km". And for a network? A value only gets printed when the database knows it for the whole network, not just for the address you gave. no cap.
  • -m, --netmask β€” calculates the netmask for the IP address. If you don't provide a mask or prefix, IPv6 assumes a 128-bit mask, while IPv4 assumes your IP lives in a complete class A, B, or C network. ⚠️ But listen β€” so many networks don't use the default IPv4 netmasks anymore, so don't get too comfy with that assumption. The variable exposed is NETMASK.
  • --wildcard β€” shows the wildcard mask, aka the inverse of the netmask, the thing Cisco ACLs and OSPF vibe with, e.g., "0.0.0.255" for a /24 network. It's IPv4-only bestie, nothing prints for IPv6. Variable exposed is WILDCARD. The summary shows it when you pass --all-info.
  • -p, --prefix β€” shows the prefix for the mask/IP address. Variable exposed is PREFIX.
  • --class-prefix β€” assigns the netmask of the given IPv4 address based on the address class. This was literally the default in previous versions of this software, iykyk.
  • -n, --network β€” shows the network address for your IP address and netmask. Variable exposed is NETWORK.
  • --cidr β€” shows the network address and the prefix in CIDR notation, e.g., "192.168.123.0/24". The prefix is included for a single address too, slay. Variable exposed is CIDR. For example, ipcalc -r 24 --cidr --format=value prints a random private network. πŸŽ€
  • --reverse-dns β€” shows the reverse DNS for the given IP address and netmask. Now here's the tea: reverse DNS domains for IPv6 (RFC 3596) can only be delegated at 4-bit boundaries, so for an IPv6 prefix that is not a multiple of 4, the network is covered by up to 8 domains, and all of them get printed. In that case the REVERSEDNS variable holds a quoted, space-separated list, and with --format=value each domain prints on its own line. The summary shows it with --all-info, and in JSON REVERSEDNS is always an array. Variable exposed is REVERSEDNS.
  • --minaddr β€” shows the minimum host address in the provided network. Variable exposed is MINADDR.
  • --maxaddr β€” shows the maximum host address in the provided network. Variable exposed is MAXADDR.
  • --addresses β€” shows the number of host addresses in the provided network. Variable exposed is ADDRESSES.
  • --addrspace β€” shows address space allocation info for the provided network. Variable exposed is ADDRSPACE.
  • --format=FORMAT β€” prints the output as human, shell, json or value; peek the Output format section for the deets. πŸ’…
  • -s, --silent β€” never ever displays error messages, and never shows the result of a comparison. 🀫

πŸ’€ Deprecated options πŸ’€

These are kept around for compatibility with earlier versions. On a terminal, ipcalc prints a little hint that names the replacement, so you're not left guessing. 🫢

  • -j, --json β€” prints the summary as a JSON object, even when specific info options are given, which only add their values to it; with --split, --split-hosts, --deaggregate and --binary it prints JSON, and with the comparison options it prints nothing. Use --format=json instead β€” that prints only the selected values. ✨
  • --no-decorate β€” prints the values of the specific info options, or the networks of --split, --split-hosts and --deaggregate, without titles; prints the summary without colors; and with the comparison options prints nothing. It's ignored when -j is given, and it can't be used with --binary. Use --format=value instead, or for the summary use --format=human with the NO_COLOR environment variable set.

🌈 Environment 🌈

  • NO_COLOR β€” when it's set, to any value, the human format prints without colors, even on a terminal. bye bye rainbows 😭
  • COLUMNS β€” the width of the output in columns. With --binary, an IPv6 address prints on a single line when it's 135 or more, and in two halves otherwise, e.g., "COLUMNS=135 ipcalc --binary 2001:db8::/48". When it's unset, the width of the terminal is used, or 80 when the output isn't a terminal. πŸ“

🌸 EXAMPLES 🌸 (aka the part where it all clicks, bestie)

πŸ’« Display all information of an IPv4

$ ipcalc --all-info 193.92.150.2/24
Address:        193.92.150.2
Network:        193.92.150.0/24
Netmask:        255.255.255.0 = 24
Wildcard:       0.0.0.255
Broadcast:      193.92.150.255
Reverse DNS:    150.92.193.in-addr.arpa.

Address space:  Internet
Address class:  Class C
HostMin:        193.92.150.1
HostMax:        193.92.150.254
Hosts/Net:      254

Country code:   GR
Country:        Greece

Look at that. Everything. Network, netmask, wildcard, broadcast, reverse DNS, address space, class, host range, host count, and even the country. It's giving full dossier. πŸ•΅οΈβ™€οΈ

πŸ’« Display information in key-value format

$ ipcalc --format=shell -pnmb --minaddr --maxaddr --geoinfo --addrspace 193.92.150.2/255.255.255.224
NETWORK=193.92.150.0
NETMASK=255.255.255.224
PREFIX=27
BROADCAST=193.92.150.31
ADDRSPACE=Internet
MINADDR=193.92.150.1
MAXADDR=193.92.150.30
COUNTRYCODE=GR
COUNTRY=Greece

This is the "pls just hand me variables so I can eval you" format and honestly it ate. ✨

πŸ’« Display all information of an IPv6

$ ipcalc --all-info 2a03:2880:20:4f06:face:b00c:0:14/64
Full Address:   2a03:2880:0020:4f06:face:b00c:0000:0014
Address:        2a03:2880:20:4f06:face:b00c:0:14
Full Network:   2a03:2880:0020:4f06:0000:0000:0000:0000/64
Network:        2a03:2880:20:4f06::/64
Netmask:        ffff:ffff:ffff:ffff:: = 64
Reverse DNS:    6.0.f.4.0.2.0.0.0.8.8.2.3.0.a.2.ip6.arpa.

Address space:  Global Unicast
Interface ID:   face:b00c:0000:0014
HostMin:        2a03:2880:20:4f06::
HostMax:        2a03:2880:20:4f06:ffff:ffff:ffff:ffff
Hosts/Net:      2^(64) = 18446744073709551616

Country code:   IE
Country:        Ireland

Sixteen quintillion hosts in one net, no big deal. And note that Hosts/Net shows you the math too β€” 2^(64) = 18446744073709551616 β€” because we don't gatekeep. πŸ‘‘

$ ipcalc --all-info fe80::21b:21ff:fe3a:5c7d/64
Full Address:   fe80:0000:0000:0000:021b:21ff:fe3a:5c7d
Address:        fe80::21b:21ff:fe3a:5c7d
Full Network:   fe80:0000:0000:0000:0000:0000:0000:0000/64
Network:        fe80::/64
Netmask:        ffff:ffff:ffff:ffff:: = 64
Reverse DNS:    0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa.

Address space:  Link-Scoped Unicast
Interface ID:   021b:21ff:fe3a:5c7d
EUI-64:         00:1b:21:ff:fe:3a:5c:7d
MAC address:    00:1b:21:3a:5c:7d
MAC scope:      universal
MAC type:       individual
HostMin:        fe80::
HostMax:        fe80::ffff:ffff:ffff:ffff
Hosts/Net:      2^(64) = 18446744073709551616

Not it un-embedding a whole MAC address out of the interface ID like that πŸ” The EUI-64 line, the MAC address, the scope, the type β€” all just there. Main character energy, fr fr.

πŸ’« Display JSON output

$ ipcalc --all-info --format=json 2a03:2880:20:4f06:face:b00c:0:14/64
{
  "FULLADDRESS":"2a03:2880:0020:4f06:face:b00c:0000:0014",
  "ADDRESS":"2a03:2880:20:4f06:face:b00c:0:14",
  "FULLNETWORK":"2a03:2880:0020:4f06:0000:0000:0000:0000",
  "NETWORK":"2a03:2880:20:4f06::",
  "NETMASK":"ffff:ffff:ffff:ffff::",
  "PREFIX":"64",
  "CIDR":"2a03:2880:20:4f06::/64",
  "REVERSEDNS":[
    "6.0.f.4.0.2.0.0.0.8.8.2.3.0.a.2.ip6.arpa."],
  "ADDRSPACE":"Global Unicast",
  "INTERFACEID":"face:b00c:0000:0014",
  "MINADDR":"2a03:2880:20:4f06::",
  "MAXADDR":"2a03:2880:20:4f06:ffff:ffff:ffff:ffff",
  "ADDRESSES":"18446744073709551616",
  "COUNTRYCODE":"IE",
  "COUNTRY":"Ireland",
  "COORDINATES":"53.000000,-8.000000"
}

For when your script needs structured data and not vibes. (Tho we contain multitudes β€” we can do both.) 🫢

πŸ’« Split a network into subnets of different sizes

$ ipcalc -S 1:28 -S 2:27 192.168.0.0/24
[Split networks]
Network:        192.168.0.64/28
Network:        192.168.0.0/27
Network:        192.168.0.32/27

Total:          3

[Unused networks]
Network:        192.168.0.80/28
Network:        192.168.0.96/27
Network:        192.168.0.128/25

Bestie it even tells you the unused networks. Nothing left on read. πŸ’…

πŸ’« Split a network into subnets for a number of hosts

$ ipcalc --split-hosts=10,20 192.168.0.0/24
[Split networks]
1. Requested size: 10 hosts
Network:        192.168.0.32/28
Netmask:        255.255.255.240 = 28
Broadcast:      192.168.0.47
HostMin:        192.168.0.33
HostMax:        192.168.0.46
Hosts/Net:      14

2. Requested size: 20 hosts
Network:        192.168.0.0/27
Netmask:        255.255.255.224 = 27
Broadcast:      192.168.0.31
HostMin:        192.168.0.1
HostMax:        192.168.0.30
Hosts/Net:      30

Total:          2
Needed size:    48
Used network:   192.168.0.0/26

[Unused networks]
Network:        192.168.0.48/28
Network:        192.168.0.64/26
Network:        192.168.0.128/25

You asked for hosts, it gave you hosts, and it also told you the Needed size, the Used network, and what's still free. Generous queen. πŸ‘‘

πŸ’« Split an IPv6 prefix into one /58 and /64 networks in the remaining space

$ ipcalc --format=value -S 1:58 -S 64 2001:db8:1c88:6000::/56
2001:db8:1c88:6000::/58
2001:db8:1c88:6040::/64
2001:db8:1c88:6041::/64
...
2001:db8:1c88:60ff::/64

Yes queen, carve up that IPv6 space. πŸ¦‹

πŸ’« Display the bits of a network

$ ipcalc --binary 192.168.92.6/22
Network:    192.168.92.0/22

                                  192.     168.   92-95.   0-255
                             11000000.10101000.010111xx.xxxxxxxx
                             └──── network /22 β”€β”€β”€β”€β”€β”˜β”” host 10 β”˜

Address:    192.168.92.6     11000000.10101000.01011100.00000110
Netmask:    255.255.252.0    11111111.11111111.11111100.00000000
Network:    192.168.92.0     11000000.10101000.01011100.00000000
HostMin:    192.168.92.1     11000000.10101000.01011100.00000001
HostMax:    192.168.95.254   11000000.10101000.01011111.11111110
Broadcast:  192.168.95.255   11000000.10101000.01011111.11111111

Not the xxs showing you exactly which bits are host bits 😭 this is the visual you show your group chat when someone asks "wait what even IS a /22". Iconic.

πŸ’« Check whether a network is a subnet of another

$ ipcalc 192.168.0.1/24 --subnet-of=192.168.1.15/23
192.168.0.0/24 is a subnet of 192.168.0.0/23

Short. Direct. Answered in one line. πŸ’œ

πŸ’« Check whether a network overlaps any network in a list

$ while read net; do
>   ipcalc -s 10.20.0.0/16 --overlaps="$net"
>   case $? in 0) echo "conflict: $net" ;; 2) echo "bad entry: $net" ;; esac
> done < networks.txt

This is THE vibe-check-the-whole-firewall-ruleset move. 0 means conflict, 2 means bad entry, and you get a whole audit loop in four lines. πŸ”₯

πŸ’« Lookup of a hostname

$ ipcalc --format=value --lookup-host localhost
::1

πŸ’« IPv4 lookup of a hostname

$ ipcalc --format=value --lookup-host localhost -4
127.0.0.1

πŸ’« Reverse lookup of a hostname

$ ipcalc --format=value -h 127.0.0.1
localhost

Forward and reverse, both directions, both protocols. Obsessed. πŸŽ€

πŸ’« Use the values in a shell script

$ eval "$(ipcalc --format=shell -n -p 192.168.1.5/24)"
$ echo "$NETWORK/$PREFIX"
192.168.1.0/24

The eval + --format=shell combo is the whole hack. It just works. 🌈


πŸ‘‘ AUTHORS πŸ‘‘

  • Nikos Mavrogiannopoulos n.mavrogiannopoulos@gmail.com
  • Erik Troan ewt@redhat.com
  • Preston Brown pbrown@redhat.com
  • David Cantrell dcantrell@redhat.com

The legends who built the thing. Respect. 🫑


πŸ› REPORTING BUGS πŸ›

Found a bug? Report it at <https://gitlab.com/ipcalc/ipcalc/issues> β€” that's the spot. Fr fr, they wanna know. πŸ”


Copyright Β© 1997-2024 Red Hat, Inc. Copyright Β© 2020-2024 Nikos Mavrogiannopoulos. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Say it with me: NO warranty. Not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It's free software, bestie, not a promise. 😭

And that's the whole page, bestie!! πŸ’–βœ¨ This one's IPCALC(1) from the ipcalc source, dated October 2026. Go forth and subnet responsibly. πŸ¦‹πŸŒΈπŸ’…

πŸ“¦ where this page comes from