Setting up a dedicated server for Left 4 Dead 2 (L4D2) is almost exactly the same as Left 4 Dead (L4D) which I covered a while ago.
I knew that L4D2 would take up more space and so I started out with a 15Gb virtual hard drive this time. After installing a minimal virtual machine, open-vm-tools and L4D2 I had 4.6Gb of free space. Hopefully that will remain enough!
First update Ubuntu Server:
sudo apt-get update
sudo apt-get upgrade
If you do not have wget installed then install it as follows:
sudo apt-get install wget
Create a new folder for downloading and installing L4D2:
Download the hldsupdatetool from Valve:
Make hldsupdatetool.bin executable:
chmod +x hldsupdatetool.bin
Run the hldsupdatetool:
Type yes to the agreement and then press enter to continue.
Now make Steam executable:
chmod +x steam
Run Steam to download the Left 4 Dead files:
./steam -command update -game left4dead2 -dir /home/username/hlds
Note: you will most likely be prompted to run the last command again as the first time it runs it will update steam and not install Left 4 Dead.
Left 4 Dead files will now install to /home/username/hlds/left4dead2/ – this may take some time, so you may want to make a cup of tea. Once Left 4 Dead 2 has installed we need to to create a server configuration file called server.cfg and a script to run the server.
Create files called server.cfg and autoexec.cfg in the following location /home/username/hlds/left4dead2/left4dead2/cfg:
A basic server.cfg should look something like this:
hostname "Left 4 Dead"
- You can change the hostname to whatever you want.
- The rcon_password is for remote administration of Left 4 Dead when the server is running.
- sv_allow_lobby_connect_only 0 allows for players to connect directly to your server without using the Left 4 Dead lobby system.
- sv_password sets a password for gamers to play on your server.
In autoexec.cfg we will set the default difficulty for the server to normal with the following line:
Note: z_difficulty normal can be changed to easy, hard, or impossible.
Next create a script in your /home/username/ directory to run the game server:
The script is as follows:
./srcds_run l4d -autoupdate -console -maxplayers 8 + sv_lan 0 +hostip
xx.xx.xx.xx +ip xx.xx.xx.xx +hostport 27015 +exec server.cfg +map
- -console: This will display a console that you can type commands into.
- -game left4dead2: This specifies that the server will run L4D2.
- -maxplayers 8: This will specify the maximum number of players the server will allow, setting it to 8 should allow you to use versus mode, otherwise set it to 4 for survivors only gameplay.
- -autoupdate: This will make the server check and update to the latest version when you launch it but this needs a manual fix to work properly.
- +hostip: where xx.xx.xx.xx is your internet address.
- +ip: where xx.xx.xx.xx is your Ubuntu server static IP address. .
- -port 27015: This will specify the port for the server to run on – 27015 is the default port.
- +sv_lan 0: This will force the server to run on the internet instead of just on a LAN.
- +map c1m1_hotel: This will specify the map that the server will start with (and must be configured). You will find all the available map names on your server here: /home/username/hlds/left4dead2/left4dead2/maps
Make your startl4d2server script executable:
chmod +x startl4d2server.sh
At this point you can run the server as follows:
To connect to the server from your (LAN) PC you will need to enable the “Developer Console” in the game options as follows:
At the main menu select Options then Keyboard/Mouse followed by the Allow Developers Console option.
You can then use the ~ key to bring up the console and then type:
Note: xx.xx.xx.xx is the LAN IP address of the server.
To allow internet users to connect you will need to open port 27015 directly to the server LAN address. Friends connecting from the internet will then be able to connect to the WAN ip address of your server using the password that you provided them.
Note: if your router supports it you may be able to dispense with +ip and +hostip in your startl4d2server.sh script.