Killing Floor 2

Killing Floor 2

Not enough ratings
How to host your own cheap KF2 server ? [EN]
By nik_y\\>
In this guide,
I'm going to show you how to host your own KF2 server
at a (paying) Linux host (preferably on Ubuntu server 18.04),
and inexpensive.

If you follow protocol to the letter, there shouldn't be any problems.

With this method, you will save money instead of paying hosts with exorbitant prices and probably a rather high latency !

In addition, I will show you that afterwards you can very well rent a server for less than a month, pay only per hour and then remove the server when it is no longer needed.

After the installation, which might seem a bit difficult for those who have never used a linux terminal, as well as the configuration of the kf2 server, it will be much simpler afterwards.

Let's get started!
   
Award
Favorite
Favorited
Unfavorite
Step 1 : Choose your host and log on to your server.
To choose your host, several parameters must be taken into account.
First of all, we try to obtain the cheapest possible server while respecting the criteria.
Here are some examples of servers that I recommend :
Feel free to adapt the language of the site, as prices may vary depending on your country of origin!

Serverspace and Scaleway to my knowledge allows you to stop whenever you want your server, and avoid paying all month without using it.

When selecting a server, choose the hosting provider whose server is located close to your location. Don't hesitate to check even the city of origin because even if it is in your country, the city can be hundreds of miles away, while there is a closer server in a neighboring country!

The closer the server is, the "theoretically" lower the latency, so a better experience!

Now that you have filtered your hosts on their location, we will see which VPS (virtual dedicated server, VDS in english) server to take.
Here is the minimum configuration to be respected:
  • CPU Core : 1
  • RAM : 1 GB
  • Disk space (SSD ideally) : 25 GB <--- If the server has only 20 GB, the KF2 server will not install!
  • No IPv6, IPv4 only
  • Traffic (Optional) : unlimited
  • Operating system : Ubuntu (server) 18.04
All you have to do is order your server, and wait patiently for it to be available.

In the meantime, I recommend that you download the PuTTY software that will help us connect to the server via SSH.
https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html
After installing the software, run it!


When the server will be ready for use, you will normally have received either by email or on your host's control panel the server's ip address, as well as the root credentials.

After retrieving the necessary information, on PuTTY you enter the information on the main page.
You need to specify the public ip(v4) address of the server, the default port for SSH (22), the connection type (SSH) and specify a name for your server and register it. And finally, you click open, accept the connection certificate afterwards.

You type root in login, hit enter.
login as : root
Then you enter your password given by the host to login as root.
root@<ipv4server>'s password : [rootpassword]
Again tap enter, and now you're logged in!
Step 2 : Install a KF2 server on your VPS.
The first thing to do when you first connect to your server is to update it.

Execute the following command:
apt-get update && apt-get upgrade -y
The server will download all the necessary updates whether it's about security, or improvements for other applications and then apply them.

After the end of this one, when you will be able to rewrite a command, we will install the steamcmd software that will allow us to download the KF2 server.
Execute the following commands:
  1. add-apt-repository multiverse
  2. dpkg --add-architecture i386
  3. apt update
  4. apt install lib32gcc1 steamcmd
You may be asked for a confirmation each time, press y to validate.
When installing steamcmd, do not forget to confirm the certificate of use by using the directional arrows to move, the space key to validate, and the enter key to pass.

For those they only want to install with the command: apt install steamcmd, we install steamcmd via the multiverse directory because it is not available by default as your server is nowadays (usually) installed with a 64-bit system, hence the previous manipulation.

We are going to install other important elements for the operation of the server.
Execute the following command:
apt install mailutils postfix curl wget file tar bzip2 gzip unzip bsdmainutils python util-linux ca-certificates binutils bc jq tmux libstdc++6 lib32stdc++6 netcat
Press y to validate.

Now we will start the server installation by creating a new user profile on the server, to avoid any problems via root (the root profile is very dangerous, it has all possible rights and can even destroy your server).
Execute the following command :
adduser kf2server
After that, he will ask you for some necessary information including the password.
For security best practice, ensure you set a strong password. Random password : TU5MjU1NTg3N
For local information of the type your country, etc ... you can leave a blank.

We're going to give the sudo administrative rights to this new account.
Execute the following command :
usermod -aG sudo kf2server

Now we are going to change the user and leave the root profile.
Execute the following command :
su - kf2server

Now that you are connected to your new profile, we are going to download internally from its folder the necessary elements to set up the server.
Execute the following command :
wget -O linuxgsm.sh https://linuxgsm.sh && chmod +x linuxgsm.sh && bash linuxgsm.sh kf2server

To finish, we launch a linux executor file that will install everything simply, it will just need to validate with enter so that it can execute the installation.
Execute the following command :
./kf2server install
The installation will take more or less 15 to 20 minutes depending on the connection speed of your host (which is usually fibred). This will install all the initial maps of KF2 so that it can run them, the file size will reach 20GB in total.
It is possible that important elements are missing during the installation, which the installer will inform you about and ask you to install. You will just have to enter your kf2server account password and press enter. This will execute a sudo command that was given after the account was created.

At the very end, when you will be able to rewrite a command, we will launch and then shut down the server a first time so that it can create the necessary files for its configuration.
Execute the following commands :
  1. ./kf2server start
  2. ./kf2server stop
Step 3 : Configure your KF2 server.
Now that we have installed the KF2 server on the vps and generated the configuration files, we will modify them.

First of all, we will install the nano software which is a text editor, which is normally installed on ubuntu.
Execute the following command:
sudo apt install nano
The sudo command will allow you to get administrative privileges, it will normally ask you for the password of your new kf2server account. It may be that the nano software is already installed and even better !

To check where you are in the server files, run the following command:
ls
Normally you are in your kf2server account master file, and at the same time you distinguish the folder that will be of interest to us <serverfiles>.

We'll move from file to file and then edit the file we're looking for. Execute the following commands:
cd serverfiles/KFGame/Config
nano KFWeb.ini
There you enter the text editor, now we're going to change some parameters.
In [IpDrv.WebServer], change the line "bEnabled=false" to "bEnabled=true".
And change the line "ListenPort=8080" to another port from 2000 to 9999 (or you can leave it as default). This will increase security, because we enable the configuration panel of the KF2 server web page.


Now we are going to save the document and exit it, execute the following keystrokes:
CTRL+X ---> Y ---> ENTER

We continue to edit other files.
Now, execute the following command:
nano LinuxServer-KFEngine.ini

Sometimes the configuration files are too large, so we will search for them by executing the following keystrokes :
CTRL+W ---> bUsedForTakeover ---> ENTER
Change the line "bUsedForTakeover=TRUE" to "bUsedForTakeover=FALSE". This will block the server "lease" system. When a player performs a server search, it's possible that he will get yours back by changing the settings, which we'll avoid.


Now we are going to save the document and exit it, execute the following keystrokes:
CTRL+X ---> Y ---> ENTER

We continue to edit other files.
Now, execute the following command:
nano LinuxServer-KFGame.ini

In this file we are not going to change the difficulty of the server because it is not necessary, you can do it later on the administrative web page of the KF2 server. We will provide an administrative login password for the site, as well as a password (optional) to connect to the game server.
Scroll down in the file with the bottom directional arrow and then go to the [Engine.AccessControl] paragraph.
All you have to do is enter an administrative password on line "AdminPassword=[...]" and a password to connect to the server (to give access only to your friends) in the line "GamePassword=[...]" or a blank if you don't want to...


Now we are going to save the document and exit it, execute the following keystrokes:
CTRL+X ---> Y ---> ENTER

Now we'll apply the settings to the servers. Execute the following command three times:
cd ..

We're back to the root of our folder, and we're going to reboot the server by executing this command:
./kf2server start
And then execute the following command:
./kf2server details
This will show you all the server information at the moment.
Normally on the last line, the server status should be on "online".
We'll take care of the WebAdmin part. You have to check if the line "WebAdmin enabled: [...]" is on true or false. If it's on false, we'll have to do the same manipulation on another folder.

For those who have false, execute the following commands:
cd serverfiles/KFGame/Config/kf2server
nano KFWeb.ini
In [IpDrv.WebServer], change the line "bEnabled=false" to "bEnabled=true".
And change the line "ListenPort=8080" to another port from 2000 to 9999 (or you can leave it as default), same as before.


Now we are going to save the document and exit it, execute the following keystrokes:
CTRL+X ---> Y ---> ENTER

For those who have a different administrative password as well as the password to access the in-game server, execute the following commands:
nano LinuxServer-KFGame.ini
Scroll down in the file with the bottom directional arrow and then go to the [Engine.AccessControl] paragraph.
All you have to do is enter an administrative password on line "AdminPassword=[...]" and a password to connect to the server (to give access only to your friends) in the line "GamePassword=[...]" or a blank if you don't want to...


Now we are going to save the document and exit it, execute the following keystrokes:
CTRL+X ---> Y ---> ENTER

Now we'll apply the settings to the servers. Execute the following command four times:
cd ..

We're back to the root of our folder, and we're going to reboot the server by executing this command:
./kf2server restart
And then execute the following command:
./kf2server details
If line "WebAdmin enabled: [...]" is set to true, it means that the administrative page of the KF2 server is online!

Try to connect to the link provided by the command:
./kf2server details
on your web browser (prefer Mozilla Firefox as your browser).
The link should look like this:

It should look like this:


In section "username" enter : Admin
And in section "password" enter your administrative password that you defined previously.
Finally, click on login.
All you have to do is browse the site and enter the game settings you want. And all that's left to do is to connect to the server in KF2.

Start the game Killing Floor 2, and go to the menu by pressing the F3 key.
Enter the following command:
open <ipv4server>
And that's it!

If you have set a password to access your server, it will automatically ask you when you log in, and then it connects you without any worries.

You can then see that you got your own server, for a small price, and a very low latency due to its location!

Now you can enjoy your game server with your friends while cutting the ZEDs into small pieces.
Step 4 : Securing your VPS server (optional).
Now, I will show you how to secure your VPS server, although it is optional in the tutorial but it seems important to me.

The first thing to do is to change the root password of your machine. If someone unfortunately has access to this session, he can literally do anything on it (he will become a god).
So to remedy this, you will connect to the root session, by executing this command:
su - root
Either you're asked for the root password, you enter it. Or you were simply already logged in on it, or you logged in on your server via root as input (something we're going to change).

Run this command to change the root password:
passwd root
Type in the new password, make it cosy and make sure you never forget it!

Now we're going to do two things at the same time, we're going to make sure to change the listening port to SSH on your server, and prevent a direct connection to your server as root. This means, instead of entering port 22 to connect to the server in SSH, you will put the port you changed instead. And you won't be able to connect directly as root anymore, so you'll have to connect to one of the sessions we created, such as "kf2server" for example. The advantage of changing the listening port is to avoid being automatically attacked by DDOS or any other type directly by bots on known listening ports.

Execute the following command (as root) :
nano /etc/ssh/sshd_config
Now look for the line with port (remove the "#" to uncomment it ), then you just have to indicate a port between 2000 and 9999.


Now we will indicate in the same file to prevent root connections to the server.
Type this key combination to search and type "Authentication":
CTRL+W ---> Authentication ---> ENTER
After that, all you have to do is remove the "#" on the 3 lines below, and change the line "PermitRootLogin yes (or something else)" to "PermitRootLogin no".


Now we are going to save the document and exit it, execute the following keystrokes:
CTRL+X ---> Y ---> ENTER

Now we will apply the changes by executing this command:
/etc/init.d/ssh restart
Don't forget your SSH listening port (which is not 22 anymore), it will become your new entry port!

Now you need to quit and test if it works. Execute the following command:
exit
Do it as many times, it will automatically exit PuTTY.
All that's left to do is to restart the software and test if you manage to connect with port 22, if it doesn't work, great! Try to connect with your new port, accept the new certificate at the time of connection, try to connect as root (with the new password). That doesn't work too? Perfect! Now try to connect with your normal session (for example "kf2server"). And if it works, you're great!

After connection, we are going to connect one last time as root from your normal session to set up a firewall which is one of the important barriers to unexpected connections on the server!
Execute the following command:
su - root
Re-enter your root password.

Now you are going to execute the following commands (be careful, be very careful, follow what I tell you because it is possible that you may not be able to connect to the server anymore. You'd be good to start all over again) :
apt install ufw
We install the firewall software that is normally installed by default (but just in case).

We will enter your new SSH connection port previously defined:
ufw allow <port>
Enter your new port without the "<>", and make no mistake, this part is crucial!
I repeat, this port corresponds to the new port you set to enter your server in SSH other than port 22.

Now we will enter the ports corresponding to your game server to leave the incoming connections for the KF2 server. Execute the following commands:
ufw allow 27015/udp
ufw allow 20560/udp
ufw allow 7777/udp
ufw allow 123/udp
ufw allow <port>/tcp
The last command, you must enter the port corresponding to your port on the KF2 server administration website defined in step 3 (by default it is port 8080) and don't forget to remove the "<>" when you enter the new port .

If you made a mistake, execute this command to remove the error:
ufw delete allow <port>/...

Now is the moment of truth. All we have to do is activate it and we'll know if it works.Think twice before activating this command (I also sometimes make mistakes and have had to do it all over again):
ufw disable
ufw enable
He will ask you for confirmation, type Y to validate.
If you have not been ejected from the server, and you can still write a command, then it worked!

We now check the open ports on the firewall by executing the following command:
ufw status
If all the open ports match the ones you've opened, it's perfect!
If you see an open port named "OpenSSH", you can remove it, it corresponds to port 22 which is no longer needed in our case, it even corresponds to a flaw in the system actually.

All you have to do is leave the root session by executing the command :
exit
And test on your game server, on the KF2 game server administrative website if everything works.
Step %% : Basic Usage (KF2 Server) & Credits
Basic Usage

All Commands
A complete list of commands can be found by typing.
./kf2server
Below are the most common commands available.

    Running
  • start
    ./kf2server start
  • stop
    ./kf2server stop
  • restart
    ./kf2server restart
  • console
    Console allows you to view the live console of a server as it is running and allow you to enter commands; if supported.
    ./kf2server console
    To exit the console press CTRL+b d. Pressing CTRL+c will terminate the server.

    Updating
  • update
    Update checks for any server updates and applies them. The server will update and restart only if required.
    ./kf2server update
    Bypass the check and go straight to SteamCMD update.
    ./kf2server force-update
    validate
    You can use the SteamCMD validate option when updating the server.
    ./kf2server validate

    Debugging
  • Details
    You can get all important and useful details about the server such as passwords, ports, config files etc.
    ./kf2server details
  • Debug
    Use debug mode to help you if you are having issues with the server. Debug allows you to see the output of the server directly to your terminal allowing you to diagnose any problems the server might be having.
    ./kf2server debug
  • Logs
    Server logs are available to monitor and diagnose your server. Script, console and game server (if available) logs are created for the server.
    /home/kf2server/logs

Backup
Backup will allow you to create a complete tar bzip2 archive of the whole server.
./kf2server backup

Monitor
LinuxGSM can monitor the game server by checking that the proccess is running and querying it. Should the server go offline LinuxGSM can restart the server and send you an alert. You can use cronjobs to setup monitoring.
./kf2server monitor

Configure LinuxGSM
For details on how to alter LinuxGSM settings visit LinuxGSM[docs.linuxgsm.com] Config Files page.

Documentation
For detailed documentation visit the LinuxGSM docs[docs.linuxgsm.com].


I hope this tutorial has helped you despite its length. This is my very first handwritten tutorial, so don't hesitate to criticize me if something is missing or doesn't conform ...
If you enjoyed it, feel free to comment on it, share it, and if you have any special requests, feel free to contact me !
I look forward to hearing from you.
1 Comments
nik_y\\>  [author] 27 Jun, 2020 @ 2:49pm 
Hello les gens,
je sais que pour certains c'est légèrement frustrant que ça soit en anglais (oui, je parle à vous les français) et j'aurais pu proposer une version francophone, mais je n'ai pas le courage de le refaire x). J'ai réalisé ce guide (avec un anglais approximatif) dans le but que n'importe qui (en théorie) puisse le lire. Et je peux comprendre que ça peut être compliqué pour certain. En tout cas, ce guide est pour moi une fierté étant mon tout premier. Je n'ai toujours pas eu de retour de celui-ci (peut être un peu trop de bricolage pour certains) mais si cela à fonctionné ou vous avez besoin d'aide, n'hésiter pas à laisser un commentaire. Gros bisous à vous ! :ralphsmile: