Garry's Mod

Garry's Mod

828 ratings
How to host a Garry's Mod Server
By ✯Radek
A tutorial on how to host a Garry's Mod Server using SteamCMD, completely written from scratch. It will include: Installation, port forwarding, and how to add workshop addons, and a few more details.

NOTE (08. Feb 2022): This is a very old guide which I have not properly updated at least since 2017. It is possible that parts of this guide are outdated and that the process has changed in some way. If this happens to be the case, then it is highly unlikely that I will update that part to reflect the changes that have been made in GMod's update history. I stopped playing Garry's Mod years ago, so I haven't followed its updates since then either. This really shows in the poor spelling and wording at some places that probably hasn't changed since I wrote this guide back in 2013, when my English skills were still leaving a lot to be desired.
2
2
   
Award
Favorite
Favorited
Unfavorite
Download and use SteamCMD
Download
First, you need to download SteamCMD, of course. This program is used to install the actual files for your server, and to install the Garry's Mod files.

You can download SteamCMD here.
(Direct download link http ://media.steampowered(.)com/installer/steamcmd.zip)

It is a .zip file. Extract the steamcmd.exe file inside it (extract into its own folder because the files will be installed into the directory of steamcmd.exe), and then run it.

Use

Now, that SteamCMD is ready, we will begin installing the server.

UPDATE July 24 2024: You now have to use force_install_dir before login. To change the force_install_dir path, you have to logout first and then login again. I don't know since when this has been the case, I just never got to updating this guide sooner.

First, you start off by logging in. Type this command in the command prompt that is currently open:

login anonymous

The command prompt should return this information:






After logging in, you have to determine the path where the server will be installed.
To do this, use this command:

force_install_dir <path>

To avoid any issues regarding the directory, just set it directly to your C:\ drive, or any other drive.
Example:
force_install_dir C:\gmodserver





If you want to set the path to something further than just the C:\ drive, then type out the path carefully, and make sure it contains no spaces, otherwise it will make separate folders.

To install the Garry's Mod files, type the following command in the prompt:

app_update 4020 validate
If you have quite slow internet, then this process could take about half an hour. Fast internet however can do this quickly in just a few minutes.

4020 is the ID of "Garry's Mod Dedicated Server", not to be confused with 4000, which is the AppID of the game Garry's Mod itself. http://steamdb.info/app/4020/
Automating the Process
Mostly copied from the valve developer wiki, only because it's fairly useful material.
Only useful for updating your server.
You can also automate this process. There are 2 ways to do that:

NOTE: steamcmd = ./steamcmd.sh on Linux

Way 1


Run the commands all at once:

steamcmd.exe +login anonymous +force_install_dir <path> +app_update 4020 validate +quit

This has to be done in a normal terminal this time, not in SteamCMD. Make sure your terminal's working directory is set to the path where steamcmd.exe is located.

If you are logging in with an account, use username password instead of "anonymous" at the +login command.

Way 2

Make a script:

// gmod_server_update.txt // @ShutdownOnFailedCommand 1 //If updating multiple servers at once, then set this to 0. @NoPromptForPassword 1 login anonymous/username password // Use either "anonymous" or login with an account. force_install_dir path app_update 4020 validate quit

Then run this script with the +runscript command:

steamcmd +runscript gmod_server_update.txt
Configuration of your server
Our server is now installed. Now, we have to configure it, to make it work properly and to keep things organized.
First thing you should do, is to configure the server.cfg file. This file is used to set the Sandbox limits, and to set all console commands that are getting automatically executed when the server is booting up.

This file is located here: drive name:/Program Files(x86)/yourfilepath/blah/steamcmd/garrysmod/cfg

An example of a server.cfg file would look like this:
//The lines are used to make big spaces, since using blank spaces does not work in Steam. Replace the lines with blank spaces, or press "TAB" around 6 times to make a big space.
"hostname"--------------------------------------------"My Garry's Mod Sandbox Server"
"rcon_password"-------------------------------------"serveradmin"
"sbox_noclip"-----------------------------------------"1" //Enables noclip
"sbox_maxprops"------------------------------------"500"
"sbox_maxeffects"-----------------------------------"15"
"sbox_maxemitters"---------------------------------"15"
"sbox_maxthrusters"--------------------------------"30"
"sbox_maxsents"------------------------------------"35"
//etc.
"sbox_playershurtplayers"-------------------------"1" //Enables PVP Damage
//And you can put in some different console commands which you want to be "autoexecuted"
Note that this is just an example to show you how a proper config file looks like syntactically.

Formated in a table:

Command
Value
Action
hostname
my Garry's Mod Sandbox Server
Determines the server name
rcon_password
serveradmin
Sets the RCON password
sv_password
cupcake
Sets the server password
sbox_noclip
1
Enables/Disables noclip
sbox_maxprops
500
Sets the prop limit
sbox_maxeffects
15
Sets the maximum effect amount
sbox_maxemitters
13
Sets the maximum emitter amount
sbox_maxthrusters
30
Sets the maximum Thruster amount
sbox_maxsents
35
Sets the maximum SENT amount
An unconfigured server.cfg file only contains 3 blank lines.

For better security, I recommend to put the RCON password into the parameter line of your srcds.exe shortcut with +rcon_password password. However, you can also completely disable RCON by simply not setting a password.

To run your server, you must exit the "garrysmod" folder and make a shortcut of the srcds.exe file.
Then, right click on the srcds.exe shortcut, click on "Properties", and enter this command line in the parameter line:

-console -game garrysmod +map gm_construct +maxplayers 4
The "Parameter Line" is the line where the path of the executable is in; the "Target" line. Unedited, it looks like this:
C:\folder name\srcds.exe
Example: C:\gmodserver\srcds.exe

After the directory, you can enter as many other commands as you like. They all get executed as the server is launched. Commands that start with a dash (-) are game engine startup parameters, while commands that are initiated with a plus (+) are console commands.





























And then add the commands after it.


Double-click the shortcut, and the server should start up.
Forwarding Your Port
Simply doing these steps is not enough. The server seems to run, and you are able to join, but the server is not yet publicly visible. When somebody outside of your local area network tries to join your server, they will get the "failed after 4 retries" message.

This is because nobody but you, at the moment, has the permission to connect to your host. This is where port forwarding comes in. Port forwarding will not make your router settings accessible from anywhere, all it does is open up a port to be publicly accessible from the internet when somebody tries to establish a connection with your IP address. This is required because routers block any external incoming connection attempts by default, for security reasons. This is why you have to step in and configure your router to allow incoming connections on a specific port. In the case of Garry's Mod, it is ports 27015 onwards, because that's what the Source engine uses.

What you have to do in steps:

1. Go to your desktop and open up your start menu.

2. Search for "cmd" in the search bar, and open the command prompt.

3. In the command prompt, type "ipconfig" and press ENTER.

4. A list of IPs and other miscellaneous information should appear. Search the "Ethernet Adapter LAN" section. If your computer is connected to your router through Wi-Fi, then you will likely not have this section. In this case, you have to find the appropriate section that corresponds to your connection type.

5. When you found your appropriate section, look up the Default Gateway, and remember it. You may have two entries, one that is an IPv4 address (111.111.111.111), and one that is an IPv6 address (ffff:ffff:ffff:ffff ...). In that case, always pick the IPv4 address.

6. Open up your web browser, type in the default gateway into the URL bar, and press enter. With this, you should be able to access the configuration panel of your router. A login screen should appear, either the stock login popup of your browser, or a website login page.

7. Enter the login information for your router. What the login information is depends entirely on the router you use, and whether somebody else in your household has already changed it. If you don't know the information, ask anyone who might know it, or look it up on your router box. Often though, both the username and the password are just "admin" when factory settings are left unchanged.

8. Set up the port forward. For this, find a section for forwarding ports (it's different on all router pages), and fill in all required values and information. You can set the Service Port as 27015-27016 (Use 27015 only if only one port is required), the IP Address your IPv4 Address, and the Protocol "Any" or "All" or "TCP/UDP" (Again, depending on your router page). If you do not have such an option, then you can try to create two port forwarding entries with the same data, except one with TCP and the other with UDP.

9. Save your configuration, and then enable it, and you should be done.
Mounting Game Content
Just like how anyone can mount the content of other source games in their game, you can mount the game content of source games like CS:S, TF2, DoD:S, ... to your server. This is required if you want to spawn entities from those games in Sandbox for example.

NOTE: In my testing, it also perfectly worked by just skipping the whole app_update installation process and just setting up the mountdepots.txt file as shown further down below, by using the directories of the actual game installations in Steam/steamapps/common. I do not know of any reasons why you should not do this, so if you want to save disk space on your computer, you can skip the entire next part about app_update. Instead, you can just install the game normally on Steam.

For this, you need the app_update command in SteamCMD again.

Find the app ID of the game's dedicated server package. This should be easily done on the site steamdb(.)info by searching for the game name and then "Dedicated Server". Once you found it, go through the same process in SteamCMD as with the Garry's Mod Dedicated Server, but this time with the appropriate ID of the game that you want to mount the content of, and with a different force_install_dir location.

An example for CS:S would be

app_update 232330 validate

Note you will have to log out first with the command "logout" if you already logged in previously, or else you cannot change the force_install_dir location.

Once that's done, you have to configure your GMod server to actually mount the files. For this, there is a specific file in the directory
(...path to your server installation)/garrysmod/cfg/mount.cfg

Open the file with any plain text editor. It will likely already have content in it, mostly comments. It probably looks like this:

"mountcfg" { "cstrike" "C:\steamcmd\steamapps\common\Counter-Strike Source Dedicated Server\cstrike" "tf" "C:/mytf2server/tf" }

Edit the mountcfg block so that it includes the path for the game you installed. In the case of CS:S, this would be the path for the "cstrike" entry.

The path must contain the .vpk files of the game, which is where the content is stored.

In case you want to add any other game besides CS:S or TF2, then you can find out what to type as the game's name by looking at how the folder of your game installation is called (the one that contains the launch .exe, the .vpk archives etc.). For example for the game Portal, this would be "portal" (according to Steam/steamapps/common/Portal). Identically, for Day of Defeat: Source, the keyword would be "dod" (like in Steam/steamapps/common/Day of Defeat Source).

You also have to add the game entries to the mountdepots.txt file, also located in the cfg folder. These are the games the server will try to mount the files of.

Its structure is quite simple. Just add an entry with the value "1" for every game that you want to mount.

"gamedepotsystem" { "hl2" "1" "cstrike" "1" "tf" "1" "portal" "1" "dod" "1" "episodic" "1" "ep2" "1" }

Remember this only works with games that Garry's Mod actually supports, so don't try doing this with a GoldSrc game like Half Life 1 or CS 1.6 for example.
Workshop Addons for your Server
The first steps:

1. Create a steam collection with all addons you want to use on your server. The collection must be set to public.
2. Get the ID of the collection. It's the long number at the end of the collection's page URL, /id=123456789(Right Click on collection page -> Copy Page URL).
3. Use the ID to link the collection with your server. For this, you have to add the following parameter to the srcds.exe shortcut:

+host_workshop_collection <Collection ID>

But wait, there's more!

The addons might be on your server now, but all addons that have their own content will show error signs and checkerboard textures as well as missing sounds, if the player doesn't have the addon installed on their client. So we need to force a download of their content, in a way which will be explained below.

Go to your server's lua/autorun/server directory, and create a .lua file, with any name you prefer.
Here, we will need the function resource.AddWorkshop.
resource.AddWorkshop( "id" )
You need to retrieve the ID of all the addons you want the content to be downloaded of. This is done the same way as with your collection: Go to the addon's workshop page, and copy the number at the end of the page URL.
Once you got the ID of all the addons you need, insert a resource.AddWorkshop line for every addon that has custom content, with "id" being replaced with the workshop ID. The ID has to be wrapped in quotes, as the function takes a string as a parameter.

Example:
resource.AddWorkshop( "123456789" )
Common and useful console commands for managing your server
This is a list of the most commonly used and useful console commands which can be used to manage and configure your server to your likings.

-gamemode <gamemode folder name> - Change the gamemode quickly (it will reset back to the gamemode set in the server.cfg file after the server reboots!)
-gamemode_reload_cl - Reloads the gamemode on the client
-banid - Add a user ID to the ban list (default way of banning people, use an admin mod for banning)
-banip - Add an IP address to the ban list (use admin mod for banning)
-sv_cheats 0/1 - Allow cheats on the server
-sv_gravity <value in number> - Set the world gravity. Default is 600
-sv_noclipspeed - Set the noclip speed. Default is 5
-sv_password - Set the server password
-sv_shutdown - Shuts the server down if it's empty
-sv_kickerrornum - Sets the lua error limit before a player gets kicked for them. (recommended 0)
-ai_ignoreplayers 0/1 - Toggles the "Ignore Players" setting
-ai_keepragdolls 0/1 - Toggles the "Keep Corpses" setting
-ai_disabled 0/1 - Toggles the "Disable Thinking" setting
-sbox_godmode 0/1 - Toggles godmode for all players generally (people will only be able to die by map events/triggers)
-sbox_maxballoons - Maximum balloons
-sbox_maxbuttons - Maximum buttons
-sbox_maxdynamite - Maximum dynamite
-sbox_maxeffects - Maximum effect props
-sbox_maxemitters - Maximum emitters
-sbox_maxhoverballs - Maximum hoverballs
-sbox_maxlamps - Maximum lamps
-sbox_maxlights - Maximum lights
-sbox_maxnpcs - Maximum NPCs
-sbox_maxprops - Maximum props
-sbox_maxragdolls - Maximum ragdolls
-sbox_maxsents - Maximum scripted entities
-sbox_maxspawners - Maximum spawners
-sbox_maxthrusters - Maximum thrusters
-sbox_maxturrets - Maximum thrusters
-sbox_maxvehicles - Maximum vehicles
-sbox_maxwheels - Maximum wheels
-sbox_noclip - Allow/Disallow noclip
-sbox_playershurtplayers - Toggle PVP damage
-sbox_weapons - Toggle spawn with weapons

Feel free to suggest any more console commands for this list.
Final Note
That was all (or well, most) stuff I know about hosting a Garry's Mod Server. If something went wrong during installing the server, then you can ask in the comments, and I, or someone else, can maybe help you solve the problem.

Please note that there are official ethical guidelines on how a GMod server is supposed to be run, enforced by Facepunch themselves. They can be found here: https://wiki.facepunch.com/gmod/Server_Operator_Rules

Even though the chances of you violating these rules are likely very low, you shall still know that they exist and that your server must conform to them if you are actually planning to run a server in the long-term.

Please do not add me for questions, post your problem in the comments, so people with the same or a similiar problem can look up the solution if one is found. This guide is starting to age pretty terribly, and I can't continue being the customer support forever.
FAQ
Italic = Question
Bold = Answer

What is the Parameter Line?
The Parameter Line is the "Target" line you have to type the parameters in. In total, it is the directory that gets executed when you access the srcds.exe shortcut you created earlier, along with all the game engine parameters and console commands that you entered.

How to change the gamemode (to DarkRP)?
Insert "gamemode"-----------"darkrp" in your server.cfg file with Notepad++(Replace the dashes with tab indentations) if you have the DarkRP gamemode in your "gamemodes" folder of the server's garrysmod files. Or you can also add +gamemode <folder name> to the parameter line. You can find out the folder name by opening the .gma file of it with SharpGMad.

IT IS NOT WORKING
That isn't even a question, but well. If it doesn't work, then point out WHAT doesn't work, and I, or maybe someone can help you.

When I run app_update 4020 validate, it says "no subscription" and refuses to install the app. How do I fix that?
You have to log in anonymously by running the command "login anonymous" to make it work. You seem to have forgot to do this.

When I try to install the app, I get error "Error! App '4020' is <number>x<number> after update job." What does that mean?
That means, that the directory you determined with force_install_dir seems to be invalid. It may not be your client GMod directory, use a completely different one, and make sure it contains no spaces (this shouldn't actually cause this error, but just to be safe, do not put any spaces into your directory). I recommend to use a completely new directory just for your server, to keep everything clean.

I get this error: [ERROR] lua/autorun/addons.lua:1: attempt to call field 'AddWorkshop' (a nil val
ue) when I make my lua file for downloading workshop content. What can I do about that?

Make sure the lua file is located in lua/autorun/server of your server files, and that you use "resource.AddWorkshop( "id" )" for marking all the workshop addons you want to be downloaded by the players.

My server is running, and I forwarded the port, but my friends still cannot join!
Either your port forward configuration is faulty somehow, or your firewall is blocking your network from performing whatever necessary operation. So in this case, you can either try temporarily disabling your firewall, or investigate precisely what you did wrong in your port forwarding settings.

The server.cfg file is empty when I open it. Is there anything wrong?
There is nothing wrong if it's empty. When it's not edited, it only contains 3 blank lines. If it doesn't, then that's not a problem either.

How do I make myself an admin on my server?
It is strongly recommended to use an admin mod for that, as it is much easier to handle this kind of stuff with one. If you want to go the simple, "default" way, go to (your server's folder name)\garrysmod\settings\users.txt and add yourself as a superadmin there. (Open the file with notepad++ or similiar, as the file looks messy in stock Notepad.)
1,284 Comments
✯Radek  [author] Jul 25 @ 2:23pm 
I took out the part about setting up a static IP address because I do not remember anymore why I ever included the part in the first place, and I also couldn't figure out what it's even good for. The entire part only talked about the local IP address, which is not the globally public IP address under which people find your server, meaning that any changes you did to your network settings there only affected your device in your LAN. I can only imagine how many people have been confused by this, all because back then I had no idea about the difference between a local device IP address (the one that starts with 192.168.) and the global IP address with which you are actually located over the internet.
✯Radek  [author] Jul 15 @ 12:20pm 
I can't believe this guide has existed for so long and I never even explained how to mount content from other source games in your server. How did people spawn the HL2 EP2 jalopy all this time???
ojman212 Mar 10 @ 12:04pm 
Anyone know any good web Panels?
Cirno Dec 21, 2023 @ 3:16pm 
You could try hosting the server through IPV6, but I have no idea if it supports being hosted or connected through IPV6, but that is the way it has to be from now on, since we absolutely ran out of IPV4 address.
Majority of games and apps doesn't supports IPV6, if G'mod si the same case, hopefully somebody can make a mod for it.
Michael2911 Dec 19, 2023 @ 4:55am 
Because the public IP is within CG-NET, the ports do not open as they should and I have no choice but to call the internet provider to fix this problem with the ports.
Soerix Sep 21, 2023 @ 12:58pm 
No one can join my server execpt me, i did all right, i think, i added my Ethernet IP and set it up right with IP, Subnet prefix Length, And DNS wich were all included in my cmd Ipconfig, i Port forwarded by adding my description named server, Used ALL Because there was no TCP/UDP Option only TCP and UDP by themselves, and used the ports you said to use and even placed one in my start.bat, no one can join still execpt just me
filthy avian creature Apr 3, 2022 @ 1:18pm 
Backing up the comment below. This guide saved me hours of effort and research into SteamCMD. Big vouch for キャルビンシュン below, as well! That tool is incredibly helpful. No need to open every single workshop item and copy the ID-- that script is incredibly simple to use, and saves a ton of time.
The Bunkerman Apr 3, 2022 @ 11:31am 
Regarding this guide being potentially out of date, I can confirm that nearly all of it is still applicable, and all the important bits are still fine. *However*, SteamCMD now requires that you specify force_install_dir before you login anonymously, so that's the only thing that would need to be changed.

Great guide by the way! I do Source servers day in and out and still come back to this guide as a refresher once in a while.
Cirno Nov 30, 2021 @ 5:03pm 
@787878 takeover 1984 hina your ports could also be blocked by your ISP.
Thou, if you have more than 1 router you need to open in them all, including the modem if it has a configuration window.
Ludwig Nov 30, 2021 @ 4:19pm 
My port forward does not open ports.