Workload · Hosting a Left 4 Dead 2 server

Run your own Left 4 Dead 2 server, on a machine nobody else uses

To host Left 4 Dead 2 yourself, you install Valve's server (SteamCMD app 222860, no Steam account needed) on a 64-bit x86 Linux machine, give it a server.cfg, open UDP port 27015 and start srcds_run. Below is the whole evening's work in order, with the one setting that stops most groups from connecting, and a place to run it: one of our servers for game hosting.

The short version
  1. Free download: app 222860, anonymous SteamCMD login
  2. Our reading: it needs an x86 machine, so skip the ARM lines
  3. Set the lobby-only cvar to 0 so friends can type in your address
  4. Players need UDP 27015; keep the TCP side for your own RCON
  5. Restarting the service is how you pick up updates

Will a modest machine keep up?

Very likely. Valve doesn't publish a sizing table for this game. The closest thing is the Valve Developer Community (VDC) page on Source servers in general, which talks about 512 MB of memory as a minimum, 1 GB covering upwards of 60 player slots, and 4 GB or more on newer operating systems. Those are old, generic numbers, but on our reading they suggest memory is unlikely to be the limit.

Two things matter more. First, the processor type: SteamCMD is a 32-bit program that wants 32-bit libraries, which, on our reading, means an ordinary Intel or AMD (x86) server. Second, the connection: VDC says it's upload capacity a game server eats, and that the machine must accept connections nobody asked for in advance, which a home router or a CGNAT connection can prevent.

When nobody's playing, the server dozes: the sv_hibernate_when_empty setting is on by default and drops CPU use to almost nothing. That makes it cheap to keep a second or third copy on the same box, say one for coop and one for versus, each in its own folder on its own port.

The server that fits

Pick any x86 machine on our game server page, in the city closest to most of your players: Bucharest, Amsterdam, New York, Miami or San Francisco. You get the whole box, all of its cores, memory and disks, plus root, on a port no other customer shares at the access switch. That port is unmetered, 500 Mbps or 1 Gbps depending on the line, so a long weekend of campaigns never turns into a bandwidth bill.

  • Want to play tonight? Machines already in a rack go live in about 30 minutes once the order is approved; browse them on ready servers. Payment verification can add time.
  • Locked yourself out? Rack servers and blades include a remote console you can open in a browser. Most Moonshot cartridges have power control only.
  • No contract: one month is the default term.

Steer clear of all our ARM machines for this. This is our own conclusion rather than anything Valve states: the server's 32-bit libraries appear on VDC for x86-64 systems only, and we know of no ARM build of it. Separately, the X-Gene cartridge is limited to two old Ubuntu releases, 16.04 and 18.04.

Step one: libraries, a user and the firewall

Do this as root (or with sudo) on a fresh 64-bit Ubuntu. Turning the firewall on first means nothing is reachable before you want it to be. Swap 198.51.100.7 for your home IP, which is where you'll run remote admin from.

sudo apt-get update
sudo apt-get install -y lib32gcc-s1 lib32stdc++6 curl
sudo useradd -m -s /bin/bash l4d2

# IPv6 rules only get written if this is set before the allows
sudo sed -i 's/^IPV6=.*/IPV6=yes/' /etc/default/ufw
sudo ufw allow OpenSSH
sudo ufw --force enable
sudo ufw allow 27015/udp
sudo ufw allow from 198.51.100.7 to any port 27015 proto tcp
sudo ufw status verbose

lib32gcc-s1 is the package VDC names for a hand install of SteamCMD on Debian-family 64-bit systems, and lib32stdc++6 is its answer to the missing libstdc++ message. The separate l4d2 account follows VDC's warning never to run SteamCMD as root.

Step two: download the server

  1. Fetch SteamCMD into the service account's home: sudo -u l4d2 bash -c 'mkdir -p /home/l4d2/steamcmd && cd /home/l4d2/steamcmd && curl -sqL "https://client-update.steamstatic.com/installer/steamcmd_linux.tar.gz" | tar zxf -'
  2. Install the game server, choosing the folder before logging in, as Valve recommends: sudo -u l4d2 bash -c 'cd /home/l4d2/steamcmd && ./steamcmd.sh +force_install_dir /home/l4d2/server +login anonymous +app_update 222860 validate +quit'
  3. Check the number: VDC's list of dedicated servers gives 222860 for Left 4 Dead 2. 222840 belongs to the original game.

The first run updates SteamCMD itself before it downloads anything, so let it finish. validate compares every file with Steam's copy; it's worth it now, less so on routine updates.

Step three: make it joinable

Settings live in left4dead2/cfg/server.cfg under the install folder, and VDC says the server reads that file at start-up and again whenever the map changes. Open it as the service account with sudo -u l4d2 nano /home/l4d2/server/left4dead2/cfg/server.cfg and paste something like this:

hostname "Saturday Night Survivors"
rcon_password "pick-something-long-and-random"
sv_lan 0
sv_allow_lobby_connect_only 0
// only if you want a Steam group server:
// sv_steamgroup 1234567
// sv_steamgroup_exclusive 1

Then make it readable by that account alone: sudo chmod 600 /home/l4d2/server/left4dead2/cfg/server.cfg. What each line does:

  • hostname is the name your friends see in the server list.
  • rcon_password protects remote admin. Keep it in this file and nowhere else: put it on a command line and anyone logged in can read it from the process list, and your shell history keeps it.
  • sv_lan 0 makes it an internet server. At 1, VDC says, it sends no heartbeat, skips authentication and refuses addresses outside the local network.
  • sv_allow_lobby_connect_only set to 0 is the one people miss. Out of the box it's at 1, which lets players in only through a matchmaking lobby and blocks typing in your address.
  • sv_steamgroup ties the server to a Steam group by number; you'll see it on your group's admin profile page. Adding sv_steamgroup_exclusive at 1 keeps an empty server members-only.

Keep it running and up to date

Save this as /etc/systemd/system/l4d2.service. It starts the server at boot, relaunches it any time the process stops, and asks Steam for updates every time it starts.

[Unit]
Description=Left 4 Dead 2 server
Wants=network-online.target
After=network-online.target

[Service]
User=l4d2
WorkingDirectory=/home/l4d2/server
# updates can take a while; a failed one must not block the start
TimeoutStartSec=1800
ExecStartPre=-/home/l4d2/steamcmd/steamcmd.sh +force_install_dir /home/l4d2/server +login anonymous +app_update 222860 +quit
ExecStart=/home/l4d2/server/srcds_run -game left4dead2 -console -norestart -port 27015 +map c2m1_highway
Restart=always
RestartSec=15

[Install]
WantedBy=multi-user.target
  1. Turn it on: sudo systemctl daemon-reload first, after which sudo systemctl enable --now l4d2 starts it and keeps it on at boot.
  2. Watch it boot: journalctl -u l4d2 -f. It answers server-browser queries only once a map has loaded.
  3. Update later: sudo systemctl restart l4d2. The update step runs first. If it exits with an error, the leading - lets the game start on the files it already has; if it hangs instead, the start waits up to 30 minutes, the TimeoutStartSec limit.

About the launch line: -norestart leaves restarts to systemd's Restart=always, and +map c2m1_highway opens on The Highway, where Dark Carnival begins, in coop (the default mp_gamemode). For versus, VDC says the mode is switched with the map command: type map c2m1_highway versus at the server console or send it over RCON. Source's generic line also has +maxplayers, but VDC gives no figure for this game and says the game sets the ceiling, so it's left out here.

What your players' traffic needs

  • UDP 27015: the game itself, open to everyone. Change it with -port and change the firewall rule to match.
  • TCP 27015: remote admin. VDC's RCON protocol page says srcds listens for it on TCP and that it follows -port. Keep it limited to your own IP, as in step one.
  • UDP 27020: SourceTV, only if you turn it on (+tv_port moves it). Leave it closed otherwise.
  • UDP 26900: Steam traffic going out. ufw allows outgoing connections by default, so there's nothing to add.

Running a second server for versus? It needs its own install folder: run the SteamCMD line again with another force_install_dir, say /home/l4d2/server2. Give it its own server.cfg inside that folder and its own unit file pointing there with -port 27016. Then open ufw allow 27016/udp for players and ufw allow from 198.51.100.7 to any port 27016 proto tcp for its RCON.

When something goes wrong

  • Friends see the server but can't join by IP: make sure sv_allow_lobby_connect_only got set to 0, then restart.
  • The log says it can't find a running copy of Steam: VDC's answer is to link steamclient.so where the server looks for it. For this layout: sudo -u l4d2 bash -c 'mkdir -p /home/l4d2/.steam/sdk32 && ln -s /home/l4d2/steamcmd/linux32/steamclient.so /home/l4d2/.steam/sdk32/steamclient.so'.
  • A custom file went back to default after an update: that's validate. VDC warns that it restores any default file you edited; files you added are untouched.
  • Custom campaigns: this game's add-ons are VPK files, and the add-on notes for L4D2 on VDC describe them from the player's side. They don't document a Workshop routine for dedicated servers, so try any VPK on a spare instance first.

You manage the server; we keep the hardware and the network running. So copies are your job: keep copies of server.cfg and your add-ons off this machine, and treat that copy as private because it holds your RCON password. If you'd rather start from a different Source game, our Garry's Mod walkthrough uses the same tools, and Linux servers covers the operating systems on offer.

Questions people ask

Do I have to buy another copy of the game for the server?
No. VDC's dedicated server list marks app 222860 as downloadable with an anonymous SteamCMD login, so the machine never needs your Steam account or password. Your players still need the game on their own computers.
Why can my group only find the server through a lobby?
Out of the box, sv_allow_lobby_connect_only sits at 1, which VDC describes as players only joining from a matchmaking lobby. Set that cvar to 0 in server.cfg and restart, and anyone can connect with your address and port 27015.
Which port should I forward or open?
UDP 27015 for players. TCP 27015 carries the remote console, so open it only to the address you administer from. SourceTV's UDP 27020 needs opening only if you use it.
Can I switch between coop and versus?
Yes. mp_gamemode accepts coop, versus, survival, realism, holdout or scavenge, according to VDC, and you switch it with the map command, for instance map c2m1_highway versus. The sv_gametypes setting limits which of those the server will accept.
How do updates work?
With the unit above, each start runs SteamCMD's app_update 222860 first, so sudo systemctl restart l4d2 pulls any new build. Keep validate for repairs, since it puts changed default files back.

Give your group a server of its own

Choose the city closest to your group and get a whole x86 machine, with no contract.

Start your Left 4 Dead 2 server

Read next