Skip to content

DDoS Protection

Distributed Denial of Service (DDoS) attacks represent one of the most significant threats to network availability. These malicious attempts to disrupt normal traffic overwhelm target systems with excessive requests, rendering services inaccessible to legitimate users. MikroTik RouterOS provides robust firewall capabilities to detect, mitigate, and block various types of DDoS attacks, ensuring network resilience and continued service availability.

A denial-of-service (DoS) or distributed denial-of-service (DDoS) attack is a malicious attempt to disrupt normal traffic of a targeted server, service, or network by overwhelming the target or its surrounding infrastructure with a flood of Internet traffic. DDoS attacks achieve effectiveness by using multiple compromised computer systems as sources of attack traffic, making mitigation more challenging than simple DoS attacks.

Understanding the various attack vectors is essential for implementing appropriate protections:

Attack TypeDescriptionTarget Layer
SYN FloodExploits TCP handshake by sending SYN packets without completing connectionTransport (Layer 4)
SYN-ACK FloodSends spoofed SYN-ACK packets at high rate, overwhelming target resourcesTransport (Layer 4)
HTTP FloodOverwhelms web servers with seemingly legitimate HTTP requestsApplication (Layer 7)
DNS AmplificationExploits DNS servers to amplify attack traffic toward victimApplication (Layer 7)
UDP FloodSends UDP packets to random ports, consuming bandwidth and resourcesTransport (Layer 4)
ICMP FloodOverwhelms target with ICMP Echo Request packetsNetwork (Layer 3)

Effective DDoS protection in RouterOS employs multiple complementary techniques:

  • Traffic Rate Limiting: Using dst-limit to restrict connection rates per source-destination pair
  • Address List Management: Automatically tracking and blocking identified attackers
  • Connection Tracking Integration: Leveraging connection state for intelligent filtering
  • RAW Prerouting: Dropping malicious traffic before it consumes connection tracking resources

The primary DDoS protection strategy in RouterOS involves detecting anomalous traffic patterns and automatically blocking the sources. This approach uses a dedicated firewall chain with rate limiting to identify attackers, then creates address lists for automatic blocking.

Before implementing detection rules, define address list names to track attackers and targets. The lists are created automatically when the first entry is added (by add-src-to-address-list and add-dst-to-address-list actions in the detection rules below):

  • DDoS-attackers — identified attack sources
  • DDoS-targets — servers being targeted

These address lists serve as dynamic databases of identified malicious sources and their targets, enabling targeted traffic dropping at the RAW prerouting chain.

Create a dedicated firewall chain to detect and handle DDoS traffic:

/ip firewall filter
add chain=forward connection-state=new action=jump jump-target=detect-DDoS

This rule redirects all new forward connections to the detection chain for analysis.

The dst-limit parameter is the cornerstone of DDoS detection. It matches packets based on rate thresholds:

/ip firewall filter
add chain=detect-DDoS action=return dst-limit=32,32,src-and-dst-addresses/10s

The dst-limit parameter follows this format: count/time,burst,mode[/expire]

ParameterDescriptionExample Value
countMaximum packets to allow per time window32
timeTime window duration10s
burstAllowable burst beyond rate limit32
modeMatching mode: src-address, dst-address, src-and-dst-addresses, etc.src-and-dst-addresses
expireTime to track rate per flow(optional)

The example rule matches 32 packets with 32 packet burst based on source and destination address flow, renewing every 10 seconds. When legitimate traffic stays within these limits, the action=return allows it to proceed normally.

When the dst-limit buffer fills during an attack, subsequent rules identify and track attackers:

/ip firewall filter
add chain=detect-DDoS action=add-dst-to-address-list address-list=DDoS-targets address-list-timeout=10m
add chain=detect-DDoS action=add-src-to-address-list address-list=DDoS-attackers address-list-timeout=10m

These rules add detected attack targets and sources to their respective address lists with a 10-minute timeout, enabling automatic cleanup of entries after the attack subsides.

Drop traffic between identified attackers and targets at the RAW prerouting chain:

/ip firewall raw
add chain=prerouting action=drop dst-address-list=DDoS-targets src-address-list=DDoS-attackers

Using RAW prerouting for dropping provides optimal performance since these connections bypass connection tracking, reducing router CPU load during active attacks.

/ip firewall filter
add chain=forward connection-state=new action=jump jump-target=detect-DDoS
add chain=detect-DDoS action=return dst-limit=32,32,src-and-dst-addresses/10s
add chain=detect-DDoS action=add-dst-to-address-list address-list=DDoS-targets address-list-timeout=10m
add chain=detect-DDoS action=add-src-to-address-list address-list=DDoS-attackers address-list-timeout=10m
/ip firewall raw
add chain=prerouting action=drop dst-address-list=DDoS-targets src-address-list=DDoS-attackers

SYN floods exploit the TCP three-way handshake mechanism by sending SYN packets without completing the connection request. This consumes server resources as half-open connections accumulate, eventually preventing legitimate connections.

RouterOS includes a built-in mechanism to mitigate SYN floods at the TCP level:

/ip settings set tcp-syncookies=yes

When SYN cookies are enabled, the router responds to SYN requests with a special ACK packet containing a cryptographic hash. Legitimate clients echo this hash back in their subsequent response, proving the connection was originally initiated correctly. Invalid or spoofed responses are discarded without creating half-open connections.

BenefitDescription
Resource ConservationPrevents creation of half-open connections during SYN flood
Transparent OperationClients require no special configuration
Cryptographic ValidationEnsures responses correspond to actual connection requests
/ip settings print

Verify SYN cookie status after enabling. The feature works at the IP settings level and affects all TCP connections passing through the router.

For SYN-specific attacks that bypass SYN cookies, combine with the general DDoS detection rules:

/ip firewall filter
add chain=detect-DDoS action=return dst-limit=32,32,src-and-dst-addresses/10s protocol=tcp tcp-flags=syn

This rule specifically rate-limits SYN packets within the detection chain, providing an additional layer of protection against high-volume SYN floods.

SYN-ACK floods exploit the TCP handshake in reverse by sending spoofed SYN-ACK packets. The target must process these out-of-order packets, consuming CPU resources as it attempts to match them to non-existent connection requests.

Add SYN-ACK specific rate limiting to your detection chain:

/ip firewall filter
add chain=detect-DDoS action=return dst-limit=32,32,src-and-dst-addresses/10s protocol=tcp tcp-flags=syn,ack

This rule specifically targets SYN-ACK packets, rate limiting them independently from other traffic types.

For comprehensive protection against multiple attack vectors:

/ip firewall filter
add chain=detect-DDoS action=return dst-limit=32,32,src-and-dst-addresses/10s
add chain=detect-DDoS action=return dst-limit=32,32,src-and-dst-addresses/10s protocol=tcp tcp-flags=syn
add chain=detect-DDoS action=return dst-limit=32,32,src-and-dst-addresses/10s protocol=tcp tcp-flags=syn,ack

Default thresholds may require adjustment based on your network characteristics:

/ip firewall filter
add chain=detect-DDoS action=return dst-limit=64,64,src-and-dst-addresses/10s
Network TypeRecommended CountRecommended Burst
Small Office ( < 50 users)16-3216-32
Medium Business (50-200 users)32-6432-64
Large Enterprise (200+ users)64-12864-128
Public Services (web, DNS)128-256128-256

Higher thresholds reduce false positives during legitimate traffic spikes but may allow more attack traffic through before triggering protection.

Adjust timeout values based on attack patterns:

/ip firewall filter
add chain=detect-DDoS action=add-src-to-address-list address-list=DDoS-attackers address-list-timeout=30m

Longer timeouts prevent quick re-entry by attackers but may block legitimate users whose IP addresses were dynamically reassigned to new users.

For complex networks, consider segmenting detection:

/ip firewall filter
add chain=forward connection-state=new src-address=192.168.0.0/16 action=jump jump-target=detect-DDoS-internal
add chain=forward connection-state=new action=jump jump-target=detect-DDoS-external

Apply different thresholds and actions based on traffic source.

Monitor identified attackers and targets:

/ip firewall address-list print where list=DDoS-attackers
/ip firewall address-list print where list=DDoS-targets

Enable logging for attack detection:

/ip firewall filter
add chain=detect-DDoS action=log log-prefix="DDoS-detected"

Execute scripts when attacks are detected:

/system script add name=block-ddos source={
:log info "DDoS attack detected - checking attack intensity"
}
/ip firewall filter
add chain=detect-DDoS action=run-script script-name=block-ddos

Monitor router resource usage during potential attacks:

/tool/netwatch add host=127.0.0.1 type=icmp interval=30s down-script=alert-high-cpu
  1. Increase dst-limit thresholds for peak traffic periods
  2. Add whitelist address lists for known good sources
  3. Reduce address list timeout values
  4. Review attack detection timing and patterns
/ip firewall raw
add chain=prerouting action=accept src-address-list=trusted dst-address-list=DDoS-targets
  1. Verify jump rule redirects traffic to detect-DDoS chain
  2. Check dst-limit syntax for correct formatting
  3. Confirm address lists exist and are properly named
  4. Review RAW prerouting rule for correct address list references
/ip firewall filter print chain=detect-DDoS
/ip firewall address-list print
/ip firewall raw print
  1. Ensure RAW prerouting drop rules are in place before connection tracking
  2. Increase dst-limit thresholds to trigger blocking sooner
  3. Consider hardware-level filtering for sustained attacks
  4. Implement upstream null routing as last resort
/ip firewall raw print
  1. Verify address list entries are being created
  2. Check RAW rules are processing before filter rules
  3. Confirm attacker IP ranges aren’t being NAT’d
  4. Consider external mitigation services for volumetric attacks

Implement multiple protection layers:

  1. Network Perimeter: ISP-level filtering and null routes
  2. Router Firewall: RouterOS RAW and filter rules
  3. Connection Tracking: SYN cookies and connection limits
  4. Application Layer: Web application firewalls for HTTP attacks
  • Audit address lists daily during attack-prone periods
  • Analyze blocked traffic patterns weekly
  • Adjust thresholds based on traffic baselines
  • Test configurations in lab environment first
  • Document normal traffic patterns and baselines
  • Record threshold values and rationale
  • Maintain runbooks for attack response
  • Track attack trends over time
  • /ip firewall address-list - Manage address lists
  • /ip firewall filter - Configure firewall filter rules
  • /ip firewall raw - Configure RAW prerouting rules
  • /ip settings - Configure TCP/IP settings including SYN cookies
  • /tool/netwatch - Monitor router resources
  • /system/logging - Configure logging for attack detection