Install, configure and administer BIND 9 on Debian Whezzy

BINDBIND (Berkeley Internet Name Domain) is the most used DNS software over the Internet. The BIND package is available for all Linux distributions, which makes the installation simple and straightforward. In today’s article we will show you how to install, configure and administer BIND 9 on a Debian VPS.



The installation is very simple and easy, login to your server via SSH and run:

apt-get install bind9


Open the /etc/bind/named.conf.options file and add the following lines on the top of the file.

acl trusted {;

and in the options block add :

allow-recursion    {trusted; };

Restart the service

service bind9 restart


The following script can be used to create new DNS zone files.

#!/usr/bin/env bash
# Create Zone file

# Variables
SERIAL=$(date +"%Y%m%d")01

# Functions
ok() { echo -e '\e[32m'$1'\e[m'; } # Green

error() { echo -e '\e[1;31m'$1'\e[m'; } # Red

usage () {
  ok "[*] Usage: $0 [ -i ip ] [ -d domain ] [ -h ]"

# Sanity check
if [[ $EUID -ne 0 ]]
    error "[*] Script must be run as root"

# Get arguments
while getopts ":hd:i:" option; do
  case "$option" in
    d)  DOMAIN="$OPTARG" ;;
    i)  IP="$OPTARG" ;;
    h)  usage
        exit 0 
    :)  error "[*] Error: -$OPTARG requires an argument" 
        exit 1
    ?)  error "[*] Error: unknown option -$OPTARG" 
        exit 1

if [[ -z "$DOMAIN" || -z "$IP" ]]; then
  error "[*] Error: you must specify a Domain Name using -d and IP Address using -i"
  exit 1

# Create zones directory
mkdir -p $ZONE_DIR

# Check if exist
grep "zone \"${DOMAIN}\"" ${BIND_LOCAL} > /dev/null

if [[ 0 -eq $? ]]
  error "[*] Error: ${DOMAIN} is already added!" >&2
  exit 1

# Create zone file
  cat > ${ZONE_DIR}db.${DOMAIN} << _EOF_
\$TTL 86400;    expire in 1 day.
@       IN      SOA     ${NAME_SERVER_1}. admin.${DOMAIN}. (
                        ${SERIAL}      ; serial
                        10800           ; Refresh
                        3600            ; Retry
                        604800          ; Expire
                        300             ; Negative Response TTL

; DNS Servers
@               IN      NS      ${NAME_SERVER_1}.
@               IN      NS      ${NAME_SERVER_2}.

; A Records
@               IN      A       ${IP}
localhost       IN      A
host            IN      A       ${IP}
mail            IN      A       ${IP}

; MX Records
@               IN      MX 10   ${DOMAIN}.
@               IN      MX 20   mail.${DOMAIN}.

; TXT Records
@               IN      TXT     "v=spf1 a mx -all"

; Aliases
ftp             IN      CNAME   ${DOMAIN}.

# Add record
  cat >> ${BIND_LOCAL} << _EOF_

zone "${DOMAIN}" {
type master;
file "${ZONE_DIR}db.${DOMAIN}";

ok "${DOMAIN} has been successfully added."

These instructions should work on any Debian based distribution such as Ubuntu, Mint, Elementary OS and others.

Of course you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

1 thought on “Install, configure and administer BIND 9 on Debian Whezzy”

  1. I really enjoyed the article. Recommended. I wonder if you can do an article on reverse zone, in this way, with administration script.
    Now, appreciate the attention.


Leave a Comment

To prove you are human please solve the following *