# How to set up a private Team Fortress 2 server with Meshnet

## Introduction <a href="#introduction" id="introduction"></a>

Team Fortress 2 (TF2), an online multiplayer first-person shooter developed by Valve Corporation, remains a favorite among its active and loyal community members even after more than a decade. Creating your own dedicated TF2 server not only provides enhanced stability and control compared to external servers but also enriches your gaming experience with exclusive maps, game modes, and other features. Additionally, a dedicated server is an excellent opportunity to give new life to an old PC.

Nonetheless, managing a public server can lead to potential vulnerabilities in your home network. [Meshnet](https://nordvpn.com/features/meshnet/) offers an effective solution that removes the necessity of opening ports and revealing your IP address. With Meshnet, you can establish a secure virtual network that links devices from around the globe, simulating a [local area network](https://nordvpn.com/blog/what-is-lan/) (LAN) connection between remote participants.

This guide will show how to host a private TF2 game from within the game itself as well as how to set up a TF2 dedicated server on Linux and Windows systems, with instructions to connect using Meshnet.

## Launch a private TF2 game without a dedicated server <a href="#launch-a-private-tf2-game-without-a-dedicated-server" id="launch-a-private-tf2-game-without-a-dedicated-server"></a>

If you're looking for a quick and simple way to create a private game without setting up a dedicated server, you can do so directly from the game.

### Before you begin <a href="#before-you-begin" id="before-you-begin"></a>

To ensure that your devices can communicate with each other, [enable Meshnet](https://meshnet.nordvpn.com/~/changes/5hiVtBuK6qwLGxb0SjCm/getting-started/how-to-start-using-meshnet) on your host machine and any other devices that will connect to your game.

### Configure a private TF2 game session <a href="#configure-a-private-tf2-game-session" id="configure-a-private-tf2-game-session"></a>

1. Launch the TF2 game on your computer.
2. From the main menu, select **Find a game** > **Create server**.
3. Start a server with any random map. Once the server loads, open **Console** by pressing the **\~** (tilde) key.
4. Run the following commands, replacing `<meshnet_ip_address>` with your device's Meshnet IP address and `<map_name>` with the name of the map you want to use:<br>

   ```
   sv_lan 0
   ip <meshnet_ip_address>
   heartbeat
   map <map_name>
   ```

   \
   **Example**

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FrzpojzAUqjrEFFzInjPw%2Ftf2_console_commands.png?alt=media&#x26;token=4c6367be-840e-4d4c-85fe-6abf6e4c3c97" alt="Entering commands in the console."><figcaption></figcaption></figure></div>

After the server reloads with the specified map, other players can connect to your [private game](https://nordvpn.com/gaming/) using your device's Meshnet IP address. For further details, see the [Connect to the TF2 server](#connect-to-the-tf2-server) section below.

{% hint style="info" %}
**Note**

If you can't access **Console**, make sure it is enabled in the game's settings:

1. In the main menu, click the gear button at the bottom of the screen to open **Options**.
2. Under **Keyboard**, select **Advanced**, and then select **Enable developer console** and click **OK**.
   {% endhint %}

## Create a TF2 dedicated server on Windows and Linux <a href="#create-a-tf2-dedicated-server-on-windows-and-linux" id="create-a-tf2-dedicated-server-on-windows-and-linux"></a>

The TF2 server software is compatible with Windows and Linux, allowing you to create a private server on either system. This article covers the steps for both platforms.

### Before you begin <a href="#before-you-begin.1" id="before-you-begin.1"></a>

Ensure you have the following:

1. A computer with a stable internet connection running Linux or Windows.
2. At least 20GB of free storage space for the game files.
3. A minimum of 8GB of RAM or, preferably, 16GB for optimal performance.
4. Meshnet is enabled on both your server machine and any devices that will be connecting to it.

### Create a basic TF2 dedicated server with SteamCMD <a href="#create-a-basic-tf2-dedicated-server-with-steamcmd" id="create-a-basic-tf2-dedicated-server-with-steamcmd"></a>

The steps below outline how to install and configure the server software, create a configuration file, and launch the server with customized settings.

{% tabs %}
{% tab title="Windows" %}
{% hint style="info" %}
**Note**

This user guide is based on installing the server on Windows 11.
{% endhint %}

#### Download and install SteamCMD <a href="#download-and-install-steamcmd.1" id="download-and-install-steamcmd.1"></a>

To download and install SteamCMD, which is a command-line tool used to manage dedicated server files, follow these steps:

1. Create a new folder on your computer where you want to install SteamCMD. For example:\
   \
   `D:\tf2_server`<br>
2. Download the SteamCMD for Windows from the [Valve Developer Community website](https://developer.valvesoftware.com/wiki/SteamCMD#Windows). Look for the download link under the “Windows” section.
3. Extract the contents of the downloaded ZIP file to the folder you created.
4. Double-click the **steamcmd.exe** file to launch the application.
5. If the **Windows security alert** box appears, select both the *private* and *public* networks options and then click the **Allow access** button to allow incoming connections through the firewall.

The SteamCMD tool will automatically update and, upon completion, will be ready to accept commands.

<figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FsSRWJolsItz4xHYozQud%2Ftf2_win_steamcmd_up.png?alt=media&#x26;token=8181febb-63e0-4956-ba2a-84808364d908" alt="Using the SteamCMD command line tool."><figcaption></figcaption></figure>

#### Download and install the TF2 server <a href="#download-and-install-the-tf2-server.1" id="download-and-install-the-tf2-server.1"></a>

Now that you have SteamCMD installed, it's time to download and install the TF2 server files.

1. You can log in anonymously to SteamCMD to download TF2 dedicated server files by entering the following command:<br>

   ```bash
   login anonymous
   ```

   \
   **Example:**

   <figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FH0vG2EQZC3RlJ16YVrxq%2Ftf2_win_steamcmd_login.png?alt=media&#x26;token=f1a9ef09-a632-4aa4-b896-887327bf579e" alt="Logging in to SteamCMD anonymously."><figcaption></figcaption></figure>

   \
   To log in to SteamCMD with your Steam account, enter the following command and replace `<username>` and `<password>` with your Steam account credentials:<br>

   ```bash
   login <username> <password>
   ```

   &#x20;
2. Specify the installation directory for the TF2 server files by entering `force_install_dir` followed by the path to the installation folder of your choice. For example:<br>

   ```bash
   force_install_dir D:\tf2_server\tf2\
   ```

   &#x20;
3. Download and install the server files by entering this command:<br>

   ```bash
   app_update 232250
   ```

   \
   The download process may take several hours to complete because the dedicated server content is quite large. Once the "Success!" message appears, it means that the server files are fully downloaded and installed.<br>
4. Exit SteamCMD by entering the following command:<br>

   ```bash
   quit
   ```

#### Configure the server <a href="#configure-the-server.1" id="configure-the-server.1"></a>

After installing the server files, the next step is to configure the server settings.

1. Navigate to the `tf\cfg\` directory within the folder where you installed the TF2 server.

2. Create a new text file named `server.cfg` and open it with a text editor, such as Notepad.

3. Add the following lines to the file, replacing the placeholders with your desired settings, where:
   * `<your_server_name>` is your server display name.
   * `<time_in_minutes>` is the maximum time in minutes a map can be played before switching to the next map.<br>

     ```
     hostname "<your_server_name>"
     mp_timelimit "<time_in_minutes>"
     ```

     &#x20;

     **Example**

     <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FNmLkI6m9U9PYrHcaW0Ru%2Ftf2_win_cfg.png?alt=media&#x26;token=63b3a62b-e216-4f89-bc74-af2989f19487" alt="Example server configuration file."><figcaption></figcaption></figure></div>

4. Save and close the text editor.

The `server.cfg` file allows you to store custom settings for your server. To learn more about additional configuration parameters, visit the TF2 Wiki's [dedicated server configuration page](https://wiki.teamfortress.com/wiki/Dedicated_server_configuration#Example_Server.cfg_for_TF2_dedicated_server).

#### Launch the server <a href="#launch-the-server.1" id="launch-the-server.1"></a>

Now that your server is configured, you can start it by creating a batch file to simplify the process.

1. Create a new text file in the `tf2server` folder in the folder where you installed the server. You can name it `start_tf2.bat` or choose another name for the file.
2. Open the file with a text editor and add the following line:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">srcds.exe -console -game tf +sv_pure 1 +randommap +maxplayers 24
   </code></pre>

   \
   These lines contain key server settings that can be modified according to your preferences:

   * To set a specific map, replace `+randommap` with `+map` followed by the name of your preferred map. For example: `+map ctf_2fort`.
   * To limit the number of players who can connect to the server, adjust the `maxplayers` value.
   * To control custom content from clients, set `sv_pure` to the desired value. `1` restricts most custom content to ensure a consistent gaming experience.<br>
3. Save the file and exit the text editor.
4. To launch the server, double-click the **start\_tf2.bat** file you’ve just created.
5. If the **Windows security alert** box appears, select both the *private* and *public* networks options and then click the **Allow access** button to allow incoming connections through the firewall.<br>

   <figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FZ7tjwM2bEKQxACYwkQzo%2Ftf2_win_server_start.png?alt=media&#x26;token=03ab6464-ccec-4055-bc38-d86ee1e29231" alt="Activating the TF2 dedicated server."><figcaption></figcaption></figure>

Now, your TF2 server should start with the specified settings.

{% hint style="success" %}
**Tip**\
To stop the server, type `quit` or `exit` in the console window and press **Enter**.
{% endhint %}

To ensure your server runs smoothly, regularly update the server files.
{% endtab %}

{% tab title="Linux" %}
{% hint style="info" %}
**Note**

Package names and directories may vary slightly depending on the Linux distribution, but the process of setting up and configuring a dedicated server is generally similar.

This user guide is based on installing the server on Ubuntu 22.04.1 LTS.
{% endhint %}

#### Get started with SteamCMD <a href="#get-started-with-steamcmd" id="get-started-with-steamcmd"></a>

SteamCMD is a command-line version of the Steam client. It is used to download and manage the dedicated server files for TF2 and other popular PC games that use Steam for their multiplayer architecture.

If you have a 64-bit machine, you'll need to add support for 32-bit architecture and install specific libraries required by SteamCMD, as follows:

1. Open a terminal window.
2. Enter this command to add 32-bit architecture support:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo dpkg --add-architecture i386
   </code></pre>

   &#x20;
3. Update your system's package information by entering:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo apt update
   </code></pre>

   &#x20;
4. Install the required 32-bit libraries:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo apt install lib32z1 libncurses5:i386 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libtinfo5:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386
   </code></pre>

   &#x20;
5. Optionally, create a separate user account, such as `tf2server`, for installing and running game servers.<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">sudo adduser tf2server
   </code></pre>

   &#x20;
6. Set a password and provide the required user information when prompted.

#### Download and install SteamCMD <a href="#download-and-install-steamcmd" id="download-and-install-steamcmd"></a>

Now you can proceed with the installation of SteamCMD.

1. Create a new folder to store SteamCMD files. To do this, enter the `mkdir` command and specify the desired folder name. For example:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">mkdir steamcmd
   </code></pre>

   &#x20;
2. Change the current directory to this new folder by typing:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd steamcmd
   </code></pre>

   &#x20;
3. Download the SteamCMD archive by entering:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">wget https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz
   </code></pre>

   &#x20;
4. Use the `tar` command to extract the archive:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">tar zxf steamcmd_linux.tar.gz
   </code></pre>

#### Download and install the TF2 server <a href="#download-and-install-the-tf2-server" id="download-and-install-the-tf2-server"></a>

With SteamCMD installed, it's time to download the TF2 server files.

1. Run SteamCMD by entering:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">./steamcmd.sh
   </code></pre>

   &#x20;
2. You can log in anonymously to SteamCMD to download TF2 dedicated server files, as follows:<br>

   ```bash
   login anonymous
   ```

   \
   To log in to SteamCMD with your Steam account, enter the following command and replace `<username>` and `<password>` with your Steam account credentials:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">login &#x3C;username> &#x3C;password>
   </code></pre>

   &#x20;
3. Specify the installation directory for the TF2 server files by entering `force_install_dir` followed by the path to the installation folder of your choice. For example:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">force_install_dir ./tf2
   </code></pre>

   &#x20;
4. Download and install the server files by entering this command:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">app_update 232250 +quit
   </code></pre>

   \
   The download process may take several hours to complete because the dedicated server content is quite large. Once the download is finished, the output should be similar to the following:<br>

   <figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FX12PfKO31WvysxzvEVSn%2Ftf2_linux_dl_output.png?alt=media&#x26;token=498df5f8-b129-4db3-9905-a6bd2b8ce008" alt="Terminal output after downloading the server files."><figcaption></figcaption></figure>

{% hint style="info" %}
**Note**

If you encounter the error message "Error! App '232250' state is 0x202 after update job," it may be due to insufficient disk space available on your computer.
{% endhint %}

#### Configure the server <a href="#configure-the-server" id="configure-the-server"></a>

After installing the server files, the next step is to configure the server settings.

1. Use the command below to change the current working directory to `~/steamcmd/tf2/tf/cfg`.<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd ~/steamcmd/tf2/tf/cfg
   </code></pre>

   &#x20;

2. Create a configuration file named `server.cfg`, using a text editor like Nano, as shown:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nano server.cfg
   </code></pre>

   &#x20;

3. Add the following lines, replacing the placeholders with your desired settings, where:
   * `<your_server_name>` is your server display name.
   * `<time_in_minutes>` is the maximum time in minutes a map can be played before switching to the next map.<br>

     <pre data-overflow="wrap"><code>hostname "&#x3C;your_server_name>"
     mp_timelimit "&#x3C;time_in_minutes>"
     </code></pre>

     \
     **Example**

     <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FymNqXLT9W6bwGQML8k71%2Ftf2_linux_cfg.png?alt=media&#x26;token=fabb1ac8-2a58-46ef-bfe7-c516e1956494" alt="Example server configuration file."><figcaption></figcaption></figure></div>

4. Press **Ctrl** + **X**, followed by **Y**, and then press **Enter** to save the changes and exit Nano.

The `server.cfg` file allows you to store custom settings for your server. To learn more about additional configuration parameters, visit the TF2 Wiki's [dedicated server configuration page](https://wiki.teamfortress.com/wiki/Dedicated_server_configuration#Example_Server.cfg_for_TF2_dedicated_server).

{% hint style="success" %}
**Tip**

In the terminal, the tilde symbol (`~`) represents the current user's home directory.
{% endhint %}

#### Launch the server <a href="#launch-the-server" id="launch-the-server"></a>

Your server is now configured and ready to be launched.

For convenience, you can create a shell script to run the server. To do this:

1. Navigate to the `tf2` server directory by entering:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">cd ~/steamcmd/tf2
   </code></pre>

   &#x20;
2. Create a new shell script file called `tf2.sh`, using a text editor like Nano, as shown:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">nano tf2.sh
   </code></pre>

   &#x20;
3. In the text editor, add the following lines with the server launch command.<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">#!/bin/sh
   ./srcds_run -console -game tf +sv_pure 1 +randommap +maxplayers 24
   </code></pre>

   \
   These lines contain key server settings that can be modified according to your preferences:

   * To set a specific map, replace `+randommap` with `+map` followed by the name of your preferred map.
   * To limit the number of players who can connect to the server, adjust the `maxplayers` value.
   * To control custom content from clients, set `sv_pure` to the desired value. `1` restricts most custom content to ensure a consistent gaming experience.<br>
4. Press **Ctrl** + **X**, followed by **Y**, and then press **Enter** to save the changes and exit Nano.
5. Grant the `tf2.sh` file executable permissions by entering:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">chmod u+x tf2.sh
   </code></pre>

   &#x20;
6. Launch the server using the shell script, as shown:<br>

   <pre class="language-bash" data-overflow="wrap"><code class="lang-bash">./tf2.sh
   </code></pre>

Now, your TF2 server should start with the specified settings.

<figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FsRT2MGk9wQvKi21CE7BC%2Ftf2_linux_server_start.png?alt=media&#x26;token=3df051e9-4225-4bf1-b9e8-c058d6a5119d" alt="Activating the TF2 dedicated server."><figcaption></figcaption></figure>

{% hint style="success" %}
**Tip**

To stop the server, press **CTRL** + **C** in the terminal window.
{% endhint %}

To ensure your server runs smoothly, regularly update the server files.
{% endtab %}
{% endtabs %}

## Connect to the TF2 server <a href="#connect-to-the-tf2-server" id="connect-to-the-tf2-server"></a>

To connect to the newly created server, follow these steps:

1. Copy the Meshnet IP address of the server computer from the NordVPN app by clicking it.

2. Launch the TF2 game on your computer.

3. Open **Console** by pressing the **\~** (tilde) key and then typing the following command, replacing `<server_ip>` with the copied Meshnet IP address:<br>

   ```
   connect <server_ip>
   ```

   \
   **Example**

   <div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FibXHcSb8QzQRVX13qcGS%2Ftf2_connect.png?alt=media&#x26;token=297a1fb6-6b64-41a5-94d1-c8112dd06821" alt="Connecting to the TF2 server using Console."><figcaption></figcaption></figure></div>

4. Click **Submit**.

Once connected to your server, you and your Meshnet peers can enjoy playing Team Fortress 2 together.

<div align="left"><figure><img src="https://3559400189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F0cTezbT2vN0lurEio8Z5%2Fuploads%2FpF5YalOBV22bTXXURB3G%2Ftf2_connected.png?alt=media&#x26;token=07cb2d1c-8b60-4c3f-a786-43324301901e" alt="Playing TF2."><figcaption></figcaption></figure></div>
