Implementing IP Filtering and Access Control

1. Configuring IP Allowlists (CIDR notation)

CIDRRangeHosts
10.0.0.0/810.0.0.0 - 10.255.255.25516.7M
172.16.0.0/12172.16 - 172.311M
192.168.0.0/16192.168.*.*65K
203.0.113.0/24Office subnet256
198.51.100.42/32Single host1

Example: IP allowlist (Kong)

plugins:
  - name: ip-restriction
    config:
      allow: ["10.0.0.0/8", "203.0.113.0/24"]
      status: 403
      message: "Access denied"

2. Setting Up IP Blocklists

SourceExamples
StaticKnown bad IPs
Threat feedSpamhaus, AbuseIPDB
Tor exit nodestorproject.org list
DynamicAuto-add after N abuse hits

3. Using Geographic IP Filtering

Example: Geo-block sanctioned regions

geoip2 /etc/geoip2/GeoLite2-Country.mmdb {
  $geoip_country source=$remote_addr country iso_code;
}
map $geoip_country $blocked {
  default 0;
  CU 1; IR 1; KP 1; SY 1;
}
if ($blocked) { return 451; }

4. Implementing Dynamic IP Rules

MechanismExample
Hot reloadWatch file/Redis set
Adaptive banFail2ban-style auto-add
TTL expiryTemp bans auto-clear
Severity tiersSoft warn → throttle → block

5. Configuring IP Range Validation

CheckPurpose
Bogon detectReject private IPs at edge
Reserved ranges0.0.0.0/8, 127/8
Multicast224.0.0.0/4 reject
LoopbackOnly allow from local proxy

6. Setting Up Proxy IP Detection

Example: Trust forward header chain

set_real_ip_from 10.0.0.0/8;
set_real_ip_from 172.16.0.0/12;
real_ip_header X-Forwarded-For;
real_ip_recursive on;
# Last untrusted IP becomes $remote_addr
HeaderFormat
X-Forwarded-Forclient, proxy1, proxy2
X-Real-IPSingle original
Forwarded (RFC 7239)for=1.2.3.4;proto=https
PROXY protocolTCP-level header

7. Using IP Reputation Filtering

ProviderData
CloudflareThreat score 0-100
Project HoneypotComment/dictionary spam
AbuseIPDBCrowdsourced abuse
MaxMind minFraudRisk score

8. Implementing IPv6 Support

AddressNotes
::1IPv6 loopback
fe80::/10Link-local
fc00::/7Unique local (private)
2000::/3Global unicast (public)
2001:db8::/32Documentation
Note: Listen with [::]:443 for dual-stack; rate-limit per /64 IPv6 prefix (not /128) since users get whole /64.

9. Configuring VPN Detection

MethodDetection
ASN lookupDatacenter ASNs (AWS, OVH)
VPN provider DBIPQualityScore, IP2Proxy
DNS leakMismatch IP vs DNS resolver
Latency profileTunnel adds detectable RTT

10. Setting Up IP-Based Routing

Example: Route by source CIDR

geo $backend {
  default          public-backend;
  10.0.0.0/8       internal-backend;
  192.0.2.0/24     partner-backend;
}
location / { proxy_pass http://$backend; }