How to Point a Domain Name to VPS

DNS Management on a VPS

MD. Arif Ahmed
2 min readMar 24, 2022

--

Well, you are searching for this solution means you have already completed the development of your project and you are ready to deploy it. At the time of deployment, there are some issues we always faced. Those who chose an unmanaged VPS server to deploy the project always faced this common problem, how to connect the domain to the VPS. People use unmanaged VPS because it’s cheap. But the main issue with an unmanaged VPS is you have to manage everything. So, in this article, I will discuss how to point a domain name to a VPS. There are two methods to do that:

i) Setting up a new DNS Zone with custom nameservers

ii) Changing A Record of the current DNS Zone

Assuming you have already completed all the basic setup on your VPS.

In this article, I only discuss the second method:

Second Method: Setting up a new DNS Zone with custom nameservers

To proceed with this method first you need to create new child nameservers for your domain. You need to create at least two child nameservers for your domain each entry needs to point to the VPS dedicated IP address. You can do this from your domain control panel. for example, if your VPS dedicated IP is 192.168.0.1 your child nameservers will be

Nameserver 1: ns1.yourdomain.com and Ip: 192.168.0.1

Nameserver 2: ns2.yourdomain.com and Ip: 192.168.0.1

Then you need to connect your VPS via SSH and go to the bind directory, assuming bind9 already install to your VPS.

cd /etc/bind

then create a new folder for your DNS zone files:

mkdir -p zones

then access the newly created directory:

cd zones

then create a zone file for your domain:

nano yourdomain.com

Now use the following example and replace all the IP addresses and domain instances with your actual domain name and the dedicated IP of your VPS:

<script src=”https://gist.github.com/arifthefinix/76bb6d54f3b4ab83f96914a407a515cf.js"></script>

Save the file by pressing CTRL+X and confirming changes. Then you have to insert it in the default bind configuration:

cd /etc/bind
nano named.conf.local

Add the following lines at the bottom and make sure to edit the file name with your data:

zone “yourdomain.com” {

type master;

file “/etc/bind/zones/yourdomain.com”;

};

then you have to use a stable DNS forwarder, you could use google public DNS by editing the named.conf.options file:

nano named.conf.options

Find the following lines:

// forwarders {

// 0.0.0.0;

// };

Edit them with the following lines:

forwarders {

8.8.4.4;

};

Now. you are all set. You can run the following command to make sure there is no syntax error:

named-checkzone yourdomain.com /etc/bind/zones/yourdomain.com

Finally, restart the bind service:

/etc/init.d/bind9 restart
/etc/init.d/bind9 start

--

--