Ratelimit

Introduction

AP introduces the ability to rate limit TCP and UDP ports. AP allows you to define the rate at which connections may occur to ports, as well as the maximum number of connections that can be open for a given period of time to a TCP port. This can be used to help with SYN and UDP floods.

For TCP you can define:

  • Per port, rate of connections from a single IP.

  • Maximum concurrent connections to the port (for all IPs).

For UDP you can define:

  • Per port, rate of connections from a single IP.

Note

Connections from localhost are automatically excluded from all rate limiting.


Configuration

First you will need to configure the ports to protect, the rate per port, and the maximum number of concurrent connections for each protected TCP port. The engine uses two files, one for TCP ports, one for UDP ports. The files are:

  • /etc/awp/firewall/rate-limit-tcp

  • /etc/awp/firewall/rate-limit-udp

You will need to create these files. We recommend you set the permissions so that only the root user can access these files:

  • chown root.root /etc/awp/firewall/rate-limit*

  • chmod og-rwx /etc/awp/firewall/rate-limit*


TCP

The format for the /etc/awp/firewall/rate-limit-tcp file is one file, per port:

The fields are:

  • port: The port you want to limit connections to do, for example 80.

  • rate: The maximum number of connections to allow from a single IP, within a specific period of time (defined in time_period and time_window)

  • time_period: The time period to use. The following periods are support: seconds, minutes or hours. For example, “seconds”.

  • time_window: The amount of time for the period, for example 1.

  • max_concurrent_connections: The total number of SYN connections allowed from all IPs.

Example:

80:10:seconds:2:100
443:5:seconds:5:10

In this example, the first line means:

  • Port 80 is rate limited.

  • To 10 new connections, per every 2 seconds, from the same IP.

  • WIth no more thatn 100 SYN packets allowed in from all IPs.

And the second line means:

  • Port 443 is rate limited.

  • To 5 new connections, per every 5 seconds, from the same IP.

  • With no more than 10 SYN packets allowed in from all IPs.


UDP

The format for the /etc/awp/firewall/rate-limit-udp file is one line, per port.

The fields are:

  • port: The port you want to limit connections to do, for example 80.

  • burst_limit: The number of connections at which the limit is applied, any connections above this limit will be limited per the time_period/time_window settings below.

  • time_period: The time period to use. The following are supported: second, minute, or hour. For example, “second”

  • time_window: The amount of time for the period, for example 1.

Example:

53:100:second:10
2049:100:minute:1

Note

UDP is connectionless, so there are no concurrent connections.

In this example, the first line means:

  • Port 53 is rate limited.

  • Once 100 connections occur, limit connections to 10 per second.

And the second line means:

  • Port 2049 is rate limited.

  • Once 100 connections occur, limit connections to 1 per second.


Enabling

Once you have rate limiting configured, you will ned to enable it.

To enable this option, please see FW_RATE_LIMIT.

Note

Be sure to follow the instructions in this document to configure rate limiting for your system.