Team Fortress 2

Team Fortress 2

30 ratings
Creating a private, non-LAN server with bots in Team Fortress 2
By Maziecat
These are the steps I used to get a private (read: password-ed), non-LAN server running for Team Fortress 2. My server has bots and humans alike, and I think that's too neat to keep to myself.
   
Award
Favorite
Favorited
Unfavorite
Set up port forwarding and firewall rule(s)
TL;DR: Set up an inbound firewall rule for TF2 (something something "\steamapps\common\Team Fortress 2\hl2.exe", UDP, port 27015).

  • TCP: 27015, 27036
  • UDP: 27015, 27020, 27031 - 27036

Source[portforward.com]

More information on the ports can be found here.

As for port forwarding, that will depend on what router you're using. For less technical folks, here's what I feel qualified to fill in:
  • Technically, it doesn't matter which port you use for your computer's firewall rule(s), so long as you set up the port forwarding to map from whatever port you used in the rule to one of the default ports listed above.
  • If memory serves, you will want to set a static IP address for the machine you created the firewall rule(s) so that the port forwarding you set up always forwards to the correct device. I did this ages ago and no longer remember how I did, but I know I did it for HKMP, so this guide[geroyuni.notion.site] may help.
Create and start the server
You will be using console commands for this. If you haven't already, enable the developer console (found in advanced keyboard settings, because of reasons). If you don't know what console commands are, search "Source engine console commands".

The console supports tab completion, so (e.g.) if you don't know how to spell a map, start typing something and then hit <Tab> to see if the console knows what you're on about.

  1. Run the following commands, replacing anything in angle brackets with your desired values:
    sv_lan 0 hostname "<server name>" sv_password <password>
    These will make a non-LAN server with your chosen name and password.
  2. (Optional) Set the maximum total number of players with
    maxplayers <count>
  3. Choose the map:
    map <map name>
  4. (Optional) Add bots:
    tf_bot_difficulty <number> tf_bot_add <count>
    • Bot difficulty ranges from 0 (easy) to 3 (expert), and defaults to 1 (normal).
    • You should add bots before you ask a friend to join your server, if you want them to be able to join your team right away.
    • More information about which how to add bots, which maps support bots, and other helpful commands can be found here; in particular, the "tf_bot_add" command has a lot more parameters than I've shown here.
Ask your friends to connect to your server
The short(est?) version of this step, assuming you set up everything with the default port(s), is to have your friend(s) enable the developer console and run
connect <your public IP address>
You can find your public IP address by literally asking Google, or using ipconfig or ifconfig if you're fancy.

If you set up port forwarding to non-standard external ports (i.e. the port you told your router to use; again, the port your computer uses doesn't really matter), then you might just be able to staple ":<port number>" to the end of your IP address in the "connect" command, but I haven't tested this and so can't guarantee anything.

I'm also not sure how the "connect" command reacts to a server with a password. So there's that.

But if you want to get really fancy...

Help your friend add your server to their favorites
  1. Have them open Team Fortress 2's server browser and navigate to the "Favorites" tab.
  2. Once there, they should hit whatever looks like it'll let them add a server by IP address, then they should enter your public IP address into whatever pops up and save it.
  3. They should then be able to select the server and hit "Connect" or "OK" or something. If you set a password, it should prompt them for it. They may need to refresh the server list before this works.
Questions/comments
This is my first guide. I haven't fully fleshed out this process, either with testing or screenshots. Any additional information, context, media, links, etc. are welcome.
7 Comments
Maziecat  [author] May 2, 2024 @ 1:35pm 
Also, anyone who wants to copy my guide and make their own, more actively maintained version of it should feel free to do so. Just don't be, like, weird or shitty and we won't have any issues.
Maziecat  [author] May 2, 2024 @ 1:34pm 
Glad people are benefiting from this!

It's been a minute since I've used my own guide - notice how the TF2 path is for the pre-64 bit executable - but I remember things being a bit weird when trying to get my friends to join up on a specific team. Possibly because of team balance requirements?

I also remember my server/IP disappearing from their server browser. I think that's unavoidable for any server that goes offline. That server browser is archaic. So make sure your friends save your IP in a text document or something.
Who? May 2, 2024 @ 6:22am 
thanks
2141 Apr 28, 2024 @ 5:43am 
круто
Threepio Apr 27, 2024 @ 8:36am 
wow! cool!
Chapéu Poligonal Apr 27, 2024 @ 6:19am 
i surely will test! Nice guide!
Edmond Apr 25, 2024 @ 9:02pm 
This is a good guide! I had to make a similar one for CS:S a while ago and I'd say this one's better. I really hope they allow hosting via steam like they did with the GoldSrc engine games, manual hosting is such a pain. Anyways here's how you set your IP-address manually instead of letting it do it automatically:

Go to Control panel > Network and Internet > Network and Sharing Centre > Change adapter settings

Right click your ethernet and/or Wifi connection, click properties

Select "Internet Protocol Version 4 (TCP/IPv4)", click properties

Set your ip-address in here. If you don't know what to set, run "ipconfig" in a command prompt and copy what you see there. Your DNS should be the same as your default gateway