Shorewall Blacklisting Support

Tom Eastep

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover, and with no Back-Cover Texts. A copy of the license is included in the section entitled “GNU Free Documentation License”.

2007/07/19


Table of Contents

Introduction
Static Blacklisting
Dynamic Blacklisting

Introduction

Shorewall supports two different forms of blacklisting; static and dynamic. The BLACKLISTNEWONLY option in /etc/shorewall/shorewall.conf controls the degree of blacklist filtering:

  1. BLACKLISTNEWONLY=No --  All incoming packets are checked against the blacklist. New blacklist entries can be used to terminate existing connections.

  2. BLACKLISTNEWONLY=Yes -- The blacklists are only consulted for new connection requests. Blacklists may not be used to terminate existing connections. Only the source address is checked against the blacklists.

Important

Only the source address is checked against the blacklists. Blacklists only stop blacklisted hosts from connecting to you — they do not stop you or your users from connecting to blacklisted hosts .

Important

Dynamic Shorewall blacklisting is not appropriate for blacklisting 1,000s of different addresses. Static Blacklisting can handle large blacklists but only if you use ipsets. Without ipsets, the blacklists will take forever to load, and will have a very negative effect on firewall performance.

Static Blacklisting

Shorewall static blacklisting support has the following configuration parameters:

  • You specify whether you want packets from blacklisted hosts dropped or rejected using the BLACKLIST_DISPOSITION setting in /etc/shorewall/shorewall.conf.

  • You specify whether you want packets from blacklisted hosts logged and at what syslog level using the BLACKLIST_LOGLEVEL setting in /etc/shorewall/shorewall.conf.

  • You list the IP addresses/subnets that you wish to blacklist in /etc/shorewall/blacklist. You may also specify PROTOCOL and Port numbers/Service names in the blacklist file.

  • You specify the interfaces whose incoming packets you want checked against the blacklist using the “blacklist” option in /etc/shorewall/interfaces.

  • The black list is refreshed from /etc/shorewall/blacklist by the “shorewall refresh” command.

Users with a large static black list may want to set the DELAYBLACKLISTLOAD option in shorewall.conf (added in Shorewall version 2.2.0). When DELAYBLACKLISTLOAD=Yes, Shorewall will enable new connections before loading the blacklist rules. While this may allow connections from blacklisted hosts to slip by during construction of the blacklist, it can substantially reduce the time that all new connections are disabled during "shorewall [re]start".

Beginning with Shorewall 2.4.0, you can use ipsets to define your static blacklist. Here's an example:

#ADDRESS/SUBNET         PROTOCOL        PORT
+Blacklistports[dst]
+Blacklistnets[src,dst]
+Blacklist[src,dst]
#LAST LINE -- ADD YOUR ENTRIES BEFORE THIS ONE -- DO NOT REMOVE

In this example, there is a portmap ipset Blacklistports that blacklists all traffic with destination ports included in the ipset. There are also Blacklistnets (type nethash) and Blacklist (type iphash) ipsets that allow blacklisting networks and individual IP addresses. Note that [src,dst] is specified so that individual entries in the sets can be bound to other portmap ipsets to allow blacklisting (source address, destination port) combinations. For example:

ipset -N SMTP portmap --from 1 --to 31
ipset -A SMTP 25
ipset -A Blacklist 206.124.146.177
ipset -B Blacklist 206.124.146.177 -b SMTP

This will blacklist SMTP traffic from host 206.124.146.177.

Dynamic Blacklisting

Dynamic blacklisting doesn't use any configuration parameters but is rather controlled using /sbin/shorewall[-lite] commands:

  • drop <ip address list> - causes packets from the listed IP addresses to be silently dropped by the firewall.

  • reject <ip address list> - causes packets from the listed IP addresses to be rejected by the firewall.

  • allow <ip address list> - re-enables receipt of packets from hosts previously blacklisted by a drop or reject command.

  • save - save the dynamic blacklisting configuration so that it will be automatically restored the next time that the firewall is restarted.

  • show dynamic - displays the dynamic blacklisting configuration.

If you are running Shorewall 3.2.0 Beta2 or later, there are two additional commands:

  • logdrop <ip address list> - causes packets from the listed IP addresses to be dropped and logged by the firewall. Logging will occur at the level specified by the BLACKLIST_LOGLEVEL setting at the last [re]start (logging will be at the 'info' level if no BLACKLIST_LOGLEVEL was given).

  • logreject <ip address list> - causes packets from the listed IP addresses to be rejected and logged by the firewall. Logging will occur at the level specified by the BLACKLIST_LOGLEVEL setting at the last [re]start (logging will be at the 'info' level if no BLACKLIST_LOGLEVEL was given).

Dynamic blacklisting is not dependent on the “blacklist” option in /etc/shorewall/interfaces.

Example 1. Ignore packets from a pair of systems

    shorewall[-lite] drop 192.0.2.124 192.0.2.125

Drops packets from hosts 192.0.2.124 and 192.0.2.125


Example 2. Re-enable packets from a system

    shorewall[-lite] allow 192.0.2.125

Re-enables traffic from 192.0.2.125.