Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

How to setup a Factorio server on a VPS or Dedicated server

profile picture
Author
Jozef Mäsiar
Published
2024-12-10
Time to read
8 minutes reading time

Introduction

This tutorial will show you how to create a Factorio server on your VPS or dedicated server.

This tutorial was tested on Ubuntu 24.04.

Prerequisites

  • One local device with Factorio installed on it → so you can connect to the game server.
  • One server with Ubuntu → to host the game server.
    • You will need access to a root account or a user with sudo permissions.
    • This server has to be x86-64.

Example terminology

  • 203.0.113.1 - Example public IP of the remote server
  • faserver - Example user on the remote server

Step 1 - Setting up the server

In this section, we will set up a new non-root user with sudo permissions that we can use to run the server. We will also download the server and create a first save!

Step 1.1 - Adding new non-root user

It's usually best to avoid using the root user. As root users can do anything they want on the server, there's a risk of accidental or unintentional changes being made. One way to reduce this risk is to create a new user with sudo privileges. So let's create the new user.

adduser faserver

Now you will be asked for a password. Make sure to set a secure one!

You don't need to set the personal details. Just press enter to leave default values. Press enter to confirm the details.

Is the information correct? [Y/n] Y

Next, add the new user to the sudo group:

usermod -aG sudo faserver

We will need to log in as our new user:

su - faserver

Step 1.2 - Enabling port 34197

If you've got a firewall on your VPS, you'll need to make sure it allows port 34197 UDP so you can connect to it from the internet.

There are a few firewalls you can use, but we'll just cover these two:

UFW → Default firewall on Ubuntu

First things first, let's check if our firewall is enabled.

sudo ufw status

If you see Status: active then your firewall is up and running. Now we can add our new rule:

sudo ufw allow 34197/udp

Now we can check if our rules are as they should be

sudo ufw status

and you should see something like this

faserver@ubuntu:~# sudo ufw status
Status: active

To                         Action      From
--                         ------      ----
OpenSSH                    ALLOW       Anywhere
34197/udp                  ALLOW       Anywhere
OpenSSH (v6)               ALLOW       Anywhere (v6)
34197/udp (v6)             ALLOW       Anywhere (v6)

The resulting output may vary slightly depending on the rules that were applied prior to this step.

Hetzner Cloud Firewall

This only applies if you're using a Hetzner Cloud server and have Hetzner Cloud Firewall enabled. To edit your firewall rules, just go to Cloud Console and select your project. When you're in your project, select "Firewall" from the sidebar. Then select the firewall from the list that is applied to your server. Add the following "inbound" rule:

IPs Protocol Port Port range
Any IPv4 Any IPv6 UDP 34197 Leave empty

Step 1.3 - Downloading Factorio server

Now we can download the latest version of the game

wget https://factorio.com/get-download/stable/headless/linux64 -O factorio-server.tar.xz

NOTE: If you want an older version, just add the version of the game. For example if you want version 1.1.109, the link will look like this https://factorio.com/get-download/1.1.109/headless/linux64. You can find a full list of all versions here: factorio.com/download/archive

We will need to extract the tar.xz file. To extract it, run this command:

tar -xf factorio-server.tar.xz

This will create a new directory called "factorio", so we will go into it:

cd factorio

Step 1.4 - Creating a save

The Factorio server won't start without a save. You can create one using this command:

mkdir saves && ./bin/x64/factorio --create ./saves/my-save.zip 

This command will create a map using the default settings. You can replace my-save with a name of your choice.

Step 1.5 - Starting the server

Now we can start the server:

./bin/x64/factorio --start-server-load-latest

This command will use tha latest save that is in the "saves" directory.

You can use /players to test if the game server is working:

2.439 Info ServerMultiplayerManager.cpp:806: updateTick(0) changing state from(CreatingGame) to(InGame)
/players
Players (0):

On your local device, you can now open the Factorio launcher, select "Multiplayer", click the "connect to an address" option, and enter your IP address and the default port, e.g. 203.0.113.1:34197.

On your server, you can run /quit to stop the game.

Step 2 - Making the server run non-stop

For this, we will use systemd.

  1. Create a new file called factorio-server.service in /etc/systemd/system and edit it.

    sudo touch /etc/systemd/system/factorio-server.service && sudo nano /etc/systemd/system/factorio-server.service
  2. Here are the required contents of the factorio-server.service file:

    [Unit]
    Description=Factorio Headless Server
    
    [Service]
    Type=simpleP
    User=faserver
    WorkingDirectory=/home/faserver/factorio
    ExecStart=/home/faserver/factorio/bin/x64/factorio --start-server-load-latest
    
    [Install]
    WantedBy=multi-user.target
  3. Make it so the server starts on server boot

    sudo systemctl enable factorio-server.service
  4. Start the server

    sudo systemctl start factorio-server.service

Run ss -ul to check if the game is running on port 34197.

On your local device, you can now open the Factorio launcher and connect to the game as explained before.

Step 3 - Customization

Step 3.1 - Changing the port

  1. Open the factorio-server.service file:

    sudo nano /etc/systemd/system/factorio-server.service
  2. Change the 8th line:

    # Before
    ExecStart=/home/faserver/factorio/bin/x64/factorio --start-server-load-latest
    
    # After
    ExecStart=/home/faserver/factorio/bin/x64/factorio --start-server-load-latest --port <your-port>

    Replace the port with your desired port (it should have 4 or 5 digits).

    NOTE: If you password protected your game, don't forget to add --password <your-password> to the end of the replaced line! Also don't forget to update your firewall settings! Refer to Step 1.3 if you have UFW or Hetzner Cloud Firewall.

  3. Restart the game server:

    sudo systemctl daemon-reload
    sudo systemctl restart factorio-server.service

Run ss -ul to check if the game is running on your preferred port.

On your local device, you can now open the Factorio launcher, select "Multiplayer", click the "connect to an address" option, and enter your IP address and the custom port, e.g. 203.0.113.1:<your-port>.

Step 3.2 - Giving yourself admin permissions

  1. Stop the game server:

    sudo systemctl stop factorio-server.service
  2. Start the game server manually:

    cd factorio/ && ./bin/x64/factorio --start-server-load-latest

    NOTE: If you set custom port don't forget to add --port <your-port> at the end of the command

  3. Join the game server and run:

    /promote <your-username>
  4. Stop the game server using CTRL+C and restart the game server via systemctl:

    sudo systemctl start factorio-server.service

Step 3.3 - Protecting your game

You can protect your game using a password or a whitelist. We will only focus on password protection here.

  1. Open factorio-server.service file:

    sudo nano /etc/systemd/system/factorio-server.service
  2. Change the 8th line:

    # Before:
    ExecStart=/home/faserver/factorio/bin/x64/factorio --start-server-load-latest
    
    # After:
    ExecStart=/home/faserver/factorio/bin/x64/factorio --start-server-load-latest --password <your-password>

    NOTE: If you set a custom port, don't forget to add --port <your-port> to the end of the replaced line!

  3. Restart the server:

    sudo systemctl daemon-reload
    sudo systemctl restart factorio-server.service

Step 4 - Updating the Factorio version

  1. Download the latest version of Factorio:

    wget https://factorio.com/get-download/stable/headless/linux64 -O factorio-server.tar.xz
  2. Extract the latest version of Factorio:

    tar -xf factorio-server.tar.xz
  3. And restart the server:

    sudo systemctl restart factorio-server.service

Conclusion

You should now have a Factorio game server up and running. For more custom settings, edit factorio/config/config.ini. To enable a setting, remove the ; symbol at the beginning of the corresponding line. To apply the changes, restart the game server with systemctl.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue

Discover

#Hetzner4gamers

Take your gaming experience to the next level! Discover which Hetzner server is best for your gaming world.

Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more