Programster's Blog

Tutorials focusing on Linux, programming, and open-source

Host an NS2 Server From Home With Ubuntu 14.04

NS2

Natural Selection 2 (NS2) is a fantastic game but there aren't enough UK servers, so the limited ones that are available are always full. Here is how you can host your own server.

Prerequisites

  • A box running Ubuntu 14.04
  • 2 GB RAM (preferably more)
  • 2 vCPUs (hyperthreading counts)
  • CPU threads should be running 3Ghz+ as a rough measurement.

For this tutorial, I am going to be using a 2.5 GB VPS on my AMD FX 8320 server, with access to 2 vCPUs. The rest of the virtual machines running on that box are just static websites so the CPU won't suffer from noisy neighbours. You could also do this in Virtualbox. However, using a cheap $5 VPS is not likely to meet the CPU requirements as those machines have their CPU massively oversold and their processors are aimed at performance-per-watt rather than pure grunt.

Steps

# Please enter the username and password
# for your steam account here.
# This account needs to be the one that 
# has purchased NS2
STEAM_USERNAME=""
STEAM_PASSWORD=""

sudo apt install speex:i386 libgtk2.0-0:i386 lib32gcc1 -y
sudo adduser ns2server
sudo su ns2server
cd /home/ns2server
mkdir steamcmd
cd steamcmd
wget http://media.steampowered.com/client/steamcmd_linux.tar.gz
tar -xvzf steamcmd_linux.tar.gz
mkdir /home/ns2server/serverfiles

./steamcmd.sh \
+login $STEAM_USERNAME $STEAM_PASSWORD \
+force_install_dir "/home/ns2server/serverfiles" \
+app_update 4940 validate \
+quit

./steamcmd.sh \
+login anonymous \
+force_install_dir "/home/ns2server/serverfiles" \
+app_update 4940 validate \
+quit

echo "done!"

Congratulations, you've performed the installation.

Port Forwarding

If you are hosting this from home, you now need to set up port forwarding on your router to open 27015 and 27016 so that others can join your server when you start it. This varies from router to router, but when using pfSense 2.3, this can be found under Firewall > NAT.

Starting the Server

Now you need to actually start an NS2 server. Below is an example command that you can customize to your needs. The parameters are self-explanatory.

./server_linux32 \
-name \"NS2 Server\" \
-port 27015 \
-webadmin \
-webdomain "192.168.1.1" \
-webuser admin \
-webpassword password \
-webport 8080 \
-map ns2_summit \
-limit 24

Make sure webdomain is set to the private/internal IP of the server, and not your properties public IP. If you want your friends to join you, find out your public IP from icanhazip and tell your friends to connect to it by using the command connect [public ip here] in the NS2 console, which is accessed by hitting the top left key on your keyboard below escape when in the menu screen or in-game.

Conclusion

You can now configure your own NS2 server. Now the hardest bit is to get enough people to join to kick it off as nobody wants to join an empty server. If I can just figure out how to enable bots...

References

Last updated: 16th August 2018
First published: 16th August 2018

This blog is created by Stuart Page

I'm a freelance web developer and technology consultant based in Surrey, UK, with over 10 years experience in web development, DevOps, Linux Administration, and IT solutions.

Need support with your infrastructure or web services?

Get in touch