Introduction: HLDS Counter Strike 1.6 [Linux]

About: Full time Mechanical Engineer

So you have been playing Counter Strike for a while and are thinking about setting up your own server.Then this is the tutorial for you.

Welcome to my second tutorial about setting up a Half Life Dedicated Server, HLDS for gaming. This tutorial will focus specifically on setting up a Counter Strike 1.6 server using Linux OS. This is going to be a long and tedious tutorial. There is a lot of setup that goes into a HLDS and then you have to add that to setting up a Linux server. That's right, in case you didn't read the title closely this tutorial will be using Linux to run the server. So if you are afraid of command lines now is a good time to head on over to my first HLDS tutorial that uses everyone's favorite OS, Windows XP Pro.
HLDS Counter Strike 1.6 [Windows]

Still here I see, guess command lines are not that scary after all. How about no graphical user interface... nothing, I see I can't scare you off so easily, guess you are here for the long haul.

Tutorial Goals:
Install Linux Server
Run Linux Server
Install HLDS
Run HLDS

The first part of this tutorial will focus on properly installing and setting up a Linux server. My distro of choice is Linux Ubuntu Server 10.10 but any server distro will work. You may be wondering why chose Linux over the more easier OS like Windows XP Pro. There are two major reasons besides the cost factor; Linux offers greater customization and Linux uses less system resources. Even though the initial set up is hard and maintenance could be a pain I hope that I will be able to show you some tools that makes Linux much easier to run then a windows server could ever hope to be.

The second part will focus on installing HLDS. HLDS is software that is freely distributed by Valve, the creator of Counter Strike 1.6. This software will allow us to run a Counter Strike server or any other type of game server that Valve makes. This includes; Day of Defeat, Counter Strike Source, Day of Defeat Source, Team Fortress 2, and Left 4 Dead 1/2. This list is by no means all that a HLDS will run, I have left out a few Valve games that I have never played and do not see a large player base but you can still install them. Aside from Valve games you can also install a few non-Valve game servers. Killing Floor is one example that uses the HLDS tool to install and run a game server. I don't know the complete list so you will have to Google the exact game you wish to install for the HLDS installer tool command.

Note:
I am not a Linux exert or advanced user. All that I write about in this tutorial regarding Linux has been extracted from MANY Google searches and other Linux server tutorials. If you are a Linux expert please share your knowledge if I make a mistake. If will be greatly appreciated by all.

Now let us begin...

Step 1: Obtian Copy of Linux Server

The distro of choice for me is Ubuntu Server Edition. I have found that being one of the most popular Liux distros, Ubuntu has great community support. Therefor if you ever have an issue most likely a quick Google search will help in solving your problem. Ubuntu also updates on a very strict schedule with a release schedule of every six months and constant automatic updates for up to five years. All of this is of course free so that makes Ubuntu a very good choice.

Now you need to obtain the latest copy of Ubuntu Server. At the time of this tutorial Ubuntu Server 10.10 is the latest edition. You can obtain a copy through a few ways:
Downloading is the fastest and is strongly recommended.

To download follow the links. When you get to the download page chose the version of Ubuntu Server you want and also the edition. You are downloading this for your server so make sure you know if the server you have is 32 or 64 bit. Then hit the button and you should be set. The file is about 700Mb in size so you will have some wait time.

Now that you have a copy downloaded you need to burn the ISO image to a CD. If you have Windows 7 just right click on the downloaded file and chose Burn Disk Image. Any other version of Windows you will need to download third-party software to burn the image. I would suggest using InfraRecorder.

Make sure to burn the ISO at the slowest speed settings allowed. This will help prevent errors on the disk which will make you have to burn it all over again. Also verifying the files after burning is a good ideal to help prevent errors that will make installation a headache.

Step 2: Install Ubuntu Server Edition

Now you are ready to install Ubuntu Server Edition on the desktop you want to turn into a server. Along with an unused desktop to install the OS on you will need the following; monitor, keyboard, usable CD-ROM Drive installed. Now just pop the disk into the CD-ROM drive, turn the computer on and let the install screen load up.

  1. Before proceeding with installing the server it is always a good ideal to test the newly burn CD for defects. Select Check disc for defects using the arrow keys and then hit enter. This will take a  while but will save many headaches in case there are bad files written to the disk. When it is complete and there are no errors proceed on. If it found errors remove the disk and burn a new one. Try to adjust the burning speed so that it is slower.

  2. Now Select Install Ubuntu Server. The next few screens will ask you what language you use, your region, and keyboard layout. Set these accordingly. A tip on the keyboard set up, don't use the auto detect feature. Just pick yours from the list, saves a lot of time and unnecessary prompts.

  3. The next prompt will ask for a host name for the server. I like to use a nickname of mine and in this case used my gaming name, Leumas. Just make sure there are no other machines with the same name on your network.

  4. When you get to the Partition Disks Prompt chose to use entire disk. Ok to the next few prompt as Ubuntu will automatically detect what to input. After imputing the partition information the HDD will be set up for use by the system. This may take a while so have a break and come back in a few minutes.

  5. The next set up prompts will set up the main user. Make sure whatever you enter you remember/write down. Passwords should be extremely strong and hard to guess. Being a server you will have network ports open, we will get to this later, that anyone with a internet connection will be able to detect and gain access to your system. With fast computers today potential hackers could easily gain access to a  system with a weak password using brute force. This would be bad, very. So strong passwords are a must and never use this password for anything else to do with this server, such as the game serves admin password. The last prompt will ask if you wish to encrypt the home directory. This is handy if you have personal files you plan to be storing using this account. Otherwise it is unnecessary.

  6. The next prompt will ask for a HTTP proxy. If you don't know what this is you most likely don't have one so leave this blank.

  7. Setting up automatic updates is a personal preference, go with what ever you feel like.

  8. For the software selection don't select anything, we can do this later with the exact packages we need.

  9. If this is the only OS you have on this server, it should be, then install the GRUB boot loader.

  10. Almost done, one more prompt. Remove the CD-ROM and continue. Your server is done and starting up for the first time. You should eventually get a log in screen. The log in information is exactly what you set before so enter it to check out your new server. Neat huh? Very...black.

Step 3: Server Preperation

Now it's time to familiarize ourself with issuing commands to the server. Make sure you are logged in to the account you created when you installed the server. Starting in this step and continuing through a large majority of this Instructable there will be a lot of commands to input into the server. I will try to differentiate the best i can commands from text to avoid confusion:
This is a command to be put into the server console
Also be sure to pay attention to what is happening on your servers screen. There are many commands I will issue that require validation such as typing y to continue. I will not indicate this in the Instructable.
_______________________________________________________________________
First lets make sure your internet connection is set up properly and the server can communicate with the outside world. Using the server command prompt type the following:

ping -c 4 google.com

After hitting enter you should receive text describing the ping test. What the test displays is not important, we are just making sure that the server can contact the outside world. It will alert you if the test fails. If the test fails check the cables and router. If the problem still persists the network configuration was not set up properly and we will need to do this. You will have to skip this step and move ahead to the next one on Network Setup. Come back when you are done. If the test was successful continue on.
_______________________________________________________________________
Now we will install updates, this is important as it will fix any issues that Ubuntu Server my have with your system. Enter the following  code:

sudo apt-get update

Like me you may be asked to enter a sudo password. The sudo password is the same password you use to log in, enter it and the command will continue. You could potential download a large amount of files, this may take some time.
Now we need to install the updates, this is easily done by issuing the command:

sudo apt-get upgrade

When this is done the server prep is finished.

Step 4: Network Setup

Here I am going to assume you have some basic knowledge of how your home network is configured. First you will need to make sure that the router you plan on using for your server is attached to the server. Linux when installed will gather this information and set up your connection automatically as a dynamic IP address. We want a static IP address so that we always know the path from the router to the server.

In a Windows machine connected to the same router as the server go to the start menu, in run or search type cmd this will bring up the Microsoft command prompt. In the command prompt type:

ipconfig /all

We need the following information about our local area connection:
  • Subnet Mask
  • Default Gateway
  • IPv4 Address
This will help us in setting up our static address for the server. In the same Windows machine test your ability to configure your router. You will have to use the user manual to find out how to connect to your router and enter its configuration client. Most of the time you just open up any browser in a machine connected to the router and then type in the Gateway address of the router: 192.168.1.1 in my case. The passwords should be something similar to admin or just password. A Google search or the operation manual will yield this information. In the router configuration client determine the IP address range that your router will automatically assign to machines connected.

Now using your server we will setup a static IP address. Type the following command:

sudo nano /etc/network/interfaces

In to following screen we will want to edit the network adapter you will be using. If you only have one adapter installed it will be named eth0. If you are not using the primary network adapter you will have to determine its name.
Now enter the following information.

iface eth0 inet static
address ###.###.#.##
netmask ###.###.###.#
gateway ###.###.#.#


The pound signs are replaced by the information we determined earlier with one exception, the address. You will want to chose an address that the router will not assign or is less likely to assign to other machines in your network. In my example I used 192.168.1.51

After entering the proper information press ctrl x , choose yes and then hit enter. Now reboot your server and then test the internet connection again by pinging Google.

Step 5: Installing Webmin

Now we have the server almost ready. Most users will find that keeping the keyboard and monitor attached to their server to be a hassle. Lets fix this and allow us to connect to the server remotely from anywhere.

We will be installing Webmin a free tool to help users easily administer a Linux server. Type in the following commands separately and follow any screen prompts for each command.

sudo apt-get install apache2 vsftpd bind9 libnet-ssleay-perl
sudo apt-get install libauthen-pam-perl libpam-runtime rssh libio-pty-perl
sudo apt-get install monit fail2ban libapt-pkg-perl ethtool exim4
mkdir/options
cd options
wget http://prdownloads.sourceforge.net/webadmin/webmin_1.520_all.deb

sudo dpkg -i webmin_1.520_all.deb

After running the last command you may get an error message telling you that you are missing a package. Just install whatever pacakge you are missing. I was missing apt-show-versions so I used the command suggested by the error message to install it:

sudo apt-get install apt-show-versions

After istalling the package the server will continue with the sudo dpkg -i webmin_1.520_all.deb command.

Now logout of the server by typing logout or exit. If you feel confident you can detach the monitor and keyboard. Make sure that your system will not report an error when booting up if there is no keyboard attached, this can be achieved by editing the BIOS.

Now we will log into Webmin. This is an amazing tool that will allow you to control your server from any computer anywhere with a internet browser. First you will need a machince capable of contacting the internet and posessing an internet browser. Your gaming machine should do well. Open your favorite browser and enter the following into your address bar:

https://###.###.#.##:10000

The pound symbols are your servers IP address. This is the internal IP address, I am assuming you are connecting to the server using a machine that is connected to the same router as your server. The IP address is the dynamic address that was setup in the previous step, 192.168.1.51 for me.

You will get a log in screen if everything is configured properly. The user name and password is the same log in information used to log in to your server. Logging in will bring you to the system information summary screen.

Webmin runs modules that help in controlling your server. The first thing we will do before finally installing the game server components is to update the SSH module to SSH2, this will make the module more secure when connecting remotely over the internet.

  1. On the left is a set of links, expand the link labeled Webmin. Now chose Webmin Configuration
  2. Click on Webmin Modules
  3. Using the tabs one top navigate to the delete tab. In the delete modules list find SSH LoginNOTSSH Server! Click Delete Selected
  4. Put a check in box labeled Remove from users and reset control settings the chose delete.
  5. You should receive a screen about the module being successfully removed.
  6. Returning to Webmin Configuration and Webmin Modules chose the Install tab.
  7. Chose the from ftp or http URL option.
  8. Put following link into the box: http://www.webmin.com/download/modules/ssh2.wbm.gz
  9. Click install. When done you should be notified that it was a success.
  10. Now using the links from the left again expand Others and find the SSH2 Login link.
  11. The remote command terminal will begin.
  12. Hitting enter will enable you to log in using your server user name and password.
This module will allow us to send commands to the server remotely making this plug in very important.From now on any commands I ask you to enter will be enter through this module. You should also know of another important feature of Webmin that is in the Other links, the FTP server. This will allow us to easily install custom maps and features when the game server is set up.

Now without further delay we install the game server.

Step 6: Install HLDS

First we will create a directory to install the game server to:

mkdir cstrike

You can name it as you like just be sure it is something descriptive and that you will remember. Now navigate into the directory:

cd cstrike

Obtain the HLDS update tool:

wget http://storefront.steampowered.com/download/hldsupdatetool.bin

Now we need to give it permission to run:

chmod +x hldsupdatetool.bin

Now to run the program:

./hldsupdatetool.bin
yes
./steam

You may need to run the previous command a few times until the update tool is completely updated. You will know the program is completely update when after issue the ,/steam command you are given a list of possible commands.

Now to install counter strike game files.

./steam -command update -game cstrike -dir .

Don't forget the period at the end of -dir This command will take a while to complete and install all necessary components for your server. Once the command completes it is time to start the server.

Step 7: Start HLDS


Use the following command to start the server:

./hlds_run -game cstrike

This will start the basic server. You can test to make sure everything is operational by joining your server, it will be under the LAN tab in the in-game server browser.

Now we just need to configure the server and adjust the router before the server will be completely done.

Step 8: Port Forwarding


This next step is extremely important. If you experience any problems connecting to your game server revisit this step as the first part of your troubleshooting.

In order to allow external users to connect to your game server we need to setup port forwarding on you router. The router is the device that you use to connect to the internet and will link all you computers together. It should be directly connected to your server. Since all of you use different routers from different manufacturers I will have to refer you to a website that specializes in setting up port forwarding.

Counter Strike requires the following ports to be forwarded in order to allow players to connect:
 1200 UDP, 27000 - 27015 UDP, 27020 - 27039 TCP
Now remembering this information follow the steps below to properly forward your ports.
  1. Go to: http://portforward.com
    This site is free to use, you will just need to navigate through the advertisements.
  2. Find you router manufacturer and model number. This should be easily found by looking on the back or bottom of your router.
  3. Skip any advertisements.
  4. Choose the program you wish to port forward. In this case it is Counter Strike
  5. Follow the instructions. 
Can't find your router or it is not able to forward enough ports for the game?

Google it! Port Forwarding MANUFACTURER MODEL# router


Step 9: Edit Server Properties


Now lets edit your server properties so that you can change the servers name and CVARs.

  1. Using Webmin connect to your server
  2. Expand Other and find the File Manager link.
  3. Now that you are in File Manager we need to navigate to the directory that your server is stored in:
    home -> {username} -> {cstrike} ->cstrike
    Replace {username} with the name you use to log in and {cstrike} with the name you installed the game server into.
  4. Find the file labeled server.cfg
  5. Using the links at the top of the File Manager find the one labeled Edit and open the file with this option.
  6. You will want to change the CVAR labeled hostname to the name of your server.
  7. There  are more CVARs then those included in this file. Most of them you will not need to change but if you wish to a server.cfg file is included as a down loadable file. Just replace your server.cfg with this one.
Here is another way to edit your server.cfg:
http://server.counter-strike.net/configs.htm

Step 10: Final Startup

Now that everything is setup for a basic Counter Strike server lets start the server up again. You can continue to type the long form to start the server or you can set up a easier command to start the server.


  1. Using Webmin and the SSH2 login enter your server's terminal.

  2. Enter you server directory:
    cd cstrike
    Replace cstike with the name of your directory

  3. Now lets create a file called start:
    nano start

  4. Just like we did when we first started the server we will enter the startup command into this file:
    screen -S cstrike ./hlds_run -game cstrike -secure +maxplayers 16 +map cs_assault -autoupdate
    The ip, maxplayers, and map commands can be changed to your desire.

  5. Now to exit the text editor and save the file as start. Press ctrl+x on your keyboard, yes to save and then enter to save under the name start.

  6. All that is left is to give the file permission to run just like we had to do with hldsupdatetool.bin:
    chmod +x start


Now to start your server you will have to make sure you are in the servers directory, cstrike. Then you just issue the following command:
./start

If you noticed we have used a program called Screen, this will allow us to run the server in the background without it writing anything on our screen. We can detach from the running server by pressing ctrl+a+d. If you wish to see the screen again you just type screen -r

Congratulations you should now have a Counter Strike game server running properly.