Tutorial on setting up a Factorio online game server
در این آموزش به نحوه راه اندازی سرور بازی Factorio پرداخته شده و نکات فنی و اجرایی برای بهترین عملکرد ارائه می‌شود.

Tutorial on setting up a Factorio online game server

This article is a comprehensive guide to setting up a Factorio online game server. It will help you create a stable and secure server for your multiplayer gaming experience with both technical and operational steps. From choosing a location, installing the required software, to security settings and backups, this article covers everything.
0 Shares
0
0
0
0

Why should I set up a Factorio server on a Linux server?

This guide provides a step-by-step and technical guide on how to set up an online game server. Factorio on a Linux server (VPS or dedicated server) is explained. This article is for Server admins, gamers, and game development teams Designed to create a stable, low-latency, and secure server for multiplayer games.

Why VPS or dedicated server for Factorio?

Factorio is not suitable for servers with a lot of players or heavy mods. Powerful single-core CPU, requires sufficient memory and fast I/O. The choice between VPS and dedicated server varies depending on the size of the players and budget:

  • Small group (up to 8 players): A VPS with a fast CPU, 2 vCPUs, and 4–8GB of RAM is sufficient.
  • Medium group (8–32 players): 4 vCPUs, 8–16GB RAM, NVMe recommended.
  • Large server (>32 players or heavy mods): A dedicated server with 6–12 high-clocked cores, 32GB+ RAM, and NVMe is suitable.

For the lowest ping, the right location (out of 85+ global locations) is important: Europe (Frankfurt, Amsterdam), US East (New Jersey), US West (California), Asia (Singapore, Tokyo), Australia (Sydney), and Brazil (São Paulo).

Factorio Headless Prerequisites and Download

Prerequisites for Linux server:

  • Linux distribution: Ubuntu 20.04/22.04 or Debian 11+ Recommended.
  • A non-root user to run the server.
  • SSH access and the ability to install packages.

Example of basic commands (Ubuntu):

sudo apt update && sudo apt upgrade -y
sudo apt install -y wget unzip tar libstdc++6
sudo adduser --disabled-login --gecos "Factorio Server" factorio
sudo usermod -aG sudo factorio

Download headless version:

  1. Download the headless version from the official Factorio site (check the relevant version).
  2. Example (replace URL with official link):
sudo -u factorio mkdir -p /opt/factorio
cd /opt/factorio
sudo -u factorio wget https://www.factorio.com/get-download/latest/headless/linux64 -O factorio_headless.tar.xz
sudo -u factorio tar -xf factorio_headless.tar.xz

Initial setup and server running

Running the server with a new save or loading an existing save:

Starting the server with a new save:

sudo -u factorio /opt/factorio/bin/x64/factorio --start-server /opt/factorio/saves/my-save.zip --server-settings /opt/factorio/config/server-settings.json --port 34197

Load an existing save (load latest):

sudo -u factorio /opt/factorio/bin/x64/factorio --start-server-load-latest

Ports:

  • Game port: UDP 34197 (default)
  • RCON: If enabled, you can specify a custom TCP port (e.g. 27015). Settings in the file server-settings.json It is placed.

Create a systemd service to start automatically

Create a service file to automatically start and manage the server:

sudo tee /etc/systemd/system/factorio.service > /dev/null <<'EOF'
[Unit]
Description=Factorio Headless Server
After=network.target

[Service]
User=factorio
Group=factorio
Type=simple
WorkingDirectory=/opt/factorio
ExecStart=/opt/factorio/bin/x64/factorio --start-server /opt/factorio/saves/my-save.zip --server-settings /opt/factorio/config/server-settings.json --port 34197
Restart=on-failure
RestartSec=10
LimitNOFILE=4096

[Install]
WantedBy=multi-user.target
EOF

Activating and running the service:

sudo systemctl daemon-reload
sudo systemctl enable --now factorio.service
sudo journalctl -u factorio -f

Config file server-settings.json (Important points)

On the way /opt/factorio/config/server-settings.json Check or edit the following settings:

  • name: Server name
  • description: Explanation for players
  • max_players: Maximum players
  • game_password: Optional for login (recommended for private servers)
  • require_user_verification: true for Steam authentication (if needed)

Simple example:

{
  "name": "My Factorio Server",
  "description": "سرور رسمی جامعه",
  "max_players": 32,
  "game_password": "securepassword",
  "require_user_verification": true
}

Running Factorio in Docker (alternative method)

If you prefer to use Docker, the following example provides a quick and isolated way to run:

docker run -d --name=factorio \
  -p 34197:34197/udp \
  -p 27015:27015/tcp \
  -v /host/factorio/saves:/factorio/saves \
  -v /host/factorio/config:/factorio/config \
  --restart unless-stopped \
  --user 1000:1000 \
  factoriotools/factorio:latest

Advantages: Isolation, ease of updating and backup.

Security and firewall

Basic security recommendations for game servers:

1. Restrict SSH access:

sudo sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
sudo sed -i 's/PasswordAuthentication yes/PasswordAuthentication no/' /etc/ssh/sshd_config
sudo systemctl reload sshd

2. UFW example to open only necessary ports:

sudo apt install ufw -y
sudo ufw default deny incoming
sudo ufw default allow outgoing
# اجازه SSH (اگر پورت 22 یا پورت دلخواه)
sudo ufw allow 22/tcp
# اجازه پورت بازی (UDP)
sudo ufw allow 34197/udp
# اگر RCON فعال است:
sudo ufw allow 27015/tcp
sudo ufw enable

3. Install Fail2Ban to protect SSH:

sudo apt install fail2ban -y

Automatic backup and retention of saves

Example of a simple backup script that can be run with cron or systemd timer:

#!/bin/bash
SAVE_DIR=/opt/factorio/saves
BACKUP_DIR=/var/backups/factorio
mkdir -p $BACKUP_DIR
TIMESTAMP=$(date +%F_%T)
cp $SAVE_DIR/*.zip $BACKUP_DIR/factorio_save_$TIMESTAMP.zip
# نگهداری آخرین 7 بکاپ
ls -1t $BACKUP_DIR | tail -n +8 | xargs -I{} rm -f $BACKUP_DIR/{}

Add to crontab to run hourly:

0 * * * * /usr/local/bin/factorio_backup.sh

Recommendation: Sync backups to Object Storage (S3 or compatible) or another server to preserve data in case of a problem.

Optimized for low ping and better performance

  • Choose a location: Choose the closest geographical location to the players or a location in the center of the player population.
  • High-clocked CPU: Factorio emulation is highly dependent on single cores; choosing a server with a high single core frequency (3.5GHz+) is preferable.
  • Memory and disk: SSD/NVMe is required for fast I/O when saving and loading the world.
  • Network and QoS: Ensure sufficient bandwidth (especially upload) and use low-latency networking and BGP if needed.

Monitoring and logs

To view logs and check server status:

sudo journalctl -u factorio -f
# یا اگر لاگ در فایل است:
tail -f /opt/factorio/factorio-current.log

Suggested tools: Netdata, Prometheus + Grafana Or simpler tools like htop and nload To view resource usage.

Tips for mods and updates

  • Test Modes: Try mods in a test environment before installing them on the main server; mods can cause crashes or slowdowns.
  • Version compatibility: The client and server versions must match.
  • Update method: When updating the server, be sure to back up the save, stop the service, perform the update, and then restart the server.

Practical examples and troubleshooting of common problems

Problem: Players can't connect

  • Check firewall and ports: ufw status, Check for open ports with ss.
  • Check that the server is listening on UDP port 34197:
  • sudo ss -unlp | grep 34197
  • Check logs for errors or related messages.

Problem: Server lag with increasing number of players

  • Check CPU frequency, single-core load, RAM usage, and I/O.
  • If needed, upgrade to a more powerful core instance or distribute players across multiple servers.

Use company services for the best experience

If you have access to services such as 85+ global locations, VPS for gaming, Anti-DDoS server and Cloud server with NVMe You can significantly improve the gaming experience.

Applicable cases:

  • Choose a location close to players to reduce ping.
  • Examples with high-clocked processors and NVMe for better performance.
  • Use an anti-DDoS server to protect against UDP attacks.
  • Network and BGP if you need advanced routing or Anycast.
  • CDN for static content (mods, images) — Note that CDN is not applicable for UDP real-time gaming.

Conclusion and final suggestions

Setting up a Factorio server requires attention to hardware selection (strong single-core CPU, NVMe), appropriate location, security settings, and regular backups.

Summary of suggestions for a quick start:

  1. Choose a VPS with a strong CPU and NVMe.
  2. Install the headless version and configure the systemd service according to the instructions.
  3. Automate firewalls and backups.
  4. Choose server locations based on players and use anti-DDoS services if necessary.

For information about plans and advice, you can visit the support section.

Frequently Asked Questions

You May Also Like