例: 更改dns配置

说明:向w99.com的正向区域内添加一条主机(A)记录,向w99.com的反向区域文件中添加一条指针(FTR)记录

______________________________________________________________________________________

#!/bin/bash

domain="w99.com"
forward_zone="/var/named/w99.com.zone"
rev_zone="/var/named/w99.com.rev"

# This function requires that the serial number be on
# a line by itself and followed by " ;serial"

increment_serial() {
  [ -w "$1" ] || {
  echo "File $1 doesn't exist or is not writable!" >&2
  return
  }
  awk '/; serial/ {print " " $1+1 " ; serial"} \
  !/; serial/ {print $0}' "$1" > "$1.tmp" && \
  mv "$1.tmp" "$1"
}

# First, increment the serial numbers
increment_serial "$forward_zone"
increment_serial "$rev_zone"

new_hostname="amaz"
ip_address="334.16.27.39"

# Determine reversed-ip
rev_ip=`echo "$ip_address" | sed 's/^\(.*\)\.\(.*\)\.\(.*\)\.\(.*\)$/\4.\3.\2.\1.in-addr.arpa./'`

# Now, add new entries
echo "$new_hostname.$domain. IN A $ip_address" >> "$forward_zone"
echo "$rev_ip IN PTR $new_hostname.$domain." >> "$rev_zone"

echo "DNS entries created for $new_hostname ($ip_address)" >&2

# Indicate success on STDOUT
echo "true;"
exit 0