Setting up a Team Fortress 2 Server on CentOS 7

Team Fortress 2

I used to have a Team Fortress 2 server on CentOS 6 with Virtual Box. Now that I’m using KVM/QEMU/Libvirt, I wanted to set up a new one. Also, Valve somewhat changed how they worked a few years ago and I wanted a clean slate. I started with a VM with 40GB. It’s not supposed to take that much, but I remember last time it took much more than the 10GB I’d given the VM and I don’t want to have to increase the disk size again.

The first thing I had to do was get the 32-bit libraries.

 # yum install ncompress libgcc.x86_64 libgcc.i686 glibc.i686 zlib.i686 ncurses-libs.i686

I added a user with

adduser gameserver

so that it wouldn’t run as root. I switched to that user. Then

mkdir hlserver && cd hlserver
for the directory to install from.

to get the files.

tar zxf steamcmd_linux.tar.gz

to untar it. The next step was to create a SteamCMD script. They say to call it it tf2_ds.txt and put this in there:

login anonymous
force_install_dir ./tf2
app_update 232250

After that we make the update script. It needs to have

./ +runscript tf2_ds.txt

Afterwards, make it executable with:

chmod +x

When you run it, it’ll grab the files needed for TF2. Something like 6GB at the moment. If you get “Success! App ‘232250’ fully installed.”, then you got it all. Yay!

Next create the server config:

cd ~/hlserver/tf2/tf/cfg && nano server.cfg

And here’s the minimum you need in there:

hostname "Your_Server's_Name"
rcon_password "Your_Rcon_Password"
sv_contact ""
mp_timelimit "30"

The Windows Server Setup page has a more fully-featured one you can copy and edit as you see fit. Finally create a little script so that you don’t need to remember the whole server command every time:

cd ~/hlserver/ && nano

And fill that with:

tf2/srcds_run -console -game tf -nohltv +sv_pure 1 +map ctf_2fort +maxplayers 24

The final thing is fixing the firewall.

do this:

firewall-cmd --zone=public --add-port=27015/tcp --permanent
firewall-cmd --zone=public --add-port=27015/udp --permanent
firewall-cmd --zone=public --add-port=27005/udp --permanent
firewall-cmd --zone=public --add-port=27020/udp --permanent
firewall-cmd --zone=public --add-port=26901/udp --permanent
firewall-cmd --reload

The Linux server page also tells you how to make a systemd service so that it restarts if it crashes or loses power.

So run and you can connect to it! Here I am connecting to my server:

Of course there’s a lot more configuration you can do to edit the motd and other things, but that’s the basics.

Author: Eric Mesa

To find out a little more about me, see About Me