DNSBL (DNS blacklisting) module for HAProxy Lua. Dynamically block requests based on the response of the DNS query or use any of the added extra request headers to make decisions down the line.
- Query multiple DNSBL providers (Tor exit lists, Spamhaus, etc.)
- Cache results using HAProxy stick-tables for optimal performance
- Configurable track-sc index (sc0, sc1, sc2) for flexible stick-table usage
- Detailed HTTP headers for logging and downstream processing
- Fail-open design - errors don't block legitimate traffic
| Provider | Domain | Description |
|---|---|---|
| Dan.me.uk Tor List | .torexit.dan.me.uk |
Tor exit node list |
| Tor Project | .exitlist.torproject.org |
Official Tor exit list |
| Spamhaus SBL | sbl.spamhaus.org |
Spam sources |
| Spamhaus XBL | xbl.spamhaus.org |
Exploits/botnets |
| Spamhaus PBL | pbl.spamhaus.org |
Policy block list |
| Spamhaus ZEN | zen.spamhaus.org |
Combined list |
global
lua-load /usr/share/lua/5.3/dnsbl.lua
backend st_dnsbl_cache
stick-table type ipv6 size 1m expire 30m store gpc0,gpc1
frontend http-in
bind *:80
http-request track-sc0 src table st_dnsbl_cache
http-request lua.dnsbl_query st_dnsbl_cache .torexit.dan.me.uk "" ""
http-request lua.dnsbl_block st_dnsbl_cache
default_backend servershaproxy-lua-dnsbl depends on utils and socket library. Download copies to your Lua path:
# Install to Lua path (e.g., /usr/share/lua/5.3/)
cp src/dnsbl.lua /usr/share/lua/5.3/
# Install dependencies
wget -O /usr/share/lua/5.3/utils.lua \
https://raw.githubusercontent.com/dobrevit/haproxy-lua-utils/main/src/utils.luaFull documentation is available in the docs folder:
- Documentation Index
- Architecture Overview - How the module works
- API Reference - Complete function documentation
- Configuration Guide - HAProxy setup instructions
- Understanding DNSBL - How DNS blacklists work
- HTTP Headers Reference - Headers set by the module
- Troubleshooting - Common issues and solutions
The examples folder contains ready-to-use configurations:
| Example | Description |
|---|---|
| Basic | Minimal working configuration |
| Behind Proxy | Using X-Forwarded-For header |
| Multiple DNSBLs | Querying multiple providers |
| Docker | Complete Docker test environment |
| Logging | Custom log formats with DNSBL headers |
http-request lua.dnsbl_query <backend> <domain> <src_var> <src_header> [sc_index]
http-request lua.dnsbl_block <backend>| Parameter | Description |
|---|---|
backend |
Backend name containing the stick-table |
domain |
DNSBL domain (e.g., .torexit.dan.me.uk) |
src_var |
HAProxy variable with client IP (optional) |
src_header |
HTTP header with client IP (optional) |
sc_index |
Track-sc index: 0, 1, or 2 (optional, default: 0) |
# Basic - direct client IP
http-request lua.dnsbl_query st_cache .torexit.dan.me.uk "" ""
# Behind proxy - use X-Forwarded-For
http-request lua.dnsbl_query st_cache .torexit.dan.me.uk "" X-Forwarded-For
# Use sc1 instead of sc0
http-request lua.dnsbl_query st_cache .torexit.dan.me.uk "" "" 1
# Multiple providers with different track-sc indices
http-request track-sc0 src table st_tor
http-request track-sc1 src table st_spam
http-request lua.dnsbl_query st_tor .torexit.dan.me.uk "" "" 0
http-request lua.dnsbl_query st_spam xbl.spamhaus.org "" "" 1The library uses the socket.dns class to make DNS queries. The DNSBL domain is expected to return:
- NXDOMAIN - IP is not blacklisted (request allowed)
- A record response - IP is blacklisted (request blocked)
Results are cached using HAProxy's stick-table with gpc0 and gpc1 counters:
gpc0 = 1→ IP was checked and allowedgpc1 = 1→ IP was checked and blocked
The module sets these headers on each request:
| Header | Description |
|---|---|
X-DNSBL-Action |
Result: CACHE-ALLOW, LOOKUP-DENY, etc. |
X-DNSBL-Is-Allowed |
1 if allowed, 0 if blocked |
X-DNSBL-Client-IP |
IP address that was checked |
X-DNSBL-Query |
DNS query that was made |
X-DNSBL-Zone |
Spamhaus zone (if applicable) |
X-DNSBL-Description |
Block reason (if applicable) |
- Added support for
.exitlist.torproject.orgdomain - Added support for Spamhaus domains (sbl, xbl, pbl, zen)
- Added configurable track-sc index (sc0, sc1, sc2)
- Added
X-DNSBL-ZoneandX-DNSBL-Descriptionheaders - Added comprehensive documentation and examples
- Initial public release
- Support for
.torexit.dan.me.ukdomain
- Only A record DNS queries are supported (not AAAA)
- Spamhaus may rate-limit queries from public DNS resolvers
Bug reports and pull requests are welcome on GitHub at https://github.com/dobrevit/haproxy-lua-dnsbl/issues.
MIT License
Copyright (c) 2023 Dobrev IT Ltd., Martin Dobrev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.