自建DNS服务器

自建DNS服务器

1. 使用bind搭建内网DNS服务器



#!/bin/bash

yum install -y bind bind-utils bind-chroot

sed -i 's:127.0.0.1:any:g' /etc/named.conf
sed -i 's:localhost:any:g' /etc/named.conf

# dig > /var/named/named.ca
curl ftp://ftp.rs.internic.net/domain/named.cache > /var/named/named.ca

/sbin/iptables -I INPUT -p tcp --dport 53 -j ACCEPT
/sbin/iptables -I INPUT -p udp --dport 53 -j ACCEPT

2. 自定义域名解析



chown named.named -R /var/named

setsebool -P named_write_master_zones on

zone "mogublog.net" IN {
    type master;
    file "named.mogublog.net";
    allow-update { 127.0.0.1; };
};

// named.mogublog.net

$TTL 1D
@   IN  SOA  mogublog.net. root.mogublog.net. (
                            0       ; serial
                            1D      ; refresh
                            1H      ; retry
                            1W      ; expire
                            3H )    ; minimum


@   IN  NS      ns.mogublog.net.
NS  IN  A       127.0.0.1
www IN  A       8.8.8.8

// update

[root@server named]# nsupdate
> server 127.0.0.1
> update add www.mogublog.net 86400 IN A 8.8.8.8
> send
> quit