美文网首页
Bind源码安装

Bind源码安装

作者: 袁先生的笔记 | 来源:发表于2017-04-26 20:11 被阅读0次

    环境

    系统:CentOS 6.6
    软件:bind-9.10.2.tar.gz
    域名:yourdomain.com
    网段:192.168.10.0/24
    DNS服务器:dns1.yourdomain.com 192.168.10.10

    准备

    • 安装依赖包
    # yum -y install gcc openssl-devel perl-devel
    

    bind编译安装

    • 下载源码包
      地址:https://www.isc.org/downloads/bind/

    • 编译安装

      # tar -zxvf bind-9.10.2.tar.gz
      # cd bind-9.10.2
      
      # ./configure --prefix=/usr/local/named \
      --sysconfdir=/etc/named \
      --enable-threads \
      --enable-epoll \
      --disable-ipv6 \
      --disable-chroot \
      --enable-backtrace \
      --enable-symtable
      
      # make
      # make install
      
    • 配置环境变量

      # vim /etc/profile
      export PATH=/usr/local/named/sbin:/usr/local/named/bin:$PATH
      
      # source /etc/profile
      

    bind配置

    • 生成rndc控制命令的key

      # /usr/local/named/sbin/rndc-confgen > /etc/named/rndc.conf
      # tail -n 10 /etc/named/rndc.conf | head -n 9 | sed 's/#\ //g' > /etc/named/named.conf
      
    • 编辑配置文件

    # vim /etc/named/named.conf
    ......
    options {
            directory       "/data/named";
            pid-file        "/usr/local/named/var/run/named.pid";
            allow-query     { any; };
            recursion       yes;
            notify          yes;
            forwarders      { 202.106.0.20; };
            forward         first;
    };
    
    zone "." IN {
            type    hint;
            file    "db.ca";
    };
    
    zone "yourdomain.com" IN {
            type    master;
            file    "db.yourdomain.com";
    };
    
    
    zone "10.168.192.in-addr.arpa" IN {
            type    master;
            file    "db.192.168.10";
    };
    
    logging{
            channel named.log {
            file            "/var/log/named/named.log" versions 5 size 20m;
            severity        info;
            print-time      yes;
            print-severity  yes;
            print-category  yes;
            };
            category default {
            named.log;
            };
            category lame-servers {
            null;
            };
    };
    
    • 创建所需用户、目录
    # useradd -c "BIND Ower" -s /sbin/nologin named
    # mkdir -p /data/named
    # mkdir -p /var/log/named
    # chown -R named:named /etc/named /usr/local/named /data/named /var/log/named
    

    解析文件配置

    • 创建根解析文件
    # dig > /data/named/db.ca
    
    • 创建yourdomain.com域正向解析文件
    #vim /data/named/db.yourdomain.com
    $TTL    86400
    @                       IN      SOA     dns1.yourdomain.com.    root.localhost. (
                                                                                    2017042011      ;Serial
                                                                                    3H              ;Refresh
                                                                                    15M             ;Retry
                                                                                    1W              ;Expiry
                                                                                    1D )            ;Minimum
    @                       IN      NS      dns1.yourdomain.com.
    
    dns1                    IN      A       192.168.10.10
    mail                    IN      A       192.168.10.11
    www                     IN      A       192.168.10.12
    dell                    IN      CNAME   www
    
    • 创建192.168.10.0/24网段反向解析文件
    # vim /var/named/db.192.168.10
    $TTL    86400
    @       IN      SOA     dns1.yourdomain.com.    root.localhost. (
                                                                    2017042011      ;Serial
                                                                    3H              ;Refresh
                                                                    15M             ;Retry
                                                                    1W              ;Expiry
                                                                    1D )            ;Minimum
    @       IN      NS      dns1.yourdomain.com.
    
    10      IN      PTR     dns1.yourdomain.com.
    11      IN      PTR     mail.yourdomain.com.
    12      IN      PTR     www.yourdomain.com.
    12      IN      PTR     dell.yourdomain.com.
    
    • 检查解析文件
    # /usr/local/named/sbin/named-checkzone yourdomain.com /data/named/db.yourdomain.com
    
    • 检查配置文件
    # /usr/local/named/sbin/named-checkconf /etc/named/named.conf
    

    bind开机启动

    • 编写开机启动脚本
    # vim /etc/init.d/named
    #!/bin/bash
    # named
    # This shell script takes care of starting and stopping
    # named (BIND DNS server).
    # chkconfig: - 13 87
    # description: named (BIND) is a Domain Name Server (DNS) \
    # that is used to resolve host names to IP addresses.
    # probe: true
    # Source function library.
    . /etc/rc.d/init.d/functions
    # Source networking configuration.
    [ -r /etc/sysconfig/network ] && . /etc/sysconfig/network
    user=named
    named=named
    named_conf="/etc/named/named.conf"
    ROOTDIR="/usr/local/named"
    CHKCONF="$ROOTDIR/sbin/named-checkconf"
    CHKZONE="$ROOTDIR/sbin/named-checkzone"
    RNDC="$ROOTDIR/sbin/rndc"
    
    start() {
                    echo -n $"Starting $named: "
            if [ -n "`/sbin/pidof -o %PPID $named`" ]; then
                    echo -n $"$named: already running"
                    failure
                    echo
                    return 1
            fi
    
            conf_ok=0;
            if [ -x $CHKCONF ] && [ -x $CHKZONE ] && $CHKCONF ${named_conf} >/dev/null 2>&1; then
               conf_ok=1;
            else
               RETVAL=$?;
            fi
            if [ $conf_ok -eq 1 ]; then
               daemon $ROOTDIR/sbin/$named -u $user ;
    #           daemon $ROOTDIR/sbin/$named -c $named_conf  &
               RETVAL=$?;
               [ $RETVAL -eq 0 ] && touch /var/lock/subsys/named
               echo
              return $RETVAL
            fi
    }
    
    stop() {
           # Stop daemons.
            echo -n $"Stopping $named: "
            $RNDC stop >/dev/null 2>&1
            RETVAL=$?
            [ "$RETVAL" -eq 0 ] || killproc "$named" -TERM >/dev/null 2>&1
    
            if [ $RETVAL -eq 0 ]; then
                rm -f /var/lock/subsys/named &> /dev/null
                rm -f $ROOTDIR/var/run/named.pid &> /dev/null
            fi;
    
            if [ $RETVAL -eq 0 ]; then
                success
            else
                failure
            fi;
            echo
            return $RETVAL
    }
    
    restart() {
            stop
            sleep 2
            start
    }
    
    status() {
           $RNDC status
    #        status $ROOTDIR/sbin/$named
            return $?
    }
    
    reload() {
            echo -n $"Reloading $named: "
            p=`/sbin/pidof -o %PPID $named`
            RETVAL=$?
            if [ "$RETVAL" -eq 0 ]; then
               $RNDC reload >/dev/null 2>&1 || /bin/kill -HUP $p;
                RETVAL=$?
            fi
           [ "$RETVAL" -eq 0 ] && success $"$named reload" || failure $"$named reload"
            echo
            return $RETVAL
    }
    
    checkconfig() {
            if [ -x $CHKCONF ] && [ -x $CHKZONE ] && $CHKCONF ${named_conf}  ; then
                return 0;
            else
                return 1;
            fi
    }
    
    case "$1" in
            start)
                   start
                    ;;
            stop)
                    stop
                    ;;
            status)
                    status
                    ;;
            restart)
                    restart
                    ;;
            reload)
                    reload
                    ;;
            checkconfig|configtest|check|test)
                    checkconfig
                    ;;
            *)
                    echo $"Usage: $0 {start|stop|status|restart|condrestart|reload|configtest|probe}"
                    exit 2
                    ;;
    esac
    
    exit $?
    
    • 添加开机启动
    # chmod +x /etc/init.d/named
    # chkconfig --add named
    # chkconfig named on
    # service named start
    

    相关文章

      网友评论

          本文标题:Bind源码安装

          本文链接:https://www.haomeiwen.com/subject/gfswzttx.html