Private LAN IP addresses

Revision as of 10:47, 25 September 2013 by Root (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

These IP addresses are reserved for private networks (sometimes called localnet). These are routable only in a LAN; WAN gateways will not route the following IP addresses. The range is the most familiar. Often forgotten is the range.

IANA Reserved Private Network Ranges Start of range End of range Total addresses
24-bit Block (/8, 1 x A) 16777216
20-bit Block (/12, 16 x B) 1048576
16-bit Block (/16, 256 x C) 65536
Link-local Zeroconf (/16 minus the first and last /24 ranges) 65026


A regex to match an arbitrary IPv4 address can be quite tricky. The following get close for testing against private IP addresses.

# localhost
allow ^127\.0\.0\.1$
# localnets
allow ^192\.168\.\d+\.\d+$
allow ^172\.(1[6-9]|2[0-9]|3[01])\.\d+\.\d+$
allow ^10\.\d+\.\d+\.\d+$
# Link-local Zeroconf (/16 minus the first and last /24 ranges)
# WARNING: this should exclude the first and last /24 ranges, but it does not.
# This shouldn't matter since the first and last /24 ranges are reserved.
allow ^169\.254\.\d+\.\d+$