How to Point a Domain Name to VPS
To use a custom domain name with a VPS, you will first need to make a few DNS changes. In this guide, we’ll show you how to point a domain name to a virtual private server hosting using two methods:
- Changing A record in the current DNS zone
- Setting up a new DNS zone with custom nameservers
Locating Details
Make sure to complete the initial setup of your VPS and buy a domain name before proceeding.
Firstly, you’ll need to find the IP address of your virtual server. On Hostinger panel, you may locate all VPS related information under the Servers section.
The highlighted area under SSH Details shows your virtual server’s dedicated IP address.
Method 1 – Pointing Domain to VPS via A record
The following method is a pretty straightforward solution. It would involve changing your current A record in the authoritative DNS zone. This means that the A record switch must be carried out at the DNS zone where your nameservers are currently pointing.
If you choose this option, your DNS zone file with all other existing entries (CNAME, MX, NS, and other records) will remain with the current provider. The approach may be easier for beginners or those who do not wish to alter the location of their DNS zone.
If you’re not sure where your domain name is pointing at the moment, you may use DNS lookup tools or utilize the dig command to locate the NS records. Executing the following command via terminal will do the trick:
dig NS +short hostinger-tutorials.xyz
Now that you know where your domain is pointed, navigate to the provider and open up your domain’s DNS zone.
Adding DNS entries
There are two approaches to choose from at this point:
- Using two A records – one for the www subdomain and another for the domain itself.
- Using A record for the domain and CNAME for the www subdomain.
Both of these options will provide you with the same result. Start by finding the current A record value and replace it with the dedicated IP address located earlier. Below, you’ll find a demonstration of how the entries should look like in your DNS zone.
Option 1 – Using two A records
Name | TTL | Type | Address |
example.com | 14400 | A | 153.92.211.25 |
www.example.com | 14400 | A | 153.92.211.26 |
Option 2 – Using A record and CNAME
Name | TTL | Type | Address |
example.com | 14400 | A | 153.92.211.25 |
www.example.com | 14400 | CNAME | example.com |
Performing DNS Lookup
After pointing the domain to your VPS, it’s time to check whether the records were added correctly. Keep in mind that DNS propagation can take up to 24 hours, thus you may have to wait at least a few hours before everything starts working. However, most DNS checkup tools provide instant results. You may also do this using the dig command via terminal:
dig A +short hostinger-tutorials.xyz
If the output shows your VPS dedicated IP address as the A record, everything was done correctly! The remaining part is waiting for the DNS to fully propagate worldwide. To speed up the process, you may flush DNS. Once the DNS is fully active, you will see a default loading page when visiting your domain via browser.
Method 2 – Pointing Domain to VPS via Custom Nameservers
Pointing a domain to VPS via custom nameservers is a bit trickier, as you will need to set up a new DNS zone on the virtual server. This method will switch the location of your DNS zone to the VPS, which means that all future DNS-related changes will have to be made through the newly created zone.
Creating Custom Nameservers
Start by creating new child nameservers for your domain. Each entry needs to point to the VPS dedicated IP address. On hPanel, you can do it via Domains → DNS / Nameservers → Child nameservers.
Setting Up a DNS Zone on VPS
The next step is setting up a DNS zone for your domain on the virtual server. Connect to your VPS via SSH and go to:
cd /etc/bind
Then, create a separate folder for your DNS zone files:
mkdir -p zones
Access the newly created directory:
cd zones
Using the nano command, create a new zone file for your domain:
nano hostinger-tutorials.xyz
Use the following example and replace all IP address and domain instances with your actual domain name and the dedicated IP of your VPS:
; ; BIND data file for hostinger-tutorials.xyz ; $TTL 3h @ IN SOA ns1.hostinger-tutorials.xyz. admin.hostinger-tutorials.xyz. ( 1 ; Serial 3h ; Refresh after 3 hours 1h ; Retry after 1 hour 1w ; Expire after 1 week 1h ) ; Negative caching TTL of 1 day ; @ IN NS ns1.hostinger-tutorials.xyz. @ IN NS ns2.hostinger-tutorials.xyz. hostinger-tutorials.xyz. IN MX 10 hostinger-tutorials.xyz. hostinger-tutorials.xyz. IN A 153.92.211.25 ns1 IN A 153.92.211.25 ns2 IN A 153.92.211.26 www IN CNAME hostinger-tutorials.xyz. mail IN A 153.92.211.25 ftp IN CNAME hostinger-tutorials.xyz.
Save the file by pressing CTRL+X and confirm the changes. The next task is inserting it in the default bind configuration:
cd /etc/bind nano named.conf.local
Add the following lines in the bottom and make sure to edit the file name with the real values:
zone "hostinger-tutorials.xyz" { type master; file "/etc/bind/zones/hostinger-tutorials.xyz"; };
It is also recommended to use a stable DNS forwarder. In this demonstration, we’ll use Google Public DNS by editing the named.conf.options file:
nano named.conf.options
Locate the following lines:
// forwarders { // 0.0.0.0; // };
Edit them and according to this example:
forwarders { 8.8.4.4; };
Now, all necessary values have been added. Double-check if DNS zone file syntax is correct by executing:
named-checkzone hostinger-tutorials.xyz /etc/bind/zones/hostinger-tutorials.xyz
If the task was done correctly, the output should be similar to:
Lastly, restart the DNS bind service and make sure it’s running:
/etc/init.d/bind9 restart /etc/init.d/bind9 start
Changing Nameservers
Since all pieces of the puzzle have been gathered, the last step is changing the nameservers of your domain to the newly created ones. You can point your domain to Hostinger through their domain management panel.
Keep in mind that DNS propagation may take up to 24 hours, thus you’ll have to wait at least an hour or two before everything is fully operational. To speed things up, you may flush DNS again. You may also use online DNS checkup tools to confirm the functionality of your newly created zone. Once the DNS finishes propagating, you will see a default loading page while accessing your domain through the browser.
Bonus – Setting Up Reverse DNS
In some cases, you may be required to set up a reverse DNS record. Hostinger simplifies this process with an inbuilt tool at the bottom of your server management panel.
Once added, keep in mind that it can take a few hours to propagate before the record is fully active.
Conclusion
In this tutorial, we’ve learned two different methods of pointing a domain name to a virtual private server. It’s also important to remember that DNS changes can take at least a few hours to propagate worldwide.
Once the domain starts working with your VPS, the real journey begins. In case you have any questions, suggestions, or cool tips, make sure to share them in the comments below!
Start Working on Your Linux VPS
How to Change Hostname on Linux
How to Use Tmux on Linux for Task Management
How to Start Working with Linux Screen
Comments
August 03 2019
there is no bind folder in etc folder ....
August 03 2019
Its in lib64
March 24 2020
Great stuff indeed. No doubt DNS propagation is a time-consuming process. I checked the tool that you mentioned for the DNS Propagation, as I was Googling for more tool, So I came across a handy online tool dnschecker.org, that provides 300+ DNS servers for lookup comparing to other tools. I shared the tool for the better help of the users.
July 13 2020
in my case i have a Windows Server R2 VPS. Is there any instructions for this case? Thank you!
July 14 2020
Hey Alejandro! :) The procedure should be the same for Linux and Windows, as you are only configuring the DNS zone. For example - setting up the A record to your VPS is just showing your domain what IP address it's drawing content from. The configuration within the server could be different, for which you'd need to contact your VPS provider's support team, but the domain configuration should be exactly as it is on the guide above :)
August 07 2020
The last part where the child servers names are also added to the primary nameserver does not seem to work. I get the error that nameservers cannot be the same as the child server names. Any ideas? So if the primary nameserver cannot be empty and not be the same as the child server names... What are you supposed to put there?
November 06 2020
Hey Morten. Hope you are having a great day! You may need to check this out with our support team, but make sure you have your Child Nameservers created before you can set them as your nameservers. You can check a guide on how to do that here.
August 28 2020
Does the below enable redirect to the 'www' version? I want example.com to be redirected to www.example.com Option 1 – Using two A records Name TTL Type Address example.com 14400 A 153.92.211.25 www.example.com 14400 A 153.92.211.25 Option 2 – Using A record and CNAME Name TTL Type Address example.com 14400 A 153.92.211.25 www.example.com 14400 CNAME example.com
November 06 2020
Hey siti! :) The examples you've given enable WWW so your website is accessible with WWW. However, it doesn't exactly redirect the website to www. You can use the following code in your .htaccess for most of the popular CMS to force a www redirect (this is a https://www.domain.com redirect, so it will force your HTTPS connection too):
RewriteEngine on RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www\. [NC] RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]