Setting Up Your Factorio Server on Clear Linux: A Comprehensive Guide

Setting up a dedicated server for Factorio can significantly enhance your multiplayer experience, allowing you and your friends to play together seamlessly, regardless of who is hosting. This guide will walk you through the process of setting up a Factorio server on Clear Linux, leveraging its performance and efficiency. While the original setup might seem daunting, we’ll break it down into manageable steps, ensuring even those with basic Linux knowledge can get their server up and running. This guide expands on the basic setup, providing a more robust and SEO-optimized approach for English-speaking users interested in running their own Factorio servers.

Why Choose Clear Linux for Your Factorio Server?

Clear Linux is known for its speed and security, making it an excellent choice for hosting game servers. Its optimized kernel and streamlined package management system contribute to improved performance, which is crucial for a resource-intensive game like Factorio, especially with larger factories and more players. Furthermore, Clear Linux’s focus on security helps protect your server from potential vulnerabilities.

Prerequisites

Before we begin, ensure you have the following:

  • Hardware: A dedicated machine to run the server. While the original author used spare parts (Intel G4560, 8GB RAM, 120GB SSD), Factorio server requirements will vary based on player count and factory complexity. More players and larger factories will demand more resources.
  • Clear Linux Server Installed: You’ll need Clear Linux Server installed on your dedicated machine. Follow the official Clear Linux installation guide.
  • Factorio Account: A Factorio account is required to download the headless server software.
  • Basic Linux Knowledge: Familiarity with basic Linux commands will be helpful.
  • Network Setup: Router access to forward ports for server accessibility.

Step-by-Step Guide to Setting Up Your Factorio Server

1. Initial Server Setup and User Creation

During the Clear Linux installation, it’s highly recommended to set up user accounts. Following best practices for security, we’ll create two accounts:

  • Admin Account: For server administration and initial setup (e.g., kyle). This account will have sudo privileges.
  • Game Server Account: A non-privileged account dedicated to running the Factorio server (e.g., gamemaster). This enhances security by limiting the potential impact if the game server is compromised.

Log in to your server using the admin account you created during installation, preferably via SSH for easier command-line access.

2. Installing Essential Bundles

Clear Linux uses bundles to manage software packages. We’ll need to install some essential bundles:

sudo swupd bundle-add wget git tmux python3-basic
  • wget: For downloading the Factorio headless server package.
  • git: For cloning the Factorio updater script.
  • tmux: A terminal multiplexer to keep the server running even after you disconnect from SSH.
  • python3-basic: Python 3 and essential libraries required by the Factorio updater script.

3. Downloading and Installing Factorio Headless Server

Navigate to the gamemaster user’s home directory:

cd /home/gamemaster

Download the Factorio headless server package. You can find the download links on the Factorio website. For the latest stable version, use:

sudo wget -O factorio_headless.tar.gz https://www.factorio.com/get-download/stable/headless/linux64

If you prefer the experimental version (use with caution as it might be less stable), replace stable with experimental in the URL.

Extract the downloaded archive:

sudo tar xf factorio_headless.tar.gz

This will create a factorio directory in /home/gamemaster. Navigate into it:

cd factorio

4. Configuring Your Factorio Server

Factorio server settings are managed through a JSON file. Navigate to the data subdirectory:

cd data

Copy the example server settings file:

sudo cp server-settings.example.json server-settings.json

Edit server-settings.json using a text editor like vim or nano. If you don’t have vim, you can install it: sudo swupd bundle-add vim.

sudo vim server-settings.json

Modify the following settings according to your preferences:

  • name: The name of your server that will be displayed in the public server list.
  • description: A brief description of your server.
  • username: Your Factorio game username.
  • token: Your Factorio service token. Generate this from your Factorio profile page. Using a token is more secure than a password.
  • game_password: Set a password if you want to restrict access to your server.
  • autosave_interval: The frequency of autosaves in minutes. A value of 60 (minutes) is reasonable.

Save the file and exit the text editor.

Return to the main factorio directory:

cd ..

Create directories for saves and mods:

sudo mkdir -p saves mods

Place any mods you want to use in the mods directory as .zip files. The server will automatically load them on startup. To upload mods, you might need to enable SFTP on Clear Linux if you haven’t already. Refer to the Clear Linux documentation for instructions.

5. Creating a Save Game

Before starting the server, you need to create a save file. This will be the base map for your server.

sudo ./bin/x64/factorio --create saves/my_save.zip

Replace my_save.zip with your desired save file name.

6. Testing Your Factorio Server

You can now test if your server starts correctly. Find your server’s IP address using:

ip a

Note down the IP address (e.g., 192.168.85.135).

Start the server with your save file:

sudo ./bin/x64/factorio --start-server saves/my_save.zip

Or to load the latest save with server settings file:

sudo ./bin/x64/factorio --start-server-load-latest --server-settings ./data/server-settings.json

Launch Factorio on your gaming PC, go to “Multiplayer,” then “Connect to server,” and enter your server’s IP address. If you set a password, you’ll be prompted to enter it. You should now be able to join your Factorio server. Exit the game client and stop the server by pressing Ctrl+C in the server terminal.

7. Setting Up Automatic Updates with Factorio Updater

To keep your server updated, especially if you are using the experimental version, the Factorio Community Updater is invaluable. We already installed git in step 2, so let’s clone the updater repository:

sudo git clone https://github.com/narc0tiq/factorio-updater.git

This will create a factorio-updater directory within /home/gamemaster/factorio.

8. Permissions for the Game Server Account

To allow the gamemaster user to run the server and updater, we need to change ownership of the factorio directory and its contents to the gamemaster user and group:

sudo chown gamemaster:gamemaster /home/gamemaster/factorio -R

Switch to the gamemaster user:

su gamemaster

9. Creating Start and Update Scripts

Create two bash scripts in the gamemaster home directory for easier server management:

start_factorio.sh:

#!/bin/bash
cd /home/gamemaster/factorio
./bin/x64/factorio --start-server-load-latest --server-settings ./data/server-settings.json

update_factorio.sh:

#!/bin/bash
cd /home/gamemaster/factorio
python3 ./factorio-updater/update_factorio.py -xuDa ./bin/x64/factorio

Make these scripts executable:

chmod +x start_factorio.sh update_factorio.sh

10. Port Forwarding on Your Router

To make your server accessible from the internet, you need to forward UDP port 34197 on your router to your server’s local IP address (192.168.85.135 in our example). The exact steps for port forwarding vary depending on your router model. Consult your router’s documentation for instructions. It is recommended to only forward UDP port 34197 and restrict it to your server’s IP for security.

11. Running Your Factorio Server Persistently

To run the server in the background even after you close your SSH session, use tmux. Start a new tmux session:

tmux new -s factorio-server

Inside the tmux session, start your server using the start script:

./start_factorio.sh

Press Ctrl+B then D to detach from the tmux session. The server will continue running in the background. To re-attach to the session later, use: tmux attach -t factorio-server.

12. Restarting Your Factorio Server and Map Management

To restart your Factorio server, you first need to stop the currently running server. If you are in a tmux session, you can press Ctrl+C in the server terminal. If you detached from the session, re-attach using tmux attach -t factorio-server and then press Ctrl+C.

Once the server is stopped, you can restart it by simply running the start script again:

./start_factorio.sh

This will restart the server with the latest save and your server settings.

Map Management and Server Restarts for Map Changes:

If you need to change the map or start a new game, you’ll need to:

  1. Stop the server as described above.

  2. Create a new save file with a different name using the command from Step 5, for example:

    ./bin/x64/factorio --create saves/new_map.zip
  3. Modify the start_factorio.sh script to specify the new save file. Change the line in start_factorio.sh to:

    ./bin/x64/factorio --start-server saves/new_map.zip --server-settings ./data/server-settings.json

    Or, if you want to always load the latest save, you can use --start-server-load-latest and manually replace the latest.zip symlink in the saves folder with the save file you want to use as the “latest”.

  4. Restart the server by running the start_factorio.sh script:

    ./start_factorio.sh

This process allows you to effectively restart your Factorio server and manage different save games, essentially allowing you to “restart the map” by loading a new save file. You can have multiple save files in the saves directory and switch between them by modifying the start_factorio.sh script and restarting the server.

13. Updating Your Factorio Server

To update your Factorio server to the latest version, stop the server and then run the update script:

./update_factorio.sh

After the updater finishes, restart the server using the start script:

./start_factorio.sh

Conclusion

Congratulations! You have successfully set up a Factorio dedicated server on Clear Linux. Your friends can now connect to your server and enjoy playing Factorio together. Remember to keep your server updated and manage your save files as needed. By using Clear Linux, you benefit from a fast and secure platform for hosting your Factorio world. Enjoy building your factory!

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *