// ipinfo.app

Firewall Guides

using asn prefix lists in real infrastructure · automation patterns · community tools

// Introduction

Every ASN on the internet announces a set of CIDR prefixes — the IP ranges that belong to that network. asn.ipinfo.app exposes those prefix lists in formats ready to drop directly into your firewall, web server, or router config. Data is sourced from iptoasn.com via the Atlas service and is updated daily.

Common uses include blocking entire cloud provider ranges, restricting access to known ASNs, setting up BGP null-route communities (RTBH), and building automated threat intelligence feeds from AS reputation data.

// URL Patterns

All format endpoints follow the same pattern. Replace {format} with the format name and {asn} with the AS number (bare or AS-prefixed):

https://asn.ipinfo.app/api/text/{format}/AS{asn}

https://asn.ipinfo.app/api/download/{format}/AS{asn}

https://asn.ipinfo.app/api/json/{format}/AS{asn}

The /text/ tree returns plain text (one line per entry), useful for piping directly into bash. The /download/ tree is identical but adds Content-Disposition: attachment so browsers save it as a file. The /json/ tree wraps the list in a { name, type, list } envelope for programmatic use.

Tip: Always use the /text/ URL in shell scripts — it's a direct pipe with no JSON parsing required. Use curl -s to suppress the progress bar.
// Linux — ipset

ipset is the recommended approach for large prefix lists on Linux. It's far more efficient than individual iptables rules — a 5,000-prefix ASN is a single hash lookup rather than 5,000 rule evaluations. The downloaded script creates two named sets (AS{n}-4 for IPv4, AS{n}-6 for IPv6) and populates them in one pass.

One-liner — apply immediately
# Requires: ipset, iptables/ip6tables
curl -s https://asn.ipinfo.app/api/text/ipset/AS13335 | bash
Then wire the sets into iptables
# Drop all inbound traffic from Cloudflare (AS13335)
iptables  -I INPUT -m set --match-set AS13335-4 src -j DROP
ip6tables -I INPUT -m set --match-set AS13335-6 src -j DROP
Block multiple ASNs at once
for ASN in 13335 15169 16509; do
  curl -s "https://asn.ipinfo.app/api/text/ipset/AS${ASN}" | bash
done

# Wire all sets
for ASN in 13335 15169 16509; do
  iptables  -I INPUT -m set --match-set AS${ASN}-4 src -j DROP
  ip6tables -I INPUT -m set --match-set AS${ASN}-6 src -j DROP
done
Note: ipset sets are lost on reboot unless persisted with ipset save / ipset restore or an equivalent service (e.g. netfilter-persistent on Debian).
// Linux — iptables

The iptables format generates one rule per prefix. It works without ipset but is much slower to evaluate at scale — use ipset for ASNs with more than a few hundred prefixes. IPv6 prefixes automatically use ip6tables.

Apply directly
# Each prefix becomes an iptables INPUT DROP rule
curl -s https://asn.ipinfo.app/api/text/iptables/AS13335 | bash
Save to a file and apply later
curl -s https://asn.ipinfo.app/api/download/iptables/AS13335 \
  -o /etc/iptables/block-AS13335.rules

# Review, then apply
bash /etc/iptables/block-AS13335.rules
// Linux — Null Routing (Blackhole)

Blackhole routes install static routes with a blackhole nexthop, causing the kernel to silently discard all traffic to those prefixes. This operates at the routing layer (before netfilter) and is useful for high-volume DoS mitigation. It's also the building block for BGP RTBH (Remotely Triggered Black Hole) — announce the blackhole route to your upstream and they'll null-route the traffic before it reaches you.

Add blackhole routes
# Installs: ip route add blackhole <prefix> for every prefix in AS13335
curl -s https://asn.ipinfo.app/api/text/ipblackhole/AS13335 | bash
Remove blackhole routes
# Removes all the routes added above
curl -s https://asn.ipinfo.app/api/text/ipblackholerem/AS13335 | bash
Download files use the PHP-compatible naming convention: ipblackhole_remove_13335.txt for the remove variant.
// nginx

The nginx format generates deny directives, one per prefix. These can be included inside a geo block to set a variable, or placed directly in a location context to block access. Using geo is preferred for large lists because nginx compiles geo blocks into an efficient radix tree.

Download the deny list
curl -s https://asn.ipinfo.app/api/text/nginx/AS13335 \
  -o /etc/nginx/asn/block-AS13335.conf
/etc/nginx/nginx.conf (geo approach)
geo $block_as13335 {
    default 0;
    include /etc/nginx/asn/block-AS13335.conf;  # deny lines set geo var to 1
}

# Wait — the downloaded file uses `deny x.x.x.x/n;` syntax,
# not geo pairs. For a geo block use the list format instead:
Download as a plain CIDR list for geo blocks
# Plain CIDR list — one prefix per line
curl -s https://asn.ipinfo.app/api/text/list/AS13335 \
  | awk '{print $1, "1;"}' \
  > /etc/nginx/asn/geo-AS13335.conf

# Then in nginx.conf:
geo $block_as13335 {
    default 0;
    include /etc/nginx/asn/geo-AS13335.conf;
}

server {
    if ($block_as13335) { return 403; }
}
Or use deny directives directly in a location block
location / {
    include /etc/nginx/asn/block-AS13335.conf;
    allow all;
}

# Reload after updating
nginx -s reload
// Apache — .htaccess

The htaccess format generates mod_access_compat deny rules, compatible with Apache 2.4 when the mod_access_compat module is enabled. The list always starts with Order Deny,Allow.

Requires mod_access_compat — enabled with a2enmod access_compat on Debian/Ubuntu. For large ASNs, consider using mod_authz_host or a network-level solution instead.
Append to .htaccess
# Download and append to an existing .htaccess
curl -s https://asn.ipinfo.app/api/text/htaccess/AS13335 >> /var/www/html/.htaccess
Example output in .htaccess
Order Deny,Allow
Deny from 104.16.0.0/12
Deny from 172.64.0.0/13
Deny from 2606:4700::/32
...
// Cisco ASA

The Cisco format generates object network statements for Cisco ASA. IPv4 entries use dotted-decimal subnet masks; IPv6 entries use CIDR notation. Objects are named sequentially: {asn}-4-SN0, {asn}-4-SN1, … for IPv4 and {asn}-6-SN0, … for IPv6.

Download the config
curl -s https://asn.ipinfo.app/api/download/cisco/AS13335 \
  -o cisco_AS13335.txt
Example output
object network 13335-4-SN0
 subnet 104.16.0.0 255.240.0.0
object network 13335-4-SN1
 subnet 172.64.0.0 255.248.0.0
object network 13335-6-SN0
 subnet 2606:4700::/32
...

Paste the output into an ASDM text config import or an SSH session. After defining the objects, group them into an object-group network and reference it in your ACL.

// Juniper JunOS

The Juniper format generates set policy-options prefix-list statements. IPv4 prefixes are added to the {asn}v4 list; IPv6 prefixes go into {asn}v6.

Download and apply via SSH
# Download locally
curl -s https://asn.ipinfo.app/api/download/juniper/AS13335 \
  -o juniper_AS13335.txt

# Pipe into a JunOS commit session (adjust credentials/host)
{ echo "configure"; cat juniper_AS13335.txt; echo "commit"; } \
  | ssh user@router -T
Example output
set policy-options prefix-list 13335v4 104.16.0.0/12
set policy-options prefix-list 13335v4 172.64.0.0/13
set policy-options prefix-list 13335v6 2606:4700::/32
...
// Automation — Cron Jobs

IP ranges for any given ASN change over time — cloud providers add and remove prefixes as they grow or reorganize. A daily cron job that re-fetches and re-applies the rules keeps your firewall current without manual intervention.

Daily ipset refresh (recommended)
# /etc/cron.daily/refresh-asn-blocks  (chmod +x)
#!/bin/bash
set -euo pipefail

ASNS="13335 15169 16509"  # Cloudflare, Google, Amazon

for ASN in $ASNS; do
  # Flush the existing sets so removed prefixes don't linger
  ipset flush AS${ASN}-4 2>/dev/null || true
  ipset flush AS${ASN}-6 2>/dev/null || true

  # Re-create and populate from the live list
  curl -sf "https://asn.ipinfo.app/api/text/ipset/AS${ASN}" | bash
done

# Persist so rules survive reboot
ipset save > /etc/ipset.conf
Daily nginx geo list refresh
# /etc/cron.daily/refresh-nginx-geo
#!/bin/bash
curl -sf https://asn.ipinfo.app/api/text/list/AS13335 \
  | awk '{print $1, "1;"}' \
  > /etc/nginx/asn/geo-AS13335.conf

nginx -t && nginx -s reload
Use curl -sf (silent + fail-on-error). Without -f, a 502 response from a temporarily unavailable upstream would overwrite your rules with an error page.
// Automation — Reusable Shell Script

A single script that handles multiple ASNs, with proper error handling and idempotent ipset management.

block-asns.sh
#!/bin/bash
# block-asns.sh — fetch ASN prefix lists and apply via ipset/iptables
# Usage: ./block-asns.sh 13335 15169 16509
# Requires: curl, ipset, iptables, ip6tables

set -euo pipefail

BASE="https://asn.ipinfo.app/api/text/ipset"

for ASN in "$@"; do
  echo "==> Blocking AS${ASN}..."

  # Flush existing sets (no-op if they don't exist yet)
  ipset flush  "AS${ASN}-4" 2>/dev/null || true
  ipset flush  "AS${ASN}-6" 2>/dev/null || true
  ipset destroy "AS${ASN}-4" 2>/dev/null || true
  ipset destroy "AS${ASN}-6" 2>/dev/null || true

  # Create sets and populate from live data
  curl -sf "${BASE}/AS${ASN}" | bash

  # Wire into iptables (idempotent — check-or-insert)
  iptables  -C INPUT -m set --match-set "AS${ASN}-4" src -j DROP 2>/dev/null \
    || iptables  -I INPUT -m set --match-set "AS${ASN}-4" src -j DROP
  ip6tables -C INPUT -m set --match-set "AS${ASN}-6" src -j DROP 2>/dev/null \
    || ip6tables -I INPUT -m set --match-set "AS${ASN}-6" src -j DROP

  echo "    Done ($(ipset list AS${ASN}-4 | grep -c '^[0-9]') IPv4 + $(ipset list AS${ASN}-6 | grep -c '^[0-9:]') IPv6 prefixes)"
done

ipset save > /etc/ipset.conf
echo "==> ipset rules saved."
// Community

ASN prefix lists are used across the security and networking community for everything from datacenter ingress filtering to home-lab threat intelligence feeds. Below are open source tools that embody the same use cases — blocking, monitoring, and automating around AS-level IP data.

Bash / UFW / Pi-Hole

Multi-layer home network security system. Generates UFW firewall blocklists from ASN-based IP ranges targeting datacenter and server-rental ASNs, with Pi-Hole domain blocking layered on top. Manages 50,000+ blocked subnet entries.

SourceMod / CS:GO / TF2

Source Engine game server plugin that blocks players connecting from datacenter or VPN IP ranges. Uses ASN prefix lists to populate a MySQL CIDR blocklist database, with per-ASN kick messages and a player whitelist.

Building something with asn.ipinfo.app? Let us know and we'll add it here.