Skip to content

Latest commit

 

History

History
225 lines (147 loc) · 10.6 KB

GUIDE.md

File metadata and controls

225 lines (147 loc) · 10.6 KB
SPDX-License-Identifier path slug date title short_description tags author author_link author_img author_description language available_languages
MIT
/tutorials/cs2-dedicated-server-in-2024
cs2-dedicated-server-in-2024
2024-11-07
Counter-Strike 2 Dedicated Server in 2024 with Hetzner
Learn how to host your own Counter-Strike 2 dedicated server with Hetzner using a straightforward and simple approach to enjoy the game with your friends!
Self-Hosting
Counter-Strike
Lang:Bash
BakirGracic
Full-stack developer mastering web development but keen to learn as much as possible!
en
en
bs

If you are a fan of Counter-Strike and computers, a thought of playing on custom server with unique configurations probably crossed your mind! Well, this community guide is just for that. Here you will explore how to create and host a custom CS2 server from scratch leveraging Hetzner products.

Disclaimer

This guide will do everything from scratch with no helping tools/wrappers (straightforward approach). Yet it will be very simple for its type. Everything is explained in detail. This guide assumes you are using one of Hetzer VPS's and Ubuntu 24 image.

How (CS2) Servers Work

A server works by handling all of the user in-game interactions, processes it and sends it to clients. Along with a lot of incoming, there is also outgoing traffic.

CS2 server works by downloading all resources, files and code to be able to calculate everything, even though there is no GUI.

Steam, the company that made a platform for easier game selling and versioning, also acquired Counter-Strike. It is publicly available to host your own CS2 servers, unlike some other games that don't offer that ability. Steam made its own command line tools and packages for configuring anything Steam related, that tool is called steamcmd.

In short, we will prepare our new Hetzner server, install that tool, install CS2 server files, configure the server and run it - then its only gaming time!

System Requirements

CS2 is not Tetris. We need some adequate horsepower to be able to run the server and manage players. Thankfully Hetzner has all the tools & power we need. But still:

  • RAM: 2GB
  • Storage: 35GB (install file is ~33GB)
  • OS: Minimum Ubuntu 20.04, Debian 11, or Enterprise Linux 9 (Glibc 2.31 required, most likely included in these or newser versions)
  • CPU: 2 cores of any platform (AMD/Intel, ARM/x86)

STEP 0: Create a server

In your Hetzner account navigate to Cloud, then create a new project.

OPTIONAL: Add your device's SSH key in Security tab for it to be automatically added to your VPS, otherwise root password will arrive via email in your inbox!

Firstly create a firewall with these rules:

NAME PROTOCOL PORT
SSH TCP 22
ICMP (ping) ICMP
27015 UDP (game transmission) UDP 27015
27015 TCP (pings and RCON) TCP 27015
27005 UDP (Client Port) UDP 27005
27036 TCP (Steam remote play) TCP 27036
3478 UDP (matchmaking) UDP 3478
4379 UDP (matchmaking) UDP 4379
4380 UDP (matchmaking) UDP 4380

NOTE: I don't believe all rules are required, only ports 22 & 27015 need to be open, other are for convenience and additional functionality. If you know more, please contribute to this article on GitHub!

NOTE: The rules should apply to both IPv6 and IPv4 traffic!

Let's provision our server now! Click on Add server and:

  • pick an adequate location for you needs or closest to you
  • select Ubuntu 24.04 image
  • select Shared vCPU
  • choose a server with min 2 vCPU cores, min 4GB ram and 80GB of storage (I recommend CPX21)
  • choose IPv4 and IPv6 in networking
  • select your firewall created earlier
  • name your server with a good name

NOTE: Everything else is optional, you can fiddle with other options yourself

NOTE: If you select a plan with 40GB of storage, that will not be enough, since the OS will take some space and you will not have 40GB of free space!

Now, after your sever is online, connect to it via SSH using your favourite interface!

STEP 1: Update Server

To update our server to use latest packages and versions, as root run:

apt update && apt full-upgrade -y && apt autoremove -y && reboot

NOTE: Server will reboot, SSH again

STEP 2: Make steam user

For security and convenience reasons, let's simply create a new user. You can name it anything you like, I will do steam. To create a new user and add it to sudo group, as root run:

adduser steam && usermod -aG sudo steam

NOTE: Use a strong password, press enter to skip all of the default questions

OPTIONAL: You can generate new SSH key for the user and copy your public key to new users authorized_keys to avoid typing the password on each SSH connection

Now please SSH to server via the new user, e.g. steam

STEP 3: Install steamcmd

NOTE: From now on, run every command as steam user

Run this to install steamcmd dependency

sudo apt-get install lib32gcc-s1 -y

Run this to install steamcmd

sudo add-apt-repository multiverse && sudo dpkg --add-architecture i386 && sudo apt update -y && sudo apt install steamcmd -y

NOTE: Allow/accept anything that may occur on screen like Steam agreement

STEP 5: INSTALL CS2 FILES

Run this script from shell, it will begin CS2 server files installation

steamcmd +login anonymous +app_update 730 validate +quit

NOTE: After CS2 release appid for game and server files is now 730 for both. For CSGO server it was 740, make sure to have number 730 after app_update cvar

Now sit tight and relax, let the Hetzner's fast network connection and awesome VPS performance download CS2 files (may take around 5-10 minutes)

STEP 6: STEAM LOGIN

You need to login to a Steam account for this server to be accessible to the world (otherwise it will be accessible only to LAN, which in our case is pointless)

NOTE: Singular Steam user account can only be logged in once in any Steam server system, be it graphical system or steamcmd CLI!

NOTE: The session should persist (more info about this would be appreciated, contribute to GitHub article)

NOTE: It is recommended by Steam to have a separate Steam account just for the server, but you can use your private one for testing

NOTE: We use login anonymous for only local changes like updating

To login, run

steamcmd login <username>

Afterwards enter your passoword and additionally enter 2FA code (from email/steam guard,...)

STEP 7: Game Server Login Token (GSLT)

GSLT is a token used for locating and verifying your server on the network. It is mandatory to generate it and use it in server.

GSLT can easily be generated via the link steamcommunity.com/dev/managegameservers

NOTE: Make sure to be logged in with intended account

Input 730 as app/game ID

For the memo use a descriptive text so you know where that token is used and why is it generated. I will be using hetzner-eu-central-cs2-dedicated-server-test

The token will be generated, make sure to have it ready when we start the game!

STEP 8: STARTING THE SERVER

Run this boring command to ensure the server can run (needs to be ran only once)

mkdir ~/.steam/sdk64 && sudo ln -s ~/.local/share/Steam/steamcmd/linux64/steamclient.so ~/.steam/sdk64/

Finally run the server with

cd ~/.steam/steam/steamapps/common/Counter-Strike\ Global\ Offensive/game/bin/linuxsteamrt64 && ./cs2 -dedicated -ip "your-server-ip" -maxplayers 10 -port 27015 -tickrate 128 +hostname "CS2 DEDICATED SERVER TEST" +map de_ancient +sv_logfile 1 +sv_lan 0 +game_type 0 +game_mode 1 +sv_setsteamaccount "your-gslt-token"

IMPORTANT: Check each parameter and cvar to make sure it aligns with your needs

NOTE: You can find parameter and cvar info in resources at the end of the guide

SUCCESS

The server should now be online and accessible, try loggin in to it via CS2 in-game console by running connect <HETZNER_SEREVER_IP>:27015

In your console you should see a bunch of output, that is a good sign since those are CS2 game console logs! If the process terminates by itself, that may indicate an error occured.

NOTE: The server will run as long as your SSH connection is alive. To implement a more sustainable solution to that, read the next section

ADDITIONAL: SUSTAINABILITY

Server will run as long as our SSH connection is alive. To combat that and implement other sustainability concerns, I made a simple utility script! To use it, simply run:

mkdir -p ~/CS_SERVER && cd ~/CS_SERVER && wget -O cs_server.sh https://gist.githubusercontent.com/BakirGracic/5b91d0178ff207c28507bb0332fef837/raw && sudo chmod +x cs_server.sh && ./cs_server.sh setup

This script will provide you with all the necessary tools for managing your CS2 server:

  • on setup you will be able to configure basic config options
  • you can run the server indefinetly with ./cs_server.sh start
  • also you can stop the server with ./cs_server.sh stop
  • the script will automatically try to update CS2 server files every day

CONCLUSION

Thank you for reading so far. I hope this helped you to have some fun with your friends. If you are eager to do more, you can check my website bakir.dev and look for a project or a blog post about CS2 servers :D

RESOURCES

I highly encourage you to explore these resources to learn more about hosting your awesome CS2 server!