scripts lineage2  :::  Server Packs lineage 2 — best scripts for admin servers   :::  Projects lineage Turnkey
l2-scripts.com  Freelance Studio

ArticlesTechnical guides8 min read

Linux for game server admins: MySQL, time sync and flood protection

Practical notes for anyone running a Lineage 2 server on Ubuntu or Debian: managing MariaDB/MySQL, safe remote access to the database, accurate time and basic protection against floods and overload.

Managing MariaDB and MySQL

Modern Ubuntu and Debian manage services with systemd, so use systemctl instead of the old /etc/init.d/mysql scripts. The MariaDB service is called mariadb (on Debian and Ubuntu the mysql alias works too); the MySQL service is called mysql.

sudo systemctl status mariadb     # service state and the latest log lines
sudo systemctl restart mariadb    # restart after editing the config
sudo systemctl stop mariadb       # stop
sudo systemctl start mariadb      # start
sudo systemctl enable mariadb     # start automatically at boot

If the database will not start, the reason is almost always in the log:

sudo journalctl -u mariadb -n 100 --no-pager   # last 100 lines
sudo journalctl -u mariadb -f                  # follow in real time
sudo tail -n 100 /var/log/mysql/error.log      # if a separate error log is configured

Common reasons for a crash:

  • the disk is full: check with df -h;
  • a mistake in the config after editing: journalctl shows the offending line;
  • port 3306 is taken by another process: sudo ss -ltnp | grep 3306;
  • tables damaged after a power loss or crash: see the guide on rescuing a MySQL database.

The main config files are /etc/mysql/mariadb.conf.d/50-server.cnf for MariaDB and /etc/mysql/mysql.conf.d/mysqld.cnf for MySQL. Server options go into the [mysqld] section. Installing a web server and database from scratch is covered in the guide on installing Apache, MySQL and PHP on Ubuntu.

Remote database access from Navicat or HeidiSQL

Working with the database from your home PC is convenient, but opening port 3306 to the whole internet and letting root log in from any address (as older guides often suggested) is dangerous: bots constantly try to guess passwords on exposed databases. There are two proper ways to do it.

Option 1. SSH tunnel (recommended). The database keeps listening on 127.0.0.1 only, and the client connects to it over SSH. In HeidiSQL choose a connection type with an SSH tunnel; in Navicat fill in the SSH tab of the connection settings. From the command line the tunnel looks like this:

ssh -L 3307:127.0.0.1:3306 user@server_ip
# while the session is open, point your client to 127.0.0.1, port 3307

Option 2. Open the port for your IP only. Use a separate user with rights to the server database only, not root:

  1. In the [mysqld] section of the MariaDB/MySQL config, change bind-address = 127.0.0.1 to bind-address = 0.0.0.0 and restart the service.
  2. Open the database console (sudo mariadb or sudo mysql) and create a user bound to your public IP.
  3. Allow port 3306 in the firewall from that IP only.
CREATE USER 'l2admin'@'203.0.113.10' IDENTIFIED BY 'strong_password';
GRANT ALL PRIVILEGES ON l2jdb.* TO 'l2admin'@'203.0.113.10';
sudo ufw allow from 203.0.113.10 to any port 3306 proto tcp

Here 203.0.113.10 is your public IP and l2jdb is the server database name.

Do not edit the mysql.user table directlyQueries like UPDATE mysql.user SET host = '%' ... from old guides are not supported in MySQL 8 and MariaDB 10.4+ and can break user accounts. Create and change users with CREATE USER, GRANT and ALTER USER. The game server itself does not need the database port to be open to the outside: it connects via localhost.

Time and time zone

The Olympiad, sieges, raid boss respawns, daily resets and events all depend on the system time. If your server is rented in another country, its clock follows that country's time zone. The right approach is not to set the clock by hand, but to choose the correct time zone and enable automatic time synchronization.

timedatectl                                   # time, zone and sync status
timedatectl list-timezones | grep Europe      # list available zones
sudo timedatectl set-timezone Europe/Berlin   # set the zone
sudo timedatectl set-ntp true                 # enable sync (systemd-timesyncd)
timedatectl timesync-status                   # sync details

Instead of the built-in systemd-timesyncd you can install chrony: it keeps time more precisely and corrects drift faster. Installing chrony usually removes or disables systemd-timesyncd automatically; never run two time sync services at once.

sudo apt install chrony
chronyc tracking      # current offset and time source
chronyc sources -v    # list of time servers
After changing the time zoneRestart the game server and MariaDB/MySQL: Java and the database server read the time zone at startup. You can check the database time with SELECT NOW(), @@system_time_zone;. If the game time must differ from the system time, pass a zone to the Java server with the -Duser.timezone=Europe/Berlin startup option.

Treat the old methods, date -s 23:45:30 and ntpdate, as legacy. With time sync enabled, a manually set clock is corrected back, and newer distributions have replaced ntpdate with time sync services.

Who is connected: ss instead of netstat

The netstat tool from the net-tools package is outdated and not always installed; its replacement is ss. Default pack ports are 2106 for the login server, 7777 for the game server and 3306 for the database (your pack may use different ports).

sudo ss -ltnp                                          # listening ports and their processes
ss -tn state established '( sport = :7777 )'           # active connections to the game server
ss -Htn state established '( sport = :7777 )' | wc -l  # how many of them

In the output, Recv-Q and Send-Q are the data waiting in the receive and send queues (usually close to zero), Local Address:Port is your address and port, and Peer Address:Port is the client's address and port. To find addresses with a suspicious number of connections, group them by IP:

ss -Htn state established '( sport = :7777 )' \
  | awk '{sub(/:[0-9]+$/, "", $4); print $4}' \
  | sort | uniq -c | sort -rn | head -20

Dozens of connections from one address to the login or game server port deserve a closer look: a normal client keeps one connection per game window. Keep in mind, though, that several players may share one IP (a shared network or mobile internet).

To check the load on the machine itself:

htop        # processes, CPU and memory usage (sudo apt install htop)
uptime      # load average over 1, 5 and 15 minutes
nproc       # number of CPU cores
free -h     # memory and swap
df -h       # free disk space

If the load average stays above the number of cores for a long time, the server is short on CPU. If the Java process is actively swapping, the game will lag: add memory or reduce the heap size.

Firewall and basic DoS protection

The simplest and most useful step is to close everything except the ports you need. Ubuntu ships ufw for this (on Debian install it with sudo apt install ufw); it works on top of the kernel firewall (nftables or iptables).

sudo ufw allow 22/tcp           # SSH - always before enabling!
sudo ufw allow 2106/tcp         # login server
sudo ufw allow 7777/tcp         # game server
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw enable
sudo ufw status numbered
Do not lock yourself outAllow the SSH port before running ufw enable; if SSH runs on a non-standard port, allow that port instead. If a website runs on the same machine, open ports 80 and 443 as well.

To block a specific address, insert the rule at the top of the list: ufw checks rules in order, and a deny rule added after a port has been allowed will not take effect.

sudo ufw insert 1 deny from 198.51.100.50   # block an address
sudo ufw status numbered                    # check the rule order
sudo ufw delete 1                           # remove a rule by its number

To limit the number of simultaneous connections from one IP to the game ports (no more than 10 here):

sudo iptables -I INPUT -p tcp --syn -m multiport --dports 2106,7777 \
  -m connlimit --connlimit-above 10 --connlimit-mask 32 -j REJECT --reject-with tcp-reset

This rule lasts until the next reboot. To keep it together with ufw, add the line below to /etc/ufw/before.rules just before the COMMIT line and run sudo ufw reload. Leave some headroom in the limit: players with several game windows or behind a shared IP open several connections.

-A ufw-before-input -p tcp --syn -m multiport --dports 2106,7777 -m connlimit --connlimit-above 10 --connlimit-mask 32 -j REJECT --reject-with tcp-reset

A few more hygiene rules:

  • do not expose the database port or the pack's internal ports (such as the login-to-game server link port, usually 9014): 127.0.0.1 is enough for them;
  • log in over SSH with a key and disable password login; fail2ban or sudo ufw limit 22/tcp helps against SSH password guessing;
  • do not run the game server as root: create a separate user for it;
  • update the system regularly with sudo apt update and sudo apt upgrade;
  • back up the database on a regular schedule.
Manual protection has its limitsBlocking addresses by hand helps against a simple flood from a few IPs, but it requires an admin to be around all the time. A large DDoS attack that saturates the whole channel cannot be stopped by a firewall on the server itself: you need traffic filtering on the hosting side (DDoS-protected servers).

If you would rather not deal with all this yourself, take a look at our turnkey projects and server packs.

Published 6 November 2026

Read also

Need help with your server?

We help with the server pack, setup, protection and launch — one-off or on an ongoing basis.

L2‑Scripts newsletter

Get L2‑Scripts news by email

And 5% off all studio services while you stay subscribed.

The discount is valid while you are subscribed: when ordering, tell the manager your subscription address on Telegram.