我尝试使用 Bind 在 Ubuntu 服务器上设置并运行自己的 DNS。假设我的主机名是 example.com,服务器上的静态 IP 是 100.100.100.100,如果我dig example.com
在本地执行以下命令,将获得以下结果:
; <<>> DiG 9.9.5-3ubuntu0.4-Ubuntu <<>> example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 34962
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 3, ADDITIONAL: 3
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;example.com. IN A
;; ANSWER SECTION:
example.com. 38400 IN A 100.100.100.100
;; AUTHORITY SECTION:
example.com. 38400 IN NS example.com.
example.com. 38400 IN NS ns1.example.com.
example.com. 38400 IN NS ns2.example.com.
;; ADDITIONAL SECTION:
ns1.example.com. 38400 IN A 100.100.100.100
ns2.example.com. 38400 IN A 100.100.100.100
;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Thu Aug 13 09:59:37 BST 2015
;; MSG SIZE rcvd: 141
此外,如果我写了,host example.com
我会得到以下信息:
host example.com example.com has address 100.100.100.100
example.com mail is handled by 10 webmail.example.com.
如下/etc/bind/named.conf.local
:
zone "example.com" {
type master;
file "/var/lib/bind/example.com.hosts";
notify yes;
}
是/etc/bind/named.conf
:
include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";
显然,我在 72 小时前就更新了域名提供商的 DNS 记录。此外,traceroute 和 ping 都适用于外部地址,例如 8.8.8.8,我可以通过浏览器访问静态 IP,但不能访问 example.com。
知道如何才能使 DNS 为全球所知吗?
答案1
我的答案更符合问题……
您需要定义一个区域,将您的名称服务器声明为主服务器,以便它向其他服务器提供答案,因此您至少需要一行:type master;在该区域内。
这是我在服务器的 /etc/bind/named.conf.local 中的内容(于 14:04LTS),只不过我的文件在最后一个视图中实际上有“notify no;”,但我相信您需要“notify yes;”才能发布数据。
#
# Do any local configuration here
#
#
# Consider adding the 1918 zones here, if they are not used in your
# organization
include "/etc/bind/zones.rfc1918";
acl masters {
# 195.62.28.14 # ns1.tsohost.co.uk;
# 194.142.155.4 # ns2.tsohost.co.uk;
# 95.142.154.15 # ns3.tsohost.co.uk;
};
acl internals {
127.0.0.0/8; # IPv4 localhost/loopback
10.0.0.0/24; # IPv4 localnel
#::1/128; # IPv6 localhost/loopback
#fe80::/10; # IPv6 link-local
# fec0::/10; # IPv6 site-local ... deprecated
};
view "internal" {
match-clients { internals; };
recursion yes;
zone "gscott.co.uk" {
type master;
file "/etc/bind/internals/db.gscott.co.uk";
};
};
view "external" {
match-clients { any; };
# recursion no;
notify yes;
zone "gscott.co.uk" {
type master;
file "/etc/bind/externals/db.gscott.co.uk";
};
};
然后,您将需要区域文件本身,例如:
;
; gscott.co.uk
;
$TTL 604800
@ IN SOA gscott.co.uk gscott.gscott.co.uk (
201411282233 ; serial
604800 ; refresh
86400 ; Retry
2419200 ; Expire
604800) ; Negative cache TTL
;
@ IN NS ns1
IN MX 10 mail
barbican IN A 87.127.155.63 ; the outside world .. 'yer be dragons!
恕我直言,除非你真的想要做到这一点,快速的解决办法是很多更加简单,更加轻松。