Team Fortress 2

Team Fortress 2

196 ratings
Self-hosting your very own TF2 Server - 2022 Edition
By It Starts With and 1 collaborators
In this guide, I show you how to set up your own TF2 server on both Windows and Linux.
2
3
   
Award
Favorite
Favorited
Unfavorite
Installing SteamCMD
First, we're going to download SteamCMD.

Windows:
Download the SteamCMD file, make a steamcmd folder wherever you like and extract the EXE into it. Then double click it to run.

Linux:
Assuming you are running an Ubuntu/Debian-based distribution of Linux, install it from the package repo using these commands:
sudo dpkg --add-architecture i386 sudo apt install steamcmd
then just run steamcmd in the terminal.

SteamCMD will update itself just like Steam will, and the end result should look something like this with the Steam> at the bottom:
Downloading the TF2 server files
After we got SteamCMD running in the first place, now we get to download.

Setting an install directory for the server
Set an install directory (for this guide, I'm going to pick .\tf2\ as my install directory.) by using this command on the Steam> prompt:
force_install_dir .\tf2\
Warning: for Linux, this would be
force_install_dir ./tf2/
(with the forward slashes instead of the backslashes) due to the way that the file systems work.

Logging into Steam
Now we need to log into Steam Public, by typing
login anonymous
into the prompt and hitting Enter. If a firewall prompt appears, hit Allow. After it's logged in, it should be back to the Steam> prompt as shown here:


Actually downloading the files
Run the command:
app_update 232250 validate
This command downloads (and later on, updates) the TF2 server files.
Feel free to get a coffee, have a meal or something.


After it's done downloading and returns to the Steam> prompt, we can quit it by typing
quit
into the Steam prompt.

For the server to actually run on Linux, you might also need to do this in a normal terminal:
sudo apt install libtinfo5:i386 libncurses5:i386 libcurl3-gnutls:i386
Making sure the server actually runs
Windows

Go into the steamcmd directory. Then go into the tf2 (or whatever name you chose at the install directory step). Rightclick anywhere in the window with Shift held down, then click "Open command window here". On Windows 10, that option is called "Open PowerShell window here".

Type into the command/PowerShell window that opens:
.\srcds.exe -console -game tf

One of TF2's updates broke the GUI for the dedicated server, so if you want normal windows so you can set name, map and stuff with a mouse, get this fix, then run the same command again but with "!use-vgui" instead of "-console".[gamebanana.com]

Linux

Go into the ~/.steam/steamcmd/tf2 directory using your Terminal.
cd ~/.steam/steamcmd/tf2

Then, run this in the Terminal:
./srcds_run


If it ran correctly, it should look like this:



or for Windows, if you got the fix, it can also look like this:



Congratulations, the server runs! What next?
Networking
You need to allow unsolicited connections on (also known as opening) ports 27000-27050 on your router - https://portforward.com/router.htm has guides for most routers.

You also need to open those ports on your computer. Windows does it after a firewall prompt, for Linux please Google if your distribution has a firewall and how to open ports on it.

Getting a Game Server Login Token (GSLT)
Getting a game server login token (GSLT) has one important benefit: When people add your server to favorites, if you set a login token up, that favorite will stay valid even when your IP/port changes or you switch to an actual hosting company!

To get one, your Steam account:
  • must not be community banned
  • must not be limited
  • must have a phone number registered
  • must actually own the game

So, how do you get one and how do you use it?

First, you have to go to this page and log in if your Steam client doesn't do this automatically.

Then you have to put in the base game's Steam app ID (TF2's is 440) and a memo to keep track (see below image) and hit Create.



After hitting Create, the page refreshes and a fresh shiny new token appears in the list.
You should NOT share your game server login token with ANYONE (which is the reason the one in the screenshot is partially blurred out).



When you mouse over the list entry with the token, there are 3 buttons:
  • Regenerate Token - generates a new token. You can hit that button if your login token gets leaked. All your tokens will also be regenerated when Steam Support resets your password or you reset it using the Steam Help website.
  • Set Memo - sets a new memo
  • Delete - deletes game server account and it's login token
Configuration
autoexec.cfg
You'll be inputting your Game Server Login Token here.

Are you in the tf2 directory? yes? Then open a text editor of your choice, put in
sv_setsteamaccount GAMESERVERLOGINTOKEN
as seen in the screenshot



and save it as autoexec.cfg into tf2 (the directory that has the srcds.exe/srcds-run file in it)\tf\cfg (if you're using Windows Notepad, make sure to set the "Save as type" to All Files.

server.cfg

Go to this website https://cfg.tf/server/ and go through the tabs (General, Security & Logs, etc etc).

Then, go back to General and remove the address in the "Server address" field as it is not required.

Then, hit the "Generate config" button, download the file, open it and extract it to your tf folder (that one):



Congratulations! Your server is now ready for action! The other sections are for things like replays, SourceTV and mods.
Replays
Replays were introduced in the Replay Update on May 5, 2011. On servers that have the feature enabled, video replays of a player's life are recorded and saved directly onto the server. After a player dies, they can choose to download these recordings for editing within the game.

To enable this feature, you either need to have a Web server installed or have to rent one from a hosting provider.



First, go to your cfg folder (it's in .\tf2\tf).

Then, copy and paste replay_example.cfg - rename the second file to replay.cfg.

Now open that replay.cfg with a text editor of your choice (I'll be using Notepad)

We're going to look at "HTTP mode" since Valve broke FTP support.

Local HTTP mode

The double-slashes at the beginning of every line make the server count that line as a "comment".



Now let's look at those settings.

"replay_fileserver_offload_enable" tells the server if we want to use FTP or not. (leave this at 0.)
"replay_local_fileserver_path" tells the server where it should save the replay files for clients to download.

Now, we're getting to the part where the game client (aka the player's computers) get URLs to download their replays.

replay_fileserver_host tells the server the domain/IP address of the webserver.
replay_fileserver_port tells the server the port of the webserver.
replay_fileserver_path tells the server where the replays are (that directory must be accessible to everyone or they won't be able to download the replays!)


Add -replay to your launch options (the shortcut in Windows or the command line on Linux)


FTP mode

As of 18.04.2022, 02:04, this mode is still broken.
SourceTV
Spectator mode, but crank it up to 11.

You can enable SourceTV by running tv_enable 1, or you could go further and put this command at the end of your server.cfg to be run automatically!

Other console commands you can run on the server or put at the end of your server.cfg:

tv_name NAME - This sets the SourceTV name on the scoreboard and server browser.
tv_maxclients 0-255 - This sets the maximum client number for the SourceTV server.
tv_msg TEXT - sends a message to all players watching over SourceTV
tv_delay SECONDS - This sets the delay between what happens on the server and it appearing on SourceTV.
tv_delaymapchange 0-1 - This sets if the map change on the game server will be delayed until the rest of the buffered game has been broadcasted
tv_password PASSWORD - sets the password for connecting to the broadcast
tv_record FILENAME - starts a recording that records everything
tv_stoprecord - stops recording
tv_autorecord 0-1 - sets whether the server should automatically record
tv_relayvoice 0-1 - sets whether to allow player voice chat if broadcasted
tv_transmitall 0-1 - sets whether to transmit the whole game. Normally, entities and events outside of the auto-director view are removed from SourceTV broadcasts to save bandwidth.
tv_allow_camera_man 0-1 - allows a player on the Spectator team to become SourceTV camera man (being the camera for all SourceTV viewers)
Custom assets, FastDL and You
If you've tried to join a community server with a non-Valve game mode or map, you have experienced having to wait for the download of the models, sounds, maps and so on. If the server isn't using FastDL, download speed of these things is limited to 10-20KB/sec.

Here's where that web server comes in again. You know that folder structure that has the cfg, maps, materials, scripts folders, yes?

If you want to add a custom map/sound/etc, you must not only put it on the server, but your webserver as well.

Let's say my webserver has a tf folder.

Now I want to add the map plr_highertower.

so I put it in my TF2 server's maps folder and in the mapcycle.txt inside tf\cfg.

now I have to make a maps folder on the webserver and copy the map file into the maps folder on the webserver so the download goes faster.

Now I also have to put into my server.cfg this:

sv_downloadurl http://example.com/tf/

Now, if a player joins that was never on that gamemode/map, the client downloads the assets at a much faster speed.
Server Administration with server mods
Constantly going into server console is annoying. So, what if you could just do it all in-game?

Well, there's this wonderful thing called SourceMod. It allows you to administrate your server without having to alt-tab to your server console, with lots of plugins available to stop things like interpolation abuse or check player's reputation on SteamRep and much more[www.sourcemod.net].

I won't go into too much detail here since the makers of SourceMod have an excellent guide you should follow, linked here.[wiki.alliedmods.net]

Keep in mind that SourceMod depends on MetaMod:Source being installed, equally as excellent installation guide here[wiki.alliedmods.net]
Thanks for viewing.
If you're having problems or I've missed something, please comment! I will try and help/clarify and edit the guide!

*please have mercy this is my first guide I've ever written
70 Comments
Silly guy 25 May @ 2:37pm 
Well im trying to connect to the server and it keeps falling, awesome sauce 👍 Good guide though. i dont know what i messed up :(
BE LEAF 11 Mar @ 3:02am 
Thanks for the guide, it was extremely helpful! :cozytf2mug:

Though I must note that, like user below me noted, on Linux systems (Linux Mint in my case) steamcmd seems to install itself in the folder with the path /home/[user]/.local/share/Steam/steamcmd/ and not the one specified in the guide.
Other than that, everything worked as intended and I managed to get my server up and running!

P.S.: you don't really have to port forward anymore as steam allows you to use their network services to hide your IP and redirect players to you (sort of like VPN services do). To use this method, make sure that your server is executed with sv_use_steam_networking parameter set to 1. (i.e. +sv_use_steam_networking 1 )
Julius (VIP) 23 Nov, 2024 @ 10:11am 
i did everyhting but when i got to community servers, i didnt saw my server
benji194 23 Nov, 2024 @ 3:24am 
ok yes i know im stupid, but how do i start it? i finished the guide, but im stupid and dont know how to start the actual server
Femscout 19 Nov, 2024 @ 2:26pm 
in the shortcut put in this instead :

replace the C with the drive you have it and the folder.

C:\tf2ds\srcds.exe -console -game tf +sv_pure 1 +map ctf_2fort +maxplayers 24
a 14 Jul, 2024 @ 12:43am 
i can join it, but my friends say connection fail after 4 retries
qwerty and wasd 11 Jul, 2024 @ 2:31pm 
My server is not showing up in the lan menu.
MaidFrame 27 May, 2024 @ 5:59pm 
I keep getting item definition errors when booting up the server... Strange. What does this mean?
GamerMan360 8 Apr, 2024 @ 3:05pm 
How do I change stuff like the max players? Also I have an error that says "No map selected, game may not heartbeat" how do I select a map?
felix my beloved 27 Oct, 2023 @ 7:22pm 
for whatever reason steamcmd decided to store itself in /home/[user]/.local/share/Steam/steamcmd/ on po(o)pos.