Setting up a TF2 server

19 Aug

After the launch of the Mann vs. Machine game mode in TF2 (that I blogged about here) I decided to try and set up my on TF2 server in the hope of being able to play without having to wait in line with everyone else. I eventually got a server running and was able to play with a few of my friends, but it wasn’t an easy process as all the information to do it was either badly written, fragmented over multiple different websites or seemed to require a lot of prior knowledge.

After getting it to work I decided to write my own guide here for people who want to do the same thing but who, like me, had never really messed around with servers and IP’s and ports before. So detailed below are the steps I took to get a TF2 server running on Windows 7.

Be warned: What I describe here is what I did to get my server working, I make no guarantees and take no responsibility for things going wrong or breaking due to the steps given here. However feel free to comment or ask questions if you are unsure about anything and I’ll do my best to answer them or alter the guide accordingly.

1. Creating a Static IP

2. Port Forwarding

3. Getting the Server Software

4. Setting up a Config File & Running the Server

1. Creating a Static IP

The first thing you need to do is set up the computer you’ll be running the server from with a static IP. An IP will usually be generated randomly for something connected to your internet, and will look something like 192.168.0.X, where X is a number from 1 to 254. Each time your computer reconnects to the internet it will be given a new X, most of the time it may be the same X it had before, some times it will be different. Every device connected to your internet MUST have a different X. To run the server you need your computer set up so that its X never changes, and this is what a static IP is for.

To set up a static IP you’ll first need some numbers pertaining to your computers current IP situation. First thing to do is search for cmd in the Start Menu search bar. Once cmd is open you need to type ipconfig /all. In the big list of numbers you’re looking for 3 in particular; IPv4 Address, Subnet Mask and Default Gateway. You’ll want to write these down somewhere as you’ll need them later. Next you need to get some numbers from your router, to do this you should be able to view your routers status online by typing the Default Gateway into the address bar of your internet browser of choice. If you don’t know the username and password for your router you can look here or try ringing your internet service provider. Once you’re in you need to navigate around until you find all the info about your router and look for the Domain Name Server (DNS) values, there should be 2 of them. Write these down as well. So now you should have 5 numbers written down:

  1. IPv4 Address
  2. Subnet Mask
  3. Default Gateway
  4. Domain Name Server value 1
  5. Domain Name Server value 2

Back on your computer you now need to bring up Control Panel and look for View Network Status and Tasks. From here you need to go to Change Adapter Settings and right click on your internet connection and view its Properties, then click on Internet Protocol Version 4(TCP/IPv4) and then Properties. This is where you need the 5 numbers you have written down. You want to make sure Use the following IP address and Use the following DNS server addresses are checked. Now you have to put in the 5 numbers in the correct places HOWEVER the IP address should have the same form as the IPv4 Address and Default Gateway, but should differ from them in the last value. For example if your  Default Gateway is then your static IP address can be 192.168.0.X where X≠1 and X<254. Whatever you pick will be your static IP.

That should be it, if it turns out you can’t connect to the internet then it may be the DNS numbers, if the ones on the server info page don’t work then you should be able to get the vales from your internet service provider. If all else fails then you should be able to just go back to the Internet Protocol Version 4(TCP/IPv4) properties in Control Panel and change the setting back to Obtain DNS/IP address automatically.

Back to Top

2. Port Forwarding

Now that your computer has a static IP the next job is to make sure that signal to and from the server can get in and out of your router, to do this you use port forwarding. You need to go back to your router settings online and make sure the following ports are open:

  1. 27014 to 27050 TCP
  2. 3478 to 4380 UDP
  3. 27000 to 27030 UDP

If your router allows for TCP/UDP port rules then you could try and combine 1. and 3. as 27000 to 27050 TCP/UDP however I just put them in as separate rules. To check if these ports are open you can go here, however you may need to be running the server for them to show up as open.

There are so many different routers that I can’t really walk you through how to actually do the port forwarding, but I can direct you to a brilliant site called Port Forward that should be able to show you how to do it for your router. You can get the make and model of your router from the online router settings page that you should now be very familiar with.

Back to Top

3. Getting the Server Software

So now your computer should have a static IP and all the correct ports should be open so next up is getting the server software. To run a server you can us the Half-Life Dedicated Server Update Tool (HLDS Update Tool), and once you’ve downloaded the .exe you can run it. When it comes to picking the install location you want to set one up that’s permanent and NOT inside a current TF2/Valve directory, so stay away from the Steam folder in Programs. You could pick something like C:\TFServer or C:\Program Files\HLServer. Once it’s installed you need to open up cmd again from the Start Menu search bar and navigate to your installation directory using the cd command. So for the two examples I gave above you would type cd “C:\TFServer” or cd “C:\Program Files\HLServer” or whatever directory you chose. You then need to run the server updater to get all the most recent files, to do this type hldsupdatetool.exe -command update -game tf -dir .  into the cmd. The space then full stop at the end is part of the command, it tell the installer to install the files in the current directory. If you don’t want them in the current directory then you can pick another directory to put after the -dir. The download may take a while as the total size of all the files is over 5 GB, once it’s finished you’re ready to configure and run your server.

Back to Top

4. Setting up a Config File & Running the Server

A config file (.cfg) is a file that contains all the commands and setting for your server, here is an example one with some explanation of the commands

//Example TF2 config file//

hostname yourserverhostname //Server Name
sv_pure 0 //Control where the player gets content from: 0 Anywhere, 1 Anywhere from the white list, 2 Steam official content only
sv_lan 0 //What type of server: 0 Internet, 1 Lan
sv_region 3 //Server location: -1 World, 0 East cost of America, 1 West Coast of America, 2 South America, 3 Europe, 4 Asia, 5 Australia, 6 Middle East, 7 Africa
sv_password PlayerPasswordHere //Password that has to be provided by people trying to play on the server

//Rcon Settings//
rcon_password RCONpasswordhere //Password for rcon authentication
sv_rcon_banpenalty 1440 //Set how long to ban users who fail rcon authentication (in minutes)
sv_rcon_maxfailures 2 //Set the maximum number of times a user can fail rcon authentication before being banned

//Log Settings//
sv_log on //Enables server logging
sv_log_onefile 0 //Log the server info to only one file.
sv_logfile 1 //Log the server information in the log file.
sv_logbans 1 //Log the server bans in the server logs.
sv_logecho 1 //Echo the log information to the console.

//Rate Settings//
fps_max 600 //Maximum frame fate
sv_minrate 0 // Minimum bandwidth rate allowed on server
sv_maxrate 20000 //Maximum bandwidth rate allowed on server, 0 is unlimited
sv_minupdaterate 10 //Minimum updates per second allowed
sv_maxupdaterate 66 //Maximum updates per second allowed

//Download Settings//
sv_allowupload 1 //Allow people to upload their own customizations files
sv_allowdownload 1 //Allow people to download files
net_maxfilesize 15 //Set the maximum file size for uploading (in MB)

//Team Balancing//
mp_autoteambalance 1 //Switch on team balancing
mp_autoteambalance_delay 60 //Time after the teams become unbalanced to attempt to switch players
mp_autoteambalance_warning_delay 30 //Time after the teams become unbalanced to print a balance warning
mp_teams_unbalance_limit 1 //Teams are unbalanced when one team has this many more players than the other team

//Round and Game Times//
mp_enableroundwaittime 1 //Enable timers to wait between rounds. Do not set to 0!
mp_bonusroundtime 8 //Time after round win until round restarts
mp_restartround 0 //If non-zero, the current round will restart in the specified number of seconds
mp_stalemate_enable 1 //Enable sudden death
mp_stalemate_timelimit 300 //Timelimit (in seconds) of the stalemate round.
mp_timelimit 60 //Game time per map (in minutes)
mp_maxrounds 3 //Maximum number of rounds before a map change

//Client Rules//
mp_forcecamera 0 //Restricts spectator modes for dead players
mp_allowspectators 1 //Server allows spectator mode
mp_footsteps 1 //Footstep sounds
sv_timeout 900 //After this many seconds without a message from a client the player is dropped
mp_idlemaxtime 15 //Maximum time a player is allowed to be idle (in minutes)
mp_idledealmethod 1 //What to do with idle players: 1 send to spectator, 2 kick

sv_voiceenable 1 //Enable voice communications
sv_alltalk 0 //Players can hear all other players without team restrictions 0=off 1=on
mp_chattime 10 //Amount of time players can chat after the game is over

sv_cheats 0 //Toggles game cheats
sv_visiblemaxplayers 24 //The maximum number of players reported to clients
sv_consistency 1 //Whether the server enforces file consistency for critical files
sv_stats 1 //Collect CPU usage stats

You should save something like this as server.cfg and put it in C:\–Server location you chose–\orangebox\tf\cfg. To save it as a server.cfg you can paste the text into Notepad and save as a server.txt, then open up the folder you saved it to and press the Alt key. Then go to Tools , Folder OptionsView and make sure Hide extensions for known file types is unticked. This will then allow you to change the extension of server.txt to server.cfg.

There are 2 ways of running a server, either from the command line or from a GUI (graphical user interface). I much prefer the GUI way of doing things so I’ll explain how to do it the GUI way. You want to go the the folder C:\–Server location you chose–\orangebox\ and run srcds.exe, this will open up a window showing you some basic server settings

  • Game: Team Fortress 2
  • Server Name: Can be anything you want, but will be changed to the one you set in server.cfg in a moment
  • Map: Whatever map you want, can be changed in a minute along with setting up a map rotation
  • Network: Internet
  • Max. players: Any number you want, must be 32 for Mann vs. Machine
  • UDP Port: Should default to 27015, can be any number in the range of ports you opened in section 2
  • RCON password: Anything you want, will be changed to the one you set in server.cfg in a minute

Once you have the setting how you want just click Start Server. After a few second you should now have the full set of server controls and info about the server, it’s all pretty self explanatory. First things first you want to go to Console and check everything is working, you should see some info about whether the server set up properly. If everything seems fine then in the command line at the bottom type exec server.cfg, this should set all the server properties to the ones you set in server.cfg if they weren’t already, overwritting the setting you put in at the start of the GUI where appropriate.

You should now be able to join the server from TF2, for you it should appear in the LAN servers section and if you want your friends to connect they can either join the game you’re in or can press ` key in the main menu and type connect <server IP>:<port>, password <password> where server IP will be the Public IP displayed in the console of the server GUI, port will be the open port the server is using and password is the player password set in the main section of the server GUI.

Back to Top

You should now be the proud owner of your very own TF2 server. If anything is unclear don’t hesitate to comment and I’ll try and help. I wanted this to be a self contained guide (apart from the specific router info and port checking) so if you find any info else where that you think should be included just let me know.

Leave a comment

Posted by on August 19, 2012 in Blog


Tags: , , , , , , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: