Back to Home

How to Set Up a Simple BIND Nameserver on CentOS

I decided to try out HostGator's VPS Hosting for a new Drupal project I'm working on. This is the first post in a series that will touch on various aspects of VPS management, Drupal, and video distribution.

I wanted to set up a custom nameserver partially for the learning experience and partially to gain total control over load balancing, if necessary in the future. First of all, I signed up for the Level 1 VPS at HostGator. The low cost and scalability of their plans attracted me, though I've never used them before. After doing some research, I decided to setup a simple nameserver hosted on the VPS that points to my domains on the server. Keep in mind that this is a very simple setup that is not necessarily secure. Check out the resources at the end of this post if you want to dig deeper.

The three files we will need to create or edit are:

  • /etc/resolv.conf
  • /etc/named.conf
  • /var/named/chroot/var/named/example.com.db

This assumes that you're running BIND in a chroot jail (which is the default setup for HostGator's VPS at the moment).

Step 1

Create or edit resolv.conf so that it looks like this:

File: /etc/resolv.conf

nameserver 127.0.0.1

You should comment out any other lines if they exist. This tells the host to look at its own nameserver for domain name lookups.

Step 2

Next, create or edit named.conf so that it contains:

File: /etc/named.conf

options {  
  listen-on port 53 { any; };  
};  
zone "example.com" {  
 type master;  
  notify no;  
  allow-query { any; };  
  file "/var/named/chroot/var/named/example.com.db";  
};

This tells BIND to listen on port 53 (the default DNS port number) from any IP. The zone section should be repeated for every domain you're serving. The file part should point to each zone file.

Step 3

Now we need to create a zone file for the domain:

File: /var/named/chroot/var/named/example.com.db

$TTL 14400  
@ 86400 IN SOA ns1.example.com. admin@example.com. (  
    2008021501 ; serial, todays date+todays  
    86400 ; refresh, seconds  
    7200 ; retry, seconds  
    3600000 ; expire, seconds  
    86400 ) ; minimum, seconds  
example.com. 86400 IN NS ns1.example.com.  
example.com. 86400 IN NS ns2.example.com.  
ns1 IN A 111.222.333.444  
ns2 IN A 111.222.333.445  
example.com. IN A 111.222.333.444  
localhost.example.com. IN A 127.0.0.1  
example.com. IN MX 0 example.com.  
mail IN CNAME example.com.  
www IN CNAME example.com.  
ftp IN A 111.222.333.444

Basically, this file sets up each nameserver as ns1.example.com (111.222.333.444) and ns2.example.com (111.222.333.445). This matches the nameservers to each IP.

Step 4

Then, restart BIND:

service named restart

Step 5

Finally, you need to contact your registrar and register your new nameservers ns1.example.com and ns2.example.com. Here are some step-by-step instructions for the most common registrars.

And that should do it! Please check out the following resources, as this short example just barely scratches the surface of DNS configuration:

Related Posts

The essential design concepts I use when developing an evolvable, distributed system.

Read More

How can we continuously integrate small changes while practicing acceptance test-driven development?

Read More

TDD and Testing Behavior

January 24, 2024

The importance of testing behavior when using test-driven development

Read More

When is it appropriate to use centralized orchestration versus event-driven choreography?

Read More

When defining a business problem and planning its solution, keep the two conversations separate...

Read More

Modern message brokers provide many important benefits to a distributed system...

Read More

Printable cheat sheets to help remember some of Uncle Bob's valuable contributions to the industry

Read More

Why Terraform?

December 25, 2019

Terraform leads the way in the infrastructure-as-code world...

Read More

I was looking for a quick and easy way to put together a personal static site and...

Read More

A few weeks ago, I decided to try Svelte's Sapper framework to handle the front-end of a simple app...

Read More

After years of consulting, I find myself continually coming back to three basic principles of system design...

Read More

In this fifth and final part of the Go middleware tutorial series, we'll use what we've learned to create a more structured API example...

Read More

Go Middleware - Part 4

February 24, 2019

In this fourth part of the Go middleware tutorial series, we'll discuss passing custom state along the request chain.

Read More

Go Middleware - Part 3

February 15, 2019

In this third part of the Go middleware tutorial series, we'll quickly look at a common variant on the recursive middleware implementation from part 2.

Read More

Go Middleware - Part 2

February 9, 2019

In this second part of the Go middleware tutorial series, we'll cover a recursive approach that provides a couple benefits beyond the simple loop chain example from part 1.

Read More

Go Middleware - Part 1

February 6, 2019

This is the first in a series of simple tutorials explaining the usage of HTTP middleware in Go.

Read More

How do we manage the architectural complexity that inevitably arises from using cloud services?

Read More

This Old Blog

January 20, 2019

I've decided to resurrect this old blog to publish some nuggets about software architecture and development, and perhaps...

Read More

Drupal 6 Theme Info Error

September 14, 2011

Recently one of my client sites had an issue where the custom theme info was corrupted...

Read More

Here's a slight modification to the handy Google Bookmarks Bookmarklet...

Read More

While building a Drupal site for one of my clients, I was having a heck of a time integrating...

Read More