Ubuntu搭建DNS服务器
Ubuntu搭建DNS服务器
下载bind9
执行如下命令
apt-get install bind9
编辑bind9配置文件
找到
/etc/bind/name.conf.default-zones
文件
并在末尾添加zone "www.domainname.com" { type master; file "/etc/bind/db.ip2domainname.com"; }; zone "jkl.ghi.def.abc.in-addr.arpa" { type master; file "/etc/bind/db.domainname2ip"; };
其中
jkl.ghi.def.abc
为服务器ip的反写- 然后在
/etc/bind
中创建db.ip2domainname.com
文件和db.domainname2ip
文件,注意这两个文件名要和name.conf.default-zones
中配置的file相同 然后在
db.ip2domainname.com
文件中填写如下内容; ; BIND data file for local loopback interface ; $TTL 604800 @ IN SOA ns.www.domainname.com. root.www.domainname.com. ( 2 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS ns.www.domainname.com. @ IN A abc.def.ghi.jkl ns IN A abc.def.ghi.jkl cn IN A abc.def.ghi.jkl
注意:需要把下面的
www.domainname.com
换成你的域名,不要漏掉了域名后面的小数点,abc.def.ghi.jkl
是www.domainname.com
服务器的ip,需要替换成你自己的。然后在
db.domainname2ip
文件中填写如下内容,同样要替换www.domainname.com
为你的域名。100是www.domainname.com
服务器的ip的最后一段,需要替换成你自己的。; ; BIND reverse data file for local loopback interface ; $TTL 604800 @ IN SOA ns.www.domainname.com. root.www.domainname.com. ( 1 ; Serial 604800 ; Refresh 86400 ; Retry 2419200 ; Expire 604800 ) ; Negative Cache TTL ; @ IN NS www.domainname.com. 1.0.0 IN PTR cn.domainname.com. 100 IN PTR domainname.com. 100 IN PTR www.domainname.com. 100 IN PTR dns.domainname.com. 100 IN PTR cn.domainname.com.
然后修改
/etc/bind/named.conf.options
文件为如下内容options { directory "/var/cache/bind"; // If there is a firewall between you and nameservers you want // to talk to,you may need to fix the firewall to allow multiple // ports to talk. See http://www.kb.cert.org/vuls/id/800113 // If your ISP provided one or more IP addresses for stable // nameservers,you probably want to use them as forwarders. // Uncomment the following block,and insert the addresses replacing // the all-0's placeholder. //forward first; forwarders { 223.5.5.5; 223.6.6.6; }; //======================================================================== // If BIND logs error messages about the root key being expired, // you will need to update your keys. See https://www.isc.org/bind-keys //======================================================================== listen-on{ any; }; recursion yes; allow-query { any; }; };
- 然后执行
service bind9 restart
重启bind9 DNS服务器 - 接下来还需要修改路由器配置,把DNS服务器ip换成自己搭建的DNS服务器的ip即可
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。