How to Create Nameservers on a VPS

Just bought a domain name for your website, but nothing shows up when you type it into your browser?  Don’t worry, this is perfectly normal and can be easily fixed. All you have to do is create a nameserver to tell the internet where your website is hosted.

A nameserver translates your domain name into the IP address of the server that hosts your website. If you’re new to VPS hosting, you might find it helpful to learn more about what a VPS is and how it works—check out this detailed guide on what VPS hosting is. In this guide, we’ll walk you through everything you need to know about nameservers and how to set them up on your VPS, step by step.



Why set up private nameservers on a VPS?

Every time someone visits a website, their browser queries a nameserver to find out the server where the site is hosted. Even though you can use the default nameservers provided by your hosting company, setting up a private server on your VPS can be beneficial. Here’s how:

  • Branding: First up, you don’t have to use generic nameservers like ns1.hostingprovider.com. Instead, you can have something like ns1.yourdomain.com, which makes your business look a lot more professional.
  • Full control: You have direct control over your DNS settings, which allows you to configure and customize records as needed, without having to rely on anyone else. 
  • Better performance: Private nameservers can reduce DNS lookup times and improve website loading speeds, especially if your visitors are in the same region as your server.
  • Easier domain management: If you host multiple websites, private nameservers offer a convenient way to manage all your domains from a single system. 

Prerequisites for creating nameservers on VPS

Before you start our VPS nameserver setup guide, let’s quickly go over some prerequisites:

  1. A registered domain name: Your nameservers need a domain to be associated with. Don’t have one yet? Check out this guide on which domains you should register to ensure you choose the right ones for your needs.
  2. A VPS with root access (Linux or Windows): You need full control over your server to configure the DNS settings and make changes to the nameserver setup. 
  3. An installed DNS server: A DNS server is the software that handles domain name lookups. Some examples are: BIND (Linux), PowerDNS (Linux) and Windows DNS.
  4. IP addresses for the nameservers: You need at least two IP addresses to assign to your nameservers (e.g., ns1.yourdomain.com → 192.168.1.1 and ns2.yourdomain.com → 192.168.1.2). These IPs tell the internet where to find your website.

Step by step guide to creating nameservers on VPS

With the prerequisites sorted, it’s time to learn how to set up nameservers on VPS. 

Step 1 – Install the server

First up, your VPS needs a DNS server to handle domain name lookups. Here’s how to install one on both Linux and Windows.

Linux

BIND (Berkeley Internet Name Domain) is the most common DNS server for Linux. Here’s how to install it:

  1. Log in to your Linux VPS.
  2. Update your system:

For Ubuntu, you can run:

sudo apt update && sudo apt upgrade -y  

For CentOS/RHEL, you can run:

sudo yum update -y  

These commands will update the package lists and then upgrade all installed packages to their latest versions. Expect output like in this screenshot:

Terminal screen showing a Linux package installation progress at 52%
  1. Run these commands to install BIND:

For Ubuntu, the command is:

sudo apt install bind9 -y 

For CentOS/RHEL, the command is:

sudo yum install bind bind-utils -y  

Terminal screen showing the installation of BIND9 utilities on a Linux system, with the kernel reported as up-to-date.
  1. Verify that BIND has installed successfully by checking its version:

named -v

Expect an output like this:

BIND 9.18.30-0ubuntu0.22.04.1-Ubuntu (Extended Support Version) <id:>

  1. Next, start and enable the BIND service:

sudo systemctl start named  

sudo systemctl enable named  

You may see the following lines on the terminal:

Synchronizing state of named.service with SysV service script with /lib/systemd/systemd-sysv-install.

Executing: /lib/systemd/systemd-sysv-install enable named

Your Linux VPS now has a DNS server installed and running. To verify, run this command:

ps -ef | grep named

The server should appear in the output:

Terminal screen displaying the output of the ps -ef | grep named command, showing the BIND DNS service running.

Windows

Here are the steps to set up a DNS server on Windows:

  1. Click Start, then open Server Manager.
  2. Click Manage > Add Roles and Features.
  3. Select Role-Based Installation and choose your VPS from the list.
  4. Check “DNS Server” under the list of available roles and click Next until you reach the confirmation screen.
  5. Click Install and wait for the process to finish.
  6. Now, from the start menu, got to Windows Administrative Tools > DNS to tweak any settings.

To keep things secure, don’t forget to install a firewall on your server, if you haven’t already. 

Step 2 – Register custom nameservers with a domain registrar

The next step is to register your custom nameservers with your domain registrar. Follow these steps:

  1. Log in to your domain registrar’s website.
  2. Look for an option like “Nameservers”, “Custom Nameservers”, “Private Nameservers”, or “Hostnames” in the DNS settings. It’s usually found under domain management. For example, here’s a screenshot from HOSTAFRICA’s domain management area in which the “Private Nameservers” option can be seen:
Domain management dashboard for hacp-testing.co.za, showing active status, SSL details, registration and expiry dates, and billing information.
  1. On the screen, you should be able to create custom nameservers. Register both the primary and secondary nameservers by specifying their names and IP addresses.
Web interface for registering custom nameservers for the domain hacp-testing.co.za, with fields for nameserver and IP address input.
  1. It may take a few hours (up to 24 hours) for the changes to fully update across the internet.

(Note: Alternatively, if you’d like to transfer your domain to someone else, here’s a step-by-step guide on domain transfer process works)

Step 3 – Configure your DNS server

Now that your nameservers are registered, you need to configure your DNS server to handle domain requests. Here’s how to do it:

  1. Open the default BIND configuration file:

For Ubuntu:

sudo nano /etc/bind/named.conf.local 

For CentOS/RHEL:

sudo nano /etc/named.conf  

  1. Replace hacp-testing.co.za with your actual domain and then put these lines at the end of the file:

zone “hacp-testing.co.za” {

    type master;

    file “/etc/bind/zones/hacp-testing.co.za.db”;

};

  1. Then, create the zone file:

sudo mkdir -p /etc/bind/zones  

sudo nano /etc/bind/zones/hacp-testing.co.za.db

Add the following content to the file and save it: (Make sure to put in your actual domain name and IP addresses)

$TTL 86400

@   IN  SOA  ns1.hacp-testing.co.za. admin.hacp-testing.co.za. (

        2024012901  ; Serial

        3600        ; Refresh

        1800        ; Retry

        604800      ; Expire

        86400       ; Minimum TTL

)

@   IN  NS  ns1.hacp-testing.co.za.

@   IN  NS  ns2.hacp-testing.co.za.

ns1 IN  A   [Your VPS IP]

ns2 IN  A   [Your Secondary VPS IP]

www IN  A   [Your VPS IP]

  1. Restart the BIND service to apply the changes.

sudo systemctl restart named 

(Note: If you are also storing sensitive data on your server, read this guide on how to keep critical databases safe.)

Step 4 – Test your nameservers

Once everything is set up, you must test your nameservers to make sure they are working correctly. Here are two ways to do it:

Using nslookup

Run this command, replacing yourdomain.co.za with your actual domain:

nslookup hacp-testing.co.za ns1.hacp-testing.co.za

The command sends a DNS query to ns1.hacp-testing.co.za asking for the IP address(es) associated with hacp-testing.co.za. Expect an output like this:

Server:         ns1.hacp-testing.co.za

Address:      [IP address of your nameserver]

Name:   hacp-testing.co.za

Address: [IP address of the hosting server]

Using dig

Alternatively, you can run this command:

dig @ns1.hacp-testing.co.za hacp-testing.co.za

This command directly queries ns1.hacp-testing.co.za for the DNS records of hacp-testing.co.za.  Look for the “ANSWER SECTION” in the output.  It should contain the IP address(es) associated with your domain.  A successful response will look similar to this:

;; ANSWER SECTION:

hacp-testing.co.za.      86400   IN      A       [IP address of the hosting server]


Troubleshooting common issues

Creating nameservers can sometimes be challenging, even if you follow all the instructions.  Here are some common problems you may face and how to fix them:

Nameservers not resolving?

If your domain isn’t responding to queries, try these fixes:

  • Log into your domain registrar and verify that ns1.yourdomain.co.za and ns2.yourdomain.co.za are pointing to the correct IPs.
  • Double check that your DNS server is running. On Linux, you can use the following command to do so:

systemctl status named  

On Windows, check DNS Manager and restart the DNS service using:

net stop dns && net start dns

  • If not done already, allow DNS traffic through the firewall by opening ports 53 for both TCP and UDP:

sudo ufw allow 53/tcp

sudo ufw allow 53/udp

Incorrect IP mapping?

If your domain resolves but points to the wrong IP, here’s some ways to troubleshoot:

  • Open your DNS zone file (/etc/bind/zones/yourdomain.co.za.db) and ensure that the A records have the correct IPs. To do the same on Windows, open DNS Manager, go to your zone, and confirm that ns1 and ns2 have the right IPs.
  • Clear the cache on your local machine. On Windows, run:

ipconfig /flushdns

On Linux, run:

sudo systemctl restart systemd-resolved

Propagation delays?

DNS changes can take time to spread across the internet. If your updates aren’t showing up:

  • Check TTL settings. If your zone file has a high TTL (e.g., 86400 seconds), reduce it to 3600 (1 hour) to speed up future changes.
  • Use online DNS checkers. Websites like whatsmydns.net can show how your DNS is propagating globally.
  • Wait it out. DNS propagation can take up to 24 hours, so patience may be required.

DNS server not starting?

If your DNS service won’t start:

  • Check the logs for errors by running this command:

journalctl -xe | grep named

  • Look for syntax errors in your configuration. You can use the named-checkconf command to validate the BIND config.
  • Restart the server; sometimes, a simple reboot can fix the issue:

sudo reboot

Secondary nameserver not responding?

If your secondary nameserver (ns2) isn’t working:

  1. Ensure it’s configured as a slave. In named.conf, it should have:

zone “yourdomain.co.za” {

type slave;

masters { [Primary VPS IP]; };

file “yourdomain.co.za.slave.db”;

};

  1. Check network connectivity. Ping the primary server from the secondary to ensure that they can communicate.

Port 53 blocked?

Some hosting providers block port 53 by default. If your nameservers don’t work externally:

  • Check if the port is open by running this command:

netstat -tulnp | grep :53

If it’s not open, contact your hosting provider for assistance. 

These were some common issues you may encounter when setting up private nameservers. For troubleshooting other website errors, consult this HTTP error messages guide.  


Conclusion

A private nameserver improves your website’s branding, performance, and reliability. In this guide, we learnt how to set up a private nameserver, register it with a domain registrar, configure a DNS server, and troubleshoot common nameserver-related issues. We hope you found it useful .If you are looking for reliable VPS hosting, check out the Linux VPS and Windows VPS offerings by cloud.co.za

Articles you may enjoy

Looking for further info, or perhaps a how-to guide?