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'.
- Install dnsmasq and backup its config file.
yum install dnsmasq
cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
- Disable a few features to lower resource usage.
sed -i -e 's/^#no-resolv/no-resolv/' -e 's/^#no-poll/no-poll/' -e 's/^#no-host/no-host/' /etc/dnsmasq.conf
- In the below command replace yourdomain.com with your domain name and 10.10.10.10 with your VPS IP address.
sed -i 's/^#address=/doubleclick.net/127.0.0.1/address=\/yourdomain.com\/10.10.10.10/' /etc/dnsmasq.conf
- Optionally you can verify the changes you made.
diff -Nu /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
- Start dnsmasq and make it start at boot time.
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.