• DNS简单搭建


    一、安装服务

    设置主机名

    [root@localhost named]# hostnamectl set-hostname k1.kk.cn
    [root@localhost named]# bash
    [root@k1 named]# hostname
    k1.kk.cn

    安装软件包

    [root@localhost ~]# yum install -y bind*

    二、编辑配置文件

    全局配置选项options

    listen-on port 53 { 127.0.0.1; };   IP改为服务器IP,我这是192.168.22.77

    allow-query     { localhost; };    localhost改为允许的网段,any为所有

    [root@localhost named]# vim /etc/named.conf
    
    options {
            listen-on port 53 { 192.168.22.77; };
            listen-on-v6 port 53 { ::1; };
            directory       "/var/named";
            dump-file       "/var/named/data/cache_dump.db";
            statistics-file "/var/named/data/named_stats.txt";
            memstatistics-file "/var/named/data/named_mem_stats.txt";
            allow-query     { any; };

    写入正反向配置

    [root@localhost named]# vim /etc/named.conf 
    
    zone "kk.cn" IN {
            type master;
            file "kk.a.zone";
    };
    
    zone "22.168.192.in-addr.arpa" IN {
            type master;
            file "kk.b.zone";
    };

    编辑正向配置文件

    [root@localhost ~]# cd /var/named/
    [root@localhost named]# cp -p named.localhost kk.a.zone
    $TTL 1D
    @       IN SOA  kk.cn. root.k2.kk.cn. (
                                            0       ; serial
                                            1D      ; refresh
                                            1H      ; retry
                                            1W      ; expire
                                            3H )    ; minimum
            NS      k2.kk.cn.
    k2      A       192.168.22.77
    k1      A       192.168.22.21

    正向批量操作

    #在最后面添加
    $GENERATE 1-30 k$ A 192.168.22.$
    $GENERATE 1-30 k$ CNAME k$

    编辑反向配置文件

    [root@localhost named]# vim kk.b.zone 
    $TTL 1D
    @       IN SOA  kk.cn. root.k2.kk.cn. (
                                            0       ; serial
                                            1D      ; refresh
                                            1H      ; retry
                                            1W      ; expire
                                            3H )    ; minimum
            NS      k2.kk.cn.
    77      PTR     k2.kk.cn.
    21      PTR     k1.kk.cn.

    反向批量操作

    #在最后面添加
    $GENERATE 1-30 $ PTR k$.kk.cn

    三、重启DNS服务

    [root@localhost named]# systemctl restart named

    四、配置网卡的DNS

    配置DNS1=服务器IP地址

    我这为192.168.22.21

    [root@localhost named]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 
    TYPE=Ethernet
    BOOTPROTO=static
    NAME=ens33
    UUID=727a9a45-718b-45bc-a13c-e6f5c35ab721
    DEVICE=ens33
    ONBOOT=yes
    IPADDR=192.168.22.21
    NETMASK=255.255.255.0
    GATEWAY=192.168.22.2
    DNS1=192.168.22.21

    重启网卡服务

    [root@localhost named]# systemctl restart network

    五、测试

    [root@localhost named]# nslookup 
    > 192.168.22.21
    Server:        192.168.22.77
    Address:    192.168.22.77#53
    
    21.22.168.192.in-addr.arpa    name = k1.kk.cn.
    > k1.kk.cn    
    Server:        192.168.22.77
    Address:    192.168.22.77#53
    
    Name:    k1.kk.cn
    Address: 192.168.0.1
    Name:    k1.kk.cn
    Address: 192.168.22.21
    > ^C[root@localhost named]# nslookup 
    > 192.168.22.21
    Server:        192.168.22.77
    Address:    192.168.22.77#53
    
    21.22.168.192.in-addr.arpa    name = k1.kk.cn.
    > 192.168.22.77
    Server:        192.168.22.77
    Address:    192.168.22.77#53
    
    77.22.168.192.in-addr.arpa    name = k2.kk.cn.
    > k1.kk.cn
    Server:        192.168.22.77
    Address:    192.168.22.77#53
    
    Name:    k1.kk.cn
    Address: 192.168.0.1
    Name:    k1.kk.cn
    Address: 192.168.22.21
    > k2.kk.cn    
    Server:        192.168.22.77
    Address:    192.168.22.77#53
    
    Name:    k2.kk.cn
    Address: 192.168.0.2
    Name:    k2.kk.cn
    Address: 192.168.22.77

    六、附录

    待添加

  • 相关阅读:
    我总结的面试题系列:kafka
    RabbitMQ大厂面试题
    [Algorithm] 并查集
    [LintCode] 编辑距离
    [LeetCode] Length of Longest Fibonacci Subsequence
    [LintCode] 交叉字符串
    [LeetCode] Permutation Sequence
    Permutation Sequence
    [LeetCode] Next Permutation
    [LeetCode] Longest Palindromic Substring
  • 原文地址:https://www.cnblogs.com/kklinux/p/dns_peizhi.html
Copyright © 2020-2023  润新知