Seif Eddine Segueni
Seif Eddine Segueni

Reputation: 21

How to check if a given IP @ is a subnet @ address?

Is there a way to check if a given IP address is a subnet IP address ? For example : 16.100.134.0 /19 this IP address is a subnet ip address (I saw it in the solution ) but I still don't know how they figure it out.

Upvotes: 2

Views: 3123

Answers (2)

vikas027
vikas027

Reputation: 5762

@Chris has explained it well in his answer. This is how I do it

  • CLI: Use a utility called prips.

Example:

❯ prips 20.13.16.0/30                 
20.13.16.0
20.13.16.1
20.13.16.2
20.13.16.3

# If your range is big (example /22), then you can also use grep
❯ prips 20.13.16.0/30 | grep 20.13.16.3
20.13.16.3

enter image description here

Upvotes: 0

Chris
Chris

Reputation: 1804

The /19 at the end tells you that this is a subnet address.

A complete IPV4 address is 4 lots of 8 bits or octets (each shown as a decimal in the range 0 -255) so 32 bits long. /19 tells you that this is the address of a subnet where the first 19 bits are reserved for the network and subnet address and the remaining 13 are for hosts within the subnet. A subnet means that part of the host space has been used to divide up the network into smaller networks. In this case the network address may be 16.100.0.0 /16 and the subnet uses the first 3 significant bits of the host space to split it into up to 8 subnets.

So that 13 bits means up to 2¹³-1 different IP addresses available - the last octet can take values between 0 and 255, and the second last between 134 + 0 and 134 + 31

It's maybe easier to see that in binary. The address you have there is 00010000.01100100.10000110.00000000 and valid IP addresses should be in the range 00010000.01100100.10000000.00000000 and 00010000.01100100.10011111.11111111 which makes me think you have the address of a host in the subnet - the subnet address would have all 0s for the 13 least significant bits, meaning the third octet would only have it's 3 most significant bits available ie it would have a value one of 0, 32, 64, 128, 96, 192 or 224

Upvotes: 2

Related Questions