Published on Nov 12 2012 in Dedicated Server Non-Java VPS

Sometimes your registrar does not provide DNS service but you want to point your domain to your VPS IP address. Your VPS package may also not include DNS service (although if you register a domain thru a big registrar like eNom or Godaddy it will come with DNS management service).

In such case you may change registrar to a better one :) (transfer out your domain) or register your own nameservers (ns1.yourdomain.com ns2.yourdomain.com) using your VPS IP (or IPs) in their control panel. Then you can run your own nameserver software on the VPS. Commonly used DNS software includes BIND, TinyDNS, PowerDNS.

For basic use like serving all queries related to a domain or a set of domains from single IP, Centos users can do below steps when logged in as 'root'.

yum install dnsmasq
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
sed -i -e 's/^#no-resolv/no-resolv/' -e 's/^#no-poll/no-poll/' -e 's/^#no-host/no-host/' /etc/dnsmasq.conf
sed -i 's/^#address=/doubleclick.net/127.0.0.1/address=\/yourdomain.com\/10.10.10.10/' /etc/dnsmasq.conf
diff -Nu /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
service dnsmasq start
chkconfig dnsmasq on

Now, if you run a DNS query for your domain or a host/subdomain you should receive your VPS IP. For example from your PC ping www.yourdomain.com and 10.10.10.10 (your VPS IP) should reply.

Of course dnsmasq is more powerful than above. You may also use /etc/hosts to define records for selected hosts or enable mail (MX) lines in /etc/dnsmasq.conf to name a few. dnsmasq.conf contains verbose comments for you to read first.

Note: I do not like the mess created by TinyDNS anyway you may also try this DNS server due to its low resource usage.