The instructions are designed for Ubuntu 14.04 32 bit, but should work on all versions of Ubuntu. This tutorial will teach you how to make a Garry's Mod game server.
Log in via the terminal as root.
Firstly, we need to make sure the firewall is secure to reduce the chances of a security issue. Assuming this server will be dedicated to Garryâs Mod, itâs safe to block absolutely all incoming ports (including ICMP) besides the ones required for Garry's Mod. ICMP is not required for the operation of the server, and blocking it completely will not have any negative effects on Garry's Mod, however, it will help reduce the attack vectors of a DDoS attack.
To block all non-required ports, the following commands are required:
iptables -A INPUT -p icmp --icmp-type echo-request -j DROP iptables -A OUTPUT -p icmp --icmp-type echo-reply -j DROP
This basically tells the firewall to ignore every ICMP packet it receives, and take absolutely no action on it. This also means if someone tries to ping your server, they will get no response.
The second line tells the firewall to block all outgoing ICMP packets, this is much less important, but just double ensures there wonât be any ICMP communication happening.
Next, we need to specifically allow all the ports required for Garryâs Mod (27005 - 27015 inclusive) with these commands:
iptables -I INPUT -p tcp --dport 27005:27015 -j ACCEPT iptables -I INPUT -p udp --dport 27005:27015 -j ACCEPT
This says anything on the ports between 27005 and 27015 is allowed. The first command is for TCP, and the second is for UDP. The second command (UDP) is the most important here as almost all communication between the server and the players is done with UDP. Some people have reported problems with TCP blocked, so for that reason we should allow it.
Now we want to tell the firewall to allow connections which weâve opened ourself (or the software on the server has). This means if we contact a server, weâll be able to see a response. Type this command to allow it:
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
If you will be using SSH to control your server (rather than using the console in your account), this command is required to allow SSH to work on the standard port. If you arenât using SSH, donât run this:
iptables -I INPUT -p tcp --dport 22 -j ACCEPT
And finally, the last command for setting up the firewall. This command will block all incoming connections besides the ones weâve allowed:
iptables -A INPUT -j REJECT
These settings are only applied until we restart our server, which means weâd have to manually reconfigure it every time the computer reboots. This isnât acceptable, so thereâs a package to install which saves the firewall rules to a file, and then loads it every time the server starts up. To install this package, type the following:
apt-get install iptables-persistent
Follow the instructions on screen. When asked if you would like to save the current firewall rules, press yes.
Now our firewall is set up, and no more configuration should ever be required in regards to the firewall.
If you are using SSH, thereâs a package which you should install which will automatically block peopleâs connection to the server if they keep trying the wrong SSH password. This is very useful to prevent your SSH password being brute forcedâ. To install the package, use the following command:
apt-get install fail2ban
Fail2ban is already configured to block peopleâs access after just a few failed password attempts, so we donât need to configure it. Now your server is significantly more secure than it was when we started.
Next, we need to install "screen". This basically allows you to run commands continuously, even if you logout from the server. This is vital to keep your Garryâs Mod server running continuously for long periods of time especially when you are controlling the server with SSH. To install "screen", type the following:
apt-get install screen
After the install is complete, run this command:
A disclaimer will show on screen, just press enter to continue. Typing
screen into console starts screen and allows you to work inside of a virtual console, if you disconnect from SSH, or logout, this virtual console will continue to run with your command in side of it (Garryâs Mod server runs as a Linux command, so this is where we need to use screen).
Now, before installing Steam, Garryâs Mod, and the required files, we need an account dedicated to it. I suggest calling it
steam. To make a new account, type the following:
You need to use a different password than your root password to keep everything secure. You will very rarely use this password. You will be asked some questions about the account, such as itâs full name, phone number, etc. Leave all of these blank.
Now we want to be logged into the "steam" account while we download all of the required files. This means that "steam" gets all of the ownership to these files, and the Linux permissions are set correctly without any configuration. It is much more difficult to get the permissions right if you install Steam as root, then attempt to change those permissions. To log in as steam, type the following:
We need a directory (folder) to save the Steam software. To make the directory, use this command:
Now, we want to be inside of that directory. To make it your current working directory, type the following:
We now need to download the Steam software by typing:
Now we need to decompress and install it, with the following:
tar -xvzf steamcmd_linux.tar.gz
If you're using a 64-bit OS, you'll need to install 32-bit libraries to run Steam.
apt-get install lib32stdc++6 apt-get install lib32gcc1
Run the following command to open Steam, tell it to log in as "anonymous" (a Steam account that anyone can use to download free software from their servers), and tell it to install the Garryâs Mod server into the gmodds folder (stored in the Steam accountâs home directory).
./steamcmd.sh +login anonymous +force_install_dir ../gmodds +app_update 4020 validate +quit
We can expect that command to last a long time, but we get to watch the progress of it. It is possible for this command to fail, the Steam servers quite often have minor difficulties which cause a download to fail (or not start at all). If this happens, simply start it again.
Once this command is complete, we will have a working copy of the Garryâs Mod server, however, most Garryâs Mod content requires CounterStrike: Source (CS:S for short) to be installed. To install CS:S, run the following command:
./steamcmd.sh +login anonymous +force_install_dir ../cssds +app_update 232330 validate +quit
This command will also take a while.
Once Garryâs Mod and CounterStrike are installed, they need to be linked together using a configuration file. To do so, we need to edit the following file with this command:
On the line containing "cstrike" we need to remove the two slashes (//) at the start of the line, then replace the entire path part of the line (starts with
C:/). That part of the line needs to be replaced with:
The entire line should now look like this:
There should be a tab space at the start before the word cstrike and the line should not contain a double slash (//) anywhere. Once done, you can save this file with Ctrl+X and then Y. This tells Garryâs Mod where to find CounterStrike so it can be used.
Now we have a basic Garry's Mod server installed. To run it, ensure we are in the correct directory with this command:
Then run the following command:
./srcds_run -game garrysmod +gamemode terrortown +maxplayers 16 +map cs_office
Once it has started up, you should be able to join by typing the following into the Garryâs Mod Console (NOT the server terminal):
IP_ADDRESS with the IP address of the server. If you donât know your IP address, typing the following into the server terminal will tell you what it is:
url -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
If you want to change the number of players allowed on your server, stop the server by doing Ctrl+C and do the start command again, but replace
maxplayers 16 with
maxplayers x (change
x to the number of players you want). To change the default map (the first map that is played), replace
cs_office with the name of the map you want. And finally, to change the gamemode, replace
terrortown with the gamemode you want. Garryâs Mod only comes with
terrortown (Short for Trouble in Terrorist Town) and Sandbox by default.
To further configure the server, there is a configuration file which can be edited. Each line in this file is called a configuration variable (cVar). Run this command to edit the file:
The following values can be changed, I'll explain what each one does shortly:
hostname "server name" sv_downloadurl "http://example.com/files/" sv_allowupload 1 sv_password "secret password" sv_timeout 60
Changing the hostname value allows you to change the name of your server. It will be called "Garry's Mod" unless you change it. For example, this will call your server "My cool server":
hostname "My cool server"
You may add as many variables to the file as you like, each new variable needs a new line.
sv_downloadurl variable allows you to choose where custom server content is downloaded from. Custom content includes Garry's mod maps, sounds, addons, and textures. By default, Garry's Mod will only allow data to be downloaded from your server at an extremely slow rate, which is why we need to provide a URL where the data can be downloaded from at full speed. The URL you provide needs to be a clone of your "garrysmod" folder so all of the files will be available.
sv_allowupload can has two choices, 0 or 1, this specifies if you want to allow people to upload content to the server. This is only used for sprays (graphics that the players can spray onto walls) and may cause a security problem. Sprays are often requested, so using "1" will make the players happy, but "0" will keep your server more secure.
sv password allows you to choose a password for your server. Whenever someone joins, they will be asked for this password and they can't join if they don't have it.
sv_timeout is the amount of time in seconds you want the server to wait before kicking someone who has lost their connection. The server will automatically wait for them to get their connection back, but while this is happening the player will appear to be stood still. It's best to have this at 60 or less seconds. Once you've changed these settings, a server restart is required.
Addons can also be installed to give additional features to the game. Some addons need to be installed in a specific way, so you should always read the instructions on their site, but this is how you would download and install the majority of addons:
cd /home/steam/gmodds/garrysmod/addons/ wget http://example.com/addon.zip unzip addon.zip
http://example.com/addon.zip with the URL of where the addon is located. You will also need to change
addon.zip to the name of the addon's zip file. Now the addon has been downloaded and unzipped, you may delete the zip file to save space, like so:
addon.zip with the actual name of the zip file.
If the server is currently running, you need to restart it with Ctrl+C and reissue the start command. You can press the up arrow on your keyboard to automatically insert the last command you ran.
If you lose your SSH connection, when you reconnect you will need to issue the
screen -r command, which lets you resume from where you last were (the game console).