© 2021 www.richardwalz.com
Richard Walz
All rights reserved.

How to build a dedicated Valheim game server in Ubuntu Linux

install-valheim-server-on-ubuntu-linux

Last Updated: 9/14/2021 – included backup script

This guide is for all the gamers who want to manage their own dedicated Valheim server. Learn how to do it before the “Hearth and Home” update releases later this year. This guide will be done using Digital Ocean Cloud Servers, which I have been using for the past five-plus years both professionally and for personal projects. If you use Google Cloud Platform/Azure/AWS or others, the process is pretty similar.

DigitalOcean Referral Badge

If you are looking for the Windows version of this guide go here.

Prerequisites

  • Some knowledge of Linux/Ubuntu
  • Your Own Website Domain (Recommended)
  • This guide can easily accommodate between 2 to 10 Players

Section 1: Build a server on Digital Ocean

  1. Use this link to get $100 worth of free Digital Ocean credits (Valid for 60 Days)
  2. Create an Account and Logon to Digital Ocean
  3. Click “Create” select “Droplets
  1. On the “Create Droplets” screen choose “Ubuntu 20.04 LTS
  1. Under “Choose a Plan” select “Basic” and “Regular Intel with SSD
  2. Also select “4GB/2 CPU + 80GB SSD
  1. Skip “Add block storage”
  2. On the “Choose a datacenter region” select a location that is closest for you and your friends. Since most of my friends are located within the eastern USA time zone I am going to select New York.
  1. Skip “VPC Network”
  2. Skip “Select additional options”
  1. Select “Password” unless you know how to use SSH keys. 🙂
  2. For “Create root password”, create a super-long-random-complex-password. Save this password as we will need this for connecting and managing this virtual machine.
  1. For “Choose a hostname” enter a name preferably a subdomain of the domain name you own.
    • E.g. I am going to use “val.cloudrigs.com” we will connect this to our DNS/Registrar in a later step.
    • This is just a label but in some other apps it can be sent as a header.
    • If you do not have a domain name. You can name it anything you wish such as ValheimFriendServer.
  1. Now scroll down to the bottom and click “Create Droplet“, in just a few short minutes your Digital Ocean powered Ubuntu machine will be ready to go.
  1. Once the Ubuntu server has been created it will look like the following. Write down this Droplet IP mine is 143.198.14.227

Section 2: Setup Firewall Rules

  1. Go to www.whatismyip.com and write down your public IP from your computer, mine is 136.57.10.10
  2. Log back into Digital Ocean and on the left side select “Networking” then select “Firewalls” and click “Create Firewall
  3. Create a name such as “Valheim-Firewall”
  1. Configure the following “Inbound Rules”. For SSH use your public IP from your ISP (which we got in Section 2, Step 1). This is to reduce bots and attackers from trying to bruteforce your root account. This ensures only your IP is authorized to connect.
  2. Make sure “UDP” and port range is “2456-2458” setup.
  1. Configure the following “Outbound Rules”. These should already exist.
  1. Under “Apply to Droplets” type in the name of the server you originally created. I will type in the name of my droplet, so the firewall rules apply to it. Then click “Create Firewall

Section 3: Create a DNS entry with your own domain (otherwise skip to Section 4)

  1. Now, its time to map the static IP of your Droplet IP to your DNS provider. In my case I am using CloudFlare so I am going to create a DNS entry to map “val.cloudrigs.com” to my Droplet IP of 143.198.14.227. I am doing this now so the DNS value has time to propagate throughout the world.
  2. Here is what it looks like in my CloudFlare account. Notice I am using DNS only. I am not using the proxy option.

Section 4: Connect to the server and Install Valheim

  1. Grab the IP from the droplet: 143.198.14.227
  2. If you do not have Putty download it and run it. It should look like this: Enter in the droplet IP into the “Host Name” field
  1. Click “Open” then click “Accept/I trust” the fingerprint verification screen.
    • Login as: root
    • Password: <the password you wrote down before> , if you copy the password, you can paste by right-clicking into the putty window. Just keep in mind, that no feedback is displayed when typing in any passwords. If you press enter it should connect.
    • Once connected you should see the following
  1. Run the following command, this will update and install the latest Ubuntu packages.
sudo apt-get update && sudo apt-get -y upgrade
  1. If you get the following message press the “tab” key then press enter on “Ok”
  1. Type the following command, then press enter
reboot
  1. Give the server a minute to reboot, then reconnect to putty and run this
sudo apt-get install -y git net-tools htop
  1. Navigate to the folder by typing “/opt” then press enter
cd /opt
  1. Download the Valheim Script created by Nimdy and updated by many contributors.
git clone https://github.com/Nimdy/Dedicated_Valheim_Server_Script.git
  1. Change to the following directory
cd Dedicated_Valheim_Server_Script
  1. Here we are going to change the permissions so this script can be executed.
chmod +x njordmenu.sh
  1. Launch the Nimdy Njord Menu Script.
sudo ./njordmenu.sh
  1. This is what you should see
  1. Select Option 3, by typing “3” and pressing enter.
  1. Select Option “1” and press enter (I think you got it)
  1. The Steam server software will start to download and install.
  1. Follow the on-screen instructions for creating a local Ubuntu account to run the game server. Press enter to proceed to the next step.
  1. Create a name for your server. This name will show in the Valheim public listing directory. Notice: Do not use special characters in your name.
  1. Create the world name for your server. I named mine “OdinsGate”.
  1. Select “1” to set your server public
  1. Set a password that you will share with your friends so they can access the server. Password must be at least 5 characters long.
  1. Valheim server will begin to install, this process will take 3-5 minutes.
  1. When completed you will see the following. You can press 0 to go to the main menu. It can take up to 20 minutes for your server to show up in the Valheim directory listing.

Congratulations your Valheim Server is live!!

Now your users can connect with just the domain name val.cloudrigs.com instead of by IP.

If you do not have your own domain name, just provide the droplet IP to your friends. In this example that would be 143.198.14.227


Bonus Content

  • What happens if my home network’s IP changes?
    • Logon to digital ocean and replace the Inbound SSH IP with your new one. This may seem annoying but it offers a lot of protection to your environment.
  • How can I tell if my server is running?
    • You can review by selecting option “16” in the menu or by running the following command
systemctl status valheimserver.service
  • How do I get back into the menu?
    • Use the following command
cd /opt/Dedicated_Valheim_Server_Script
sudo ./njordmenu.sh

  • How do I reboot the server?
    • Use the following command
sudo reboot
  • I accidently shutdown the server how to I power it back on?
    • Logon to digital ocean select the droplet, select “Power” then click “Turn On”
  • Do you have a script to backup the server? Yes, see the script below. named “valheimbackup.sh” make sure this script has execute permissions “sudo chmod +x valheimbackup.sh” . View this post to use cronjob.
#!/bin/bash

## Get the current date as variable.
TODAY="$(date +%Y-%m-%d--%mm)"

## Clean up files older than 3 weeks. 
find /home/steam/backups/ -mtime +21 -type f -delete

#systemctl stop the service (based off the service name)
systemctl stop valheimserver_ThorsHammerWorld.service


#Wait for RAM to offload to .db and .db.old
#allows for the closing of the databases.
sleep 120

## Tar Section. Create a backup file, with the current date in its name.
## Add -h to convert the symbolic links into a regular files.
## Backup some system files, also the entire `/home` directory, etc.
## --exclude some directories, for example the the browser's cache, `.bash_history`, etc.
tar zcvf "/home/steam/backups/valheim-backup-$TODAY.tgz" /home/steam/.config/unity3d/IronGate/Valheim/* 
chown steam:steam /home/steam/backups/valheim-backup-$TODAY.tgz