Back to blog

Protecting an L2 Server From DDoS Attacks and Bots

Contents
  1. Network-level protection
  2. Guard systems for L2
  3. Server-side anti-cheat
  4. Packet flood protection
  5. Monitoring and logging
  6. HWID bans
  7. Security checklist
  8. Conclusion

Server protection is an important part of a Lineage 2 project. DDoS attacks, bots and cheats can destroy a well-built server in days. This article covers a layered defense against common threats.

Network-level protection

The first line of defense is a correctly configured network. Many attacks can be stopped before they reach the game server.

Firewall configuration with iptables

Basic iptables protection is essential for an L2 server:

#!/bin/bash
# Basic firewall rules for the L2 server

# Clear existing rules
iptables -F
iptables -X

# Default policies
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT

# Allow loopback traffic
iptables -A INPUT -i lo -j ACCEPT

# Allow established connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Limit incoming SYN traffic
iptables -A INPUT -p tcp --syn -m limit --limit 1/s --limit-burst 3 -j ACCEPT

# Limit incoming ping traffic
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s -j ACCEPT

# L2 login and game server ports
iptables -A INPUT -p tcp --dport 2106 -j ACCEPT
iptables -A INPUT -p tcp --dport 7777 -j ACCEPT

# SSH (use your configured port)
iptables -A INPUT -p tcp --dport 22 -j ACCEPT

# Allow MySQL connections only from localhost
iptables -A INPUT -p tcp --dport 3306 -s 127.0.0.1 -j ACCEPT

# Limit port scans
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP

# Save the rules
iptables-save > /etc/iptables/rules.v4
Important: Make sure you have an alternative way to access the server before applying firewall rules. Incorrect rules can lock you out.

Fail2ban: automatic attacker blocking

Fail2ban automatically blocks IP addresses showing suspicious activity:

# Installation
apt-get install fail2ban

# L2 configuration
cat > /etc/fail2ban/jail.local << 'EOF'
[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5

[sshd]
enabled = true
port = 22

[l2-login]
enabled = true
port = 2106
filter = l2-login
logpath = /path/to/l2server/log/login.log
maxretry = 3

[l2-game]
enabled = true
port = 7777
filter = l2-game
logpath = /path/to/l2server/log/game.log
maxretry = 5
EOF

# Restart the service
systemctl restart fail2ban

Guard systems for L2

Dedicated Guard systems check client integrity and block cheats at the client-server boundary.

Popular Guard solutions

1. Super-Guard

  • ✅ Protection against most known bots
  • ✅ Client integrity checks
  • ✅ Packet injection protection
  • ✅ Regular updates for new cheats
  • ❌ Paid license

2. Active Anticheat

  • ✅ HWID bans
  • ✅ Protection against L2Walker and Adrenaline
  • ✅ Real-time process monitoring
  • ✅ Technical support

3. Smart Guard

  • ✅ Straightforward integration
  • ✅ Low client overhead
  • ⚠️ Requires client modification
Tip: Combine Guard with server-side checks, log monitoring and GM supervision for layered protection.

Guard integration

A typical Guard integration in L2J:

// Config.properties
# Guard settings
EnableGuard = True
GuardCheckInterval = 30000
GuardKickDelay = 5000
GuardBanOnFail = True

// In the server code
public class GuardManager {
    public void checkPlayer(L2PcInstance player) {
        if (!Config.ENABLE_GUARD) return;
        
        // Send the guard packet
        player.sendPacket(new GuardCheckPacket());
        
        // Wait for a response
        scheduleCheck(player);
    }
    
    private void scheduleCheck(L2PcInstance player) {
        ThreadPoolManager.schedule(() -> {
            if (!player.isGuardVerified()) {
                handleGuardFail(player);
            }
        }, Config.GUARD_KICK_DELAY);
    }
    
    private void handleGuardFail(L2PcInstance player) {
        if (Config.GUARD_BAN_ON_FAIL) {
            BanManager.addBan(player.getClient().getHWID(), 
                "Guard verification failed");
        }
        player.logout(true);
    }
}

Server-side anti-cheat

Guard protects the client, while server-side validation is also essential. Some cheats exploit server behavior without modifying the client.

Movement speed validation

public class MovementValidator {
    private static final int MAX_SPEED = 300;
    private static final int CHECK_INTERVAL = 1000;
    
    public boolean validateMovement(L2PcInstance player, 
                                    Location from, Location to) {
        double distance = from.distance(to);
        long timeDiff = System.currentTimeMillis() - 
                       player.getLastMoveTime();
        
        if (timeDiff < 100) return false; // Packets arrived too close together
        
        double speed = (distance / timeDiff) * 1000;
        int maxSpeed = player.getRunSpeed() + 50; // Speed tolerance
        
        if (speed > maxSpeed) {
            player.addWarning("Speed hack suspected: " + speed);
            
            if (player.getWarnings() > 3) {
                player.setIsParalyzed(true);
                announceToGMs(player, "Speed hack detected!");
                return false;
            }
        }
        
        player.setLastMoveTime(System.currentTimeMillis());
        return true;
    }
}

Action validation

public class ActionValidator {
    // Check the casting time
    public boolean validateCastTime(L2PcInstance player, 
                                    L2Skill skill) {
        long expectedCastTime = skill.getHitTime();
        long actualCastTime = System.currentTimeMillis() - 
                             player.getCastStartTime();
        
        // Allow a 500 ms tolerance
        if (actualCastTime < (expectedCastTime - 500)) {
            player.addWarning("Fast cast detected");
            return false;
        }
        return true;
    }
    
    // Check the number of actions per second
    public boolean checkActionFlood(L2PcInstance player) {
        int actionsPerSecond = player.getActionsInLastSecond();
        
        if (actionsPerSecond > 10) {
            player.sendMessage("You're acting too fast!");
            return false;
        }
        return true;
    }
    
    // Check the attack range
    public boolean validateAttackRange(L2PcInstance player, 
                                       L2Character target) {
        int maxRange = player.getPhysicalAttackRange() + 50;
        double distance = player.distance(target);
        
        if (distance > maxRange) {
            player.addWarning("Attack range exceeded");
            return false;
        }
        return true;
    }
}

Packet flood protection

Packet flooding can take a server down quickly. Apply suitable limits:

public class PacketFloodProtector {
    private static final int MAX_PACKETS_PER_SECOND = 100;
    private final Map<String, PacketCounter> counters =
        new ConcurrentHashMap<>();
    
    public boolean checkFlood(L2GameClient client, 
                              L2GameClientPacket packet) {
        String key = client.getAccountName();
        PacketCounter counter = counters.computeIfAbsent(key, 
            k -> new PacketCounter());
        
        counter.increment();
        
        if (counter.getCount() > MAX_PACKETS_PER_SECOND) {
            LOG.warning("Packet flood from: " + key);
            
            // Hard limit
            if (counter.getCount() > MAX_PACKETS_PER_SECOND * 2) {
                client.close(new LeaveWorld());
                BanManager.addBan(client.getHWID(), 
                    "Packet flood attack");
                return false;
            }
            
            // Soft limit: drop the packet
            return false;
        }
        
        return true;
    }
    
    // Reset the counters every second
    public void resetCounters() {
        counters.values().forEach(PacketCounter::reset);
    }
}

Monitoring and logging

Configure monitoring to make suspicious activity visible:

What to log

# security.log format
[2026-01-15 14:23:15] [WARN] Player "Cheater123" speed hack detected (speed: 450)
[2026-01-15 14:23:16] [BAN] Player "Cheater123" auto-banned (reason: Speed hack)
[2026-01-15 14:25:00] [ALERT] DDoS suspected: 1000 connections from 45.67.89.0/24
[2026-01-15 14:30:12] [INFO] Guard check failed: Player "Bot001" (HWID: xxx)

Automatic alerts

public class SecurityMonitor {
    private static final int ALERT_THRESHOLD = 10;
    
    public void checkForThreats() {
        // Check for suspicious activity
        int suspiciousPlayers = getSuspiciousPlayersCount();
        
        if (suspiciousPlayers > ALERT_THRESHOLD) {
            alertAdmins("High suspicious activity detected: " + 
                       suspiciousPlayers + " players");
            
            // Send a Telegram or Discord notification
            sendWebhook("⚠️ Security Alert", 
                       "Suspicious activity spike detected!");
        }
    }
    
    private void sendWebhook(String title, String message) {
        // Discord Webhook
        String url = Config.DISCORD_WEBHOOK_URL;
        JSONObject json = new JSONObject()
            .put("content", "**" + title + "**\n" + message);
        
        // Send using an HTTP client
        HttpUtils.post(url, json.toString());
    }
}

HWID bans

IP bans are easy to evade. HWID (Hardware ID) bans offer another layer of enforcement:

public class HWIDBanManager {
    public void banPlayer(L2PcInstance player, String reason) {
        String hwid = player.getClient().getHWID();
        
        if (hwid != null && !hwid.isEmpty()) {
            // Record the ban in the database
            Connection con = L2Database.getConnection();
            PreparedStatement ps = con.prepareStatement(
                "INSERT INTO hwid_bans (hwid, reason, date) VALUES (?, ?, NOW())");
            ps.setString(1, hwid);
            ps.setString(2, reason);
            ps.execute();
            
            // Disconnect all sessions with this hardware ID
            for (L2PcInstance p : L2World.getAllPlayers()) {
                if (hwid.equals(p.getClient().getHWID())) {
                    p.logout(true);
                }
            }
            
            LOG.info("HWID banned: " + hwid + " (reason: " + reason + ")");
        }
    }
    
    public boolean isHWIDBanned(String hwid) {
        // Check at login
        try (Connection con = L2Database.getConnection()) {
            PreparedStatement ps = con.prepareStatement(
                "SELECT 1 FROM hwid_bans WHERE hwid = ?");
            ps.setString(1, hwid);
            ResultSet rs = ps.executeQuery();
            return rs.next();
        }
    }
}
Warning: Experienced cheaters can spoof HWIDs. Combine this method with other protections.

Security checklist

Check before launch:

  • ✅ Firewall configured and active
  • ✅ Fail2ban installed and running
  • ✅ Guard system integrated
  • ✅ Server-side anti-cheat enabled
  • ✅ Packet flood protection enabled
  • ✅ HWID ban system working
  • ✅ Security logging configured
  • ✅ Telegram/Discord alerts working
  • ✅ SSH uses a non-default port
  • ✅ MySQL accessible only from localhost
  • ✅ Regular database backups
  • ✅ Hosting-level DDoS protection

Conclusion

L2 server protection requires ongoing work. New cheats and attack methods appear regularly. Keep Guard systems updated, analyze logs and respond promptly to suspicious activity.

Three protection layers:

  1. Network — firewall, fail2ban, DDoS protection
  2. Client — Guard system and integrity checks
  3. Server — anti-cheat, action validation and monitoring

A combined approach provides a stronger defense for your project.

Need help protecting your server? We integrate Guard systems and configure server protection. Contact us for a consultation.