How to set up a Team Fortress 2 online game server
Learn how to set up a Team Fortress 2 online game server professionally and securely.

How to set up a Team Fortress 2 online game server

In this article, we will teach you how to set up a Team Fortress 2 online game server. From choosing the right server and hardware to security settings and network optimization, all the steps are explained step by step. Join us to set up a stable and low-latency server for the TF2 Game.
0 Shares
0
0
0
0

 

How do I set up a stable, low-latency, and secure TF2 server?

In this guide, we cover everything from choosing a location and hardware to installing SteamCMD, configuring SRCDS, network optimization, security, and monitoring. This article is for Server administrators, Site administrators, Gamers and teams DevOps It is suitable for those who want to set up a TF2 server with high stability and responsiveness.

 

Choosing a server and location for TF2

To have Low ping And for a good gaming experience, the data center location should be close to the target players. Our company offers more than 85 global locations that you can choose based on the player population (Europe: Amsterdam, Frankfurt; America: New York, Los Angeles; Asia: Tokyo, Singapore; Brazil, etc.).

Recommended hardware specifications

  • CPU: 4 real cores with high frequency (single core speed is more important). Intel Xeon or AMD EPYC with high frequency are suitable.
  • RAM: At least 4–8 GB for a 24–32-player server.
  • Disk: NVMe to reduce map and Workshop loading times.
  • Network: Depending on the number of players and maps, 1 Gbps dedicated is recommended. For high crowds, use 10 Gbps.
  • Anti-DDoS: It is recommended to have an anti-DDoS server or protection service to repel UDP attacks.

Select service type

  • Gaming VPS: Suitable for small/medium servers with lower cost and optimized network.
  • Dedicated server: For servers with high traffic and strong CPU requirements.
  • High-performance cloud server: For scalability and distribution of locations.
  • Anti-DDoS server: This option is essential if your server is susceptible to attacks.

 

Prerequisites and Installing SteamCMD (Step 1)

To download and maintain SRCDS files from SteamCMD The steps below are based on Debian/Ubuntu-based distributions.

sudo apt update && sudo apt upgrade -y
sudo apt install -y lib32gcc-s1 ca-certificates tmux wget unzip

Create a dedicated user for the TF2 server and download SteamCMD:

sudo useradd -m -s /bin/bash tf2
sudo su - tf2
mkdir ~/steamcmd && cd ~/steamcmd
wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
tar -xvzf steamcmd_linux.tar.gz

 

Download and install TF2 server with SteamCMD

Example script for SteamCMD (save to update_tf2.txt):

login anonymous
force_install_dir /home/tf2/tf2_server
app_update 232250 validate
quit

Perform update/installation:

cd ~/steamcmd
./steamcmd.sh +runscript update_tf2.txt

After completion, the folder /home/tf2/tf2_server/ It will contain the SRCDS files.

 

Configuring SRCDS and server.cfg

Open the cfg folder (/home/tf2/tf2_server/tf/cfg) and one server.cfg Create or edit. Example of basic settings:

hostname "TF2 | Example Server"
rcon_password "StrongRconPasswordHere"
sv_password ""                // اگر می‌خواهید سرور خصوصی باشد، رمز بگذارید
sv_lan 0
sv_region 0                   // 0 = Automatic
sv_maxrate 200000
sv_minrate 80000
sv_maxupdaterate 66
sv_minupdaterate 10
sv_voiceenable 1
mp_timelimit 30
mp_maxrounds 0
tf_bot_quota 0
sv_logfile 1
sv_logbans 1
sv_logecho 1

Map rotation and custom cfg

To rotate maps, file mapcycle.txt Or use plugins for Sourcemod. For exec other files like autoexec.cfg From server.cfg Use:

  • exec banned_user.cfg
  • exec mapcycle.txt

 

Running the server (parameters and systemd)

Example SRCDS start command:

cd /home/tf2/tf2_server
./srcds_run -game tf -console -autoupdate -steam_dir /home/tf2/steamcmd -steamcmd_script /home/tf2/steamcmd/update_tf2.txt -port 27015 +map ctf_2fort +maxplayers 24 -tickrate 66

Create a systemd unit to manage the service (as root):

/etc/systemd/system/tf2.service
[Unit]
Description=Team Fortress 2 Server
After=network.target

[Service]
Type=simple
User=tf2
WorkingDirectory=/home/tf2/tf2_server
ExecStart=/home/tf2/tf2_server/srcds_run -game tf -console -autoupdate -steam_dir /home/tf2/steamcmd -steamcmd_script /home/tf2/steamcmd/update_tf2.txt -port 27015 +map ctf_2fort +maxplayers 24 -tickrate 66
Restart=on-failure
LimitNOFILE=100000

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable --now tf2.service
sudo journalctl -u tf2 -f

 

Ports and firewall

Common TF2 ports:

  • UDP 27015 (game)
  • TCP/UDP 27015 (Steam query/workshop)
  • UDP 27005 (Steam client traffic)
  • SourceTV: UDP 27020 (if enabled)

Sample rules ufw:

sudo ufw allow 27015/udp
sudo ufw allow 27015/tcp
sudo ufw allow 27005/udp
sudo ufw allow 27020/udp
sudo ufw enable

For nftables or iptables, open their equivalent. If the server is behind NAT, also forward ports on the router/hardware firewall.

 

System and network optimization for low ping

A few system settings that are commonly useful for game servers:

Recommended sysctl settings (for UDP and heavy network load)

sudo tee /etc/sysctl.d/99-tf2.conf <<EOF
net.core.rmem_max=26214400
net.core.wmem_max=26214400
net.core.netdev_max_backlog=5000
net.ipv4.udp_mem=65536 131072 262144
net.ipv4.udp_rmem_min=16384
net.ipv4.udp_wmem_min=16384
net.ipv4.tcp_mtu_probing=1
net.ipv4.tcp_fin_timeout=15
net.ipv4.tcp_tw_reuse=1
EOF
sudo sysctl --system

Disabling GSO/GRO/TSO on the network card

Disabling these features can reduce latency but increase CPU load:

sudo apt install ethtool -y
sudo ethtool -K eth0 gro off gso off tso off

Note: These settings increase CPU load; test on a dedicated server with a strong CPU.

CPU governor and IRQ affinity

To prevent frequency oscillation:

for i in /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor; do echo performance | sudo tee $i; done

If the network card has multiple queues, you can assign affinity IRQ events to specific cores to reduce latency (requires networking knowledge and review). /proc/interrupts has).

 

Plugins, Sourcemod and Metamod

For management and anti-cheat features:

  • Installation Metamod: Download the latest version and extract it in /home/tf2/tf2_server/tf.
  • Installation Sourcemod: Download and transfer files add-ons and cfg To folder tf.

Once installed, you can install add-ons to block cheats, manage players, display stats, and automate rules.

 

Security, RCON and Anti-DDoS

Important security tips:

  • RCON: Choose a strong rcon_password and restrict RCON access only from specified addresses. See example with iptables.
  • Using anti-DDoS service: Use a network-based anti-DDoS service to prevent UDP floods and amplification.
  • Logging and maintenance: Check logs regularly and roll log files (logrotate).
  • Regular update: Update SRCDS and the operating system with automated scripts.
sudo iptables -A INPUT -p tcp --dport 27015 -s 1.2.3.4 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 27015 -j DROP

 

Automatic updates and backups

Example of a simple update script:

#!/bin/bash
/home/tf2/steamcmd/steamcmd.sh +runscript /home/tf2/steamcmd/update_tf2.txt
systemctl restart tf2

Backup cfg, map and workshop folders:

tar -czf /backups/tf2_cfg_$(date +%F).tar.gz /home/tf2/tf2_server/tf/cfg /home/tf2/tf2_server/tf/maps

It is recommended to use cloud storage to keep backups and copies of important data.

 

Monitoring and troubleshooting

Basic tools for monitoring and troubleshooting:

  • top/htop for CPU and RAM monitoring
  • ss -u -a | grep 27015 To check for open UDP sockets
  • tail -f tf/logs/* to check for errors
  • mcrcon or RCON tool for sending remote commands

Troubleshooting Tips: Frame drops or lag are usually CPU or network related; if packet loss is observed, use tools like mtr Use to check the route.

 

Additional tips and best settings for specific applications

  • For small gaming servers (up to 24 people): VPS with 4 cores, 8GB RAM, NVMe is enough.
  • For competitions and high-traffic servers: Dedicated server with high frequency, 10Gbps uplink and anti-DDoS.
  • TF2 does not require a GPU server, but for streamers or peripherals that require a GPU, you can use a graphics server.
  • Location: Be sure to choose the data center closest to the players; use multiple locations and Smart DNS/Anycast for a multi-regional audience.

Important advice: Before implementing system changes in production, test first in a test environment and perform continuous monitoring after implementation.

 

Summary and service options

In this article, we covered the steps to setting up a Team Fortress 2 server, from installing SteamCMD to optimizing your network and security. For a server with low ping and high stability, you can use a gaming VPS or dedicated server; our company offers over 85 global locations, anti-DDoS servers, gaming VPS plans, and high-performance cloud servers.

 

Frequently Asked Questions

You May Also Like