Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add make-a-factorio-server tutorial #991

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
396 changes: 396 additions & 0 deletions tutorials/make-a-factorio-server/01.en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,396 @@
---
SPDX-License-Identifier: MIT
path: "/tutorials/make-a-factorio-server"
slug: "make-a-factorio-server"
date: "2024-11-09"
title: "How to setup a Factorio server on a VPS or Dedicated server"
short_description: "You will learn how to setup a Factorio server on a VPS or dedicated server."
tags: ["Factorio", "Gaming"]
author: "Jozef Mäsiar"
author_link: "https://github.com/JopGamer"
author_img: "https://avatars.githubusercontent.com/u/59136132?v=4"
language: "en"
available_languages: ["en"]
header_img: ““
cta: "gaming"
---

## 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 server.
* **One server** with Ubuntu → to host the game server.
* You will need access to a root account or a user with sudo permissions.
* Also 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 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.

```bash
adduser faserver
```

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

```bash
New password:
Retype new password:
passwd: password updated successfully
```

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

```bash
Changing the user information for faserver
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
```

Press enter to confirm the details.

```bash
Is the information correct? [Y/n] Y
```

### Step 1.3 - 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:

<details>

<summary>UFW → Default firewall on Ubuntu</summary>

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

```bash
ufw status
```

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

```bash
ufw allow 34197/udp
```

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

```bash
ufw status
```

and you should see something like this

```bash
root@ubuntu:~# 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.

</details>

<details>

<summary>Hetzner Cloud Firewall</summary>

This only applies if you're using a [Hetzner Cloud](https://console.hetzner.cloud/projects) 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* |
</details>

### Step 1.4 - Downloading Factorio server

We will need to log in as our new user

```bash
su - faserver
```

Now we can download the latest version of the game

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

> **NOTE:** If you want older version just replace the **latest** with the version of the game. For example if you want version **1.1.109** than the link will look like this `https://factorio.com/get-download/1.1.109/headless/linux64`. Full list of all versions can be found here: <https://factorio.com/download/archive/>

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

```bash
tar -xf factorio-server.tar.xz
```

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

```bash
cd factorio/
```

### Step 1.5 - Creating save

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

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

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

### Step 1.6 - Starting the server

Now we can start the server

```bash
./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 server is working:

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

## Step 2 - Making the server run non-stop

For this we will use `systemd`.


1. If you are still logged in as a `faserver` do:

```bash
exit
```


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

```bash
touch /etc/systemd/system/factorio-server.service && nano /etc/systemd/system/factorio-server.service
```


3. Here are the required contents of the `factorio-server.service` file:

```toml
[Unit]
Description=Factorio Headless Server

[Service]
Type=simple
User=faserver
WorkingDirectory=/home/faserver/factorio
ExecStart=/home/faserver/factorio/bin/x64/factorio --start-server-load-latest
```


4. Make it so the server starts on server boot

```bash
systemctl enable factorio-server.service
```


5. Start the server

```bash
systemctl start factorio-server.service
```

## Step 3 - Customization

### Step 3.1 - Changing port


1. Open `factorio-server.service` file

```bash
nano /etc/systemd/system/factorio-server.service
```


2. Change 8th line:

```bash
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>
```

And replace the port with your desired port.

> **NOTE:** That if you password protected your game don't forget to add `--password <your-password>` to the end of the replaced line! Also dont forget to update your firewall settings! Refer to [Step 1.3](https://notes.jopgamer.xyz/doc/tutorial-setup-factorio-server-tNhfPNc1QX#h-step-13-enabling-port-34197) if you have UFW or Hetzner Cloud Firewall.


3. Restart the server

```bash
systemctl restart factorio-server.service
```

### Step 3.2 - Giving your self admin


1. Stop the server

```bash
systemctl stop factorio-server.service
```


2. Log in as `faserver` user

```bash
su - faserver
```


3. Start the server

```bash
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


4. Join the server and do

```bash
/promote <your-username>
```


5. Stop the server using **CTRL+C** and start the normal server

```bash
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

```bash
nano /etc/systemd/system/factorio-server.service
```


2. Change 8th line:

```bash
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:** That if you set custom port don't forget to add `--port <your-port>` to the end of the replaced line!


3. Restart the server

```bash
systemctl restart factorio-server.service
```

## Step 4 - Updating


1. Log in as `faserver` user

```bash
su - faserver
```


2. Download the latest version of factorio

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


3. Extract the latest version of factorio

```bash
tar -xf factorio-server.tar.xz
```


4. Logout the `faserver` user

```bash
exit
```


4. And restart the server

```bash
systemctl restart factorio-server.service
```

##### License: MIT

<!--

Contributor's Certificate of Origin

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have
the right to submit it under the license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my
knowledge, is covered under an appropriate license and I have the
right under that license to submit that work with modifications,
whether created in whole or in part by me, under the same license
(unless I am permitted to submit under a different license), as
indicated in the file; or

(c) The contribution was provided directly to me by some other person
who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are
public and that a record of the contribution (including all personal
information I submit with it, including my sign-off) is maintained
indefinitely and may be redistributed consistent with this project
or the license(s) involved.

Signed-off-by: Jozef Mäsiar [email protected]

-->