设置dns

来源:互联网 发布:基因测序 知乎 编辑:程序博客网 时间:2024/04/30 07:59


webmin+bind 设置dns

安装过程如下:

# apt-get install bind9
安装完毕后,用命令whereis bind可以发现bind安装在/etc/bind目录下,进入/etc/bind目录,看到目录下有这些文件:
db.0
db.127
db.255
db.empty
db.local
db.rev
db.root
named.conf
named.conf.local
named.conf.options
rndc.key
其中的关键文件是named.conf,我们可以查看它的内容:
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the 
// structure of BIND configuration files in Debian, *BEFORE* you customize 
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local

include "/etc/bind/named.conf.options";

// prime the server with knowledge of the root servers
zone "." {
type hint;
file "/etc/bind/db.root";
};

// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912

zone "localhost" {
type master;
file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
type master;
file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
type master;
file "/etc/bind/db.255";
};

include "/etc/bind/named.conf.local";
我们注意到此文件include 两个文件"/etc/bind/named.conf.options"和 "/etc/bind/named.conf.local",此外是一些DNS解析区域及其记录文件。在此文件的注释里提示,如果要增加区域的话,可以编辑/etc/bind/named.conf.local。
文件/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 might need to uncomment the query-source
// directive below. Previous versions of BIND always asked
// questions using port 53, but BIND 8.1 and later use an unprivileged
// port by default.

// query-source address * port 53;

// 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.

// forwarders {
// 0.0.0.0;
// };

auth-nxdomain no; # conform to RFC1035

};

文件/etc/bind/named.conf.local的内容如下,基本没有内容:
//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
从以上内容可以看出,除DNS的本地域名外,其它部分已经正常。要增加本地域名解析只要编辑/etc/bind/named.conf.local,并增加相应记录文件即可。本目录下的其它文件不必更改。
这时可以作一些测试。笔者的测试环境如下:三台电脑,一台装debian,一台装redhat8,一台装win98,准备设置根域名为home,相应的域名与IP对应关系如下:
debian.home 192.168.10.103
win98.home 192.168.10.102
rh8.home 192.168.10.101
在安装DNS前,各台机子的DNS设置为202.101.98.54,这是福建省的域名服务器,各台电脑间的互访通过hosts文件解析。
在debian机子上,
/etc/resolve.conf的内容如下:
domain home.
nameserver 202.101.98.54
/etc/hosts的内容如下:
### etherconf DEBCONF AREA. DO NOT EDIT THIS AREA OR INSERT TEXT BEFORE IT.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
192.168.10.103 debian.home debian
### END OF DEBCONF AREA. PLACE YOUR EDITS BELOW; THEY WILL BE PRESERVED.
192.168.10.102 win98.home win98
192.168.10.101 winme.home winme
在redhat8电脑上的配置与此类似。
在win98电脑上建立的/windows/hosts文件内容如下:
192.168.10.103 debian.home debian
192.168.10.102 win98.home win98
192.168.10.101 winme.home winme
也就是说在使用DNS前,它们用域名访问internet或互访都是正常。但现在我们要安装DNS,所以必须先它们去掉,才能知道所安装的DNS是否正常。步骤如下:
在debian机子上,
修改/etc/resolve.conf的内容如下:
domain home.
nameserver 192.168.10.103
/etc/hosts的内容如下:
### etherconf DEBCONF AREA. DO NOT EDIT THIS AREA OR INSERT TEXT BEFORE IT.
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
192.168.10.103 debian.home debian
### END OF DEBCONF AREA. PLACE YOUR EDITS BELOW; THEY WILL BE PRESERVED.
在redhat8电脑上的配置与此类似。
在win98电脑上删除/windows/hosts文件。并打开控制面板,选网络,再选TCP/IP,在“首选DNS”里面,输入DNS为192.168.10.103,点击确定,重启电脑。
此时你会发现,三台电脑用域名互访不行了,但访问internet上的域名,比如www.linuxsir.com都可以。因此接下来的步骤是增加本地域名解析,即编辑/etc/bind/named.conf.local,并增加相应记录文件。方法我推荐使用webmin-bind。当然如果你对记录文件格式很熟悉的话,可以手工编辑。我开始是采用手工编辑,浪费很多时间,直到我发现了webmin-bind。
#apt-get install webmin webmin-bind
安装完成后,在游览器的URL里输入https://localhost:10000/,输入用户名及密码进入webmin,即可看到BIND DNS服务器,点击进入,点击创建主区域,在出现的新建主区域选项中的区域类型单选框选正向(名称至地址),在域名 / 网络编辑框中输入home,在主服务器编辑框中输入debian.home,在Email 地址编辑框中输入root.debian.home,其它按默认。点击保存。再点击home主区域,点击地址,增加三条地址记录。
再次点击创建主区域,在出现的新建主区域选项中的区域类型单选框选反向(地址至名称),在域名 / 网络编辑框中输入192.168.10,在主服务器编辑框中输入debian.home,在Email 地址编辑框中输入root.debian.home,其它按默认。点击保存。再点击192.168.10主区域,点击反向地址,增加三条地址记录。
单击启动名字服务器按钮运行 BIND 服务器, 并装载当前配置。这样就完成了增加本地域名解析的工作,DNS也大功告成了。可以在各台电脑上测试一下,用域名访问internet或互访都不成问题。
但我们需要进一步知道webmin-bind作了哪些修改。
这时的/etc/bind/named.conf的内容如下:
// This is the primary configuration file for the BIND DNS server named.
//
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the 
// structure of BIND configuration files in Debian, *BEFORE* you customize 
// this configuration file.
//
// If you are just adding zones, please do that in /etc/bind/named.conf.local

include "/etc/bind/named.conf.options";

// prime the server with knowledge of the root servers
zone "." {
type hint;
file "/etc/bind/db.root";
};

// be authoritative for the localhost forward and reverse zones, and for
// broadcast zones as per RFC 1912

zone "localhost" {
type master;
file "/etc/bind/db.local";
};

zone "127.in-addr.arpa" {
type master;
file "/etc/bind/db.127";
};

zone "0.in-addr.arpa" {
type master;
file "/etc/bind/db.0";
};

zone "255.in-addr.arpa" {
type master;
file "/etc/bind/db.255";
};

include "/etc/bind/named.conf.local";
zone "home" {
type master;
file "/var/cache/bind/home.hosts";
};

zone "10.168.192.in-addr.arpa" {
type master;
file "/var/cache/bind/192.168.10.rev";
};
我们可以发现只是末尾增加了两个zone。而且在/etc/bind/目录下的其它文件都没有改动,我们可以从文件的修改时间看出。增加的两个记录文件是/var/cache/bind/home.hosts,/var/cache/bind/192.168.10.rev。
它们的内容如下:
/var/cache/bind/home.hosts的内容如下:
$ttl 38400
home. IN SOA debian.home. root.debian.home. (
1039102090
10800
3600
604800
38400 )
home. IN NS debian.home.
debian.home. IN A 192.168.10.103
rh8.home. IN A 192.168.10.101
win98.home. IN A 192.168.10.102
/var/cache/bind/192.168.10.rev的内容如下:
$ttl 38400
10.168.192.in-addr.arpa. IN SOA debian.home. root.debian.home. (
1039102453
10800
3600
604800
38400 )
10.168.192.in-addr.arpa. IN NS debian.home.
101.10.168.192.in-addr.arpa. IN PTR rh8.home.
102.10.168.192.in-addr.arpa. IN PTR win98.home.
103.10.168.192.in-addr.arpa. IN PTR debian.home.

这些格式与网上很多文章介绍的有些不同,所以我才想写出来,希望其它初学者不要象我一样,一头雾水好几天。

DNS设置完了后,如果不能保证DNS机子一直开着,可以在其它机子上加上其它DNS,比如202.101.98.54。以免 本地DNS机子关机的时候,不能通过域名访问internet。

webmin设置dns

系统redhat 9
dns: bind 9.2.1(系统自带)
webmin: 1.240   [url]http://www.webmin.com[/url]

安装好系统和DNS服务后.

在系统设置--服务--里打开named服务,并设置为系统自动运行.

1.安装webmin
  tar -xzvf webmin1-240.tar.gz
  cd webmin1-240
  ./setup.sh /usr/local/webmin
  按照提示一步一步安装下去就可.

2.配置DNS.以jesse.com为例

  找开 servers--bind dns server
create master zone options
  zone type forward(name to address)
  domain name   ::jesse.com.
  master server :: jesse.com.
  email address :: [email]root@jesse.com[/email]
  use zone template  ::no  192.168.1.13

  在 jesse.com master zone中
  address 添加
  name ::jesse.com.    address :: 192.168.1.13
  name ::[url]www.jesse.com.[/url]    address :: 192.168.1.13
  name ::mail.jesse.com.    address :: 192.168.1.13

  mail server 中添加 ----创建邮件服务器
  mail server ::mail.jesse.com  priority ::5

jesse.com zone这样就可以了


  再创建192.168.1 zone
create master zone 
  zone type reverse (address to name)
  domain name/network :: 192.168.1
  master server :: jesse.com.
  email address :: [email]root@jesse.com[/email]
  use zone template  ::no  192.168.1.13

  在 192.168.1 zone 中
  reverse address 添加
  address ::192.168.1.13  hostname ::jesse.com.
  address ::192.168.1.13  hostname ::[url]www.jesse.com.[/url]
  address ::192.168.1.13  hostname ::mail.jesse.com.

到此域名在局域网基本可以测试使用了。

DNS服务器既可以是主控服务器也可以是辅助服务器.主控服务器也称为主服务器,是判定域名的最终来源,主控服务器同时也是传送到辅助服务器的区传送(zone transfer)的源头,辅助服务器接收所有来自主控服务器的区信息.当有两种类型的服务器时,主控服务器也可以同时担当其他域的辅助服务器.


以下是主域名服务器的named.conf 文件的配置示例.


options { 
notify-source 10.0.0.2; // 指明服务器把区变动通知(NOTIFY)消息发送到什么地方,
//当主控服务器检测到区数据库文件发生变动时就会向辅助
//服务器发出这样的消息
pid-file "/var/run/named.pid"; //本选项只是告诉守护进程(daemon)服务器写入ID信
//息的路径,通常是/var/run/named.pid,也可重新设置
}; 
zone "." { //第一个区登记项用来通知BIND在何处定位根服务器的信息
type master; //服务器发送和接收的不仅是你自己的域信息同时也包括Internet上
file "root.db"; //所有的域信息.并不是每个服务器上都有每个域名的登记项,但每个
//服务器都知道怎样获取信息 
}; 
zone "example.com" { //第二个区登记项是一个"主控"域项,意思是这个DNS服务器
type master; //保存着example.com的有效信息, Internet上其他所有的DNS
file "/var/named/sample.com.zone"; //服务器都将用它来参照任何与这个域相关的
//信息.Example.com项引用/var/named/sample.com.zone这个文件.
}; 
/var/named/sample.com.zone是一个纯文本文件,它告诉DNS服务器所有有关example.com的信息,包括serial值,刷新率,所有的DNS纪录以及其他一些项目.
DNS服务器有多种可用的选项,如果需要某种特殊的配置,读好读一遍附带的文档.
以下是 /var/named/sample.com.zone文件的内容:
@ IN SOA ns1.sample.com. ( // SOA是Start of Authority的缩写,所有区文件 
//都要以它打头
200101111 ;serial // 每更新一次该文件要修改这个数字,加1
14400 ;refresh after 4 hours // 下面四行以秒的形式处理刷新和超时周期,如
3600 ;retry after 1 hour //果BIND数据库没有发生过人工或者服务器范围的刷
604800 ;expire after 1 week //新,服务器会自动的重新读入信息.不需要经常改变
86400) ;minimum TTL of 1 day //此处所列出的数值,只有由于某种原因或非常频繁地
//改变它们的信息时才需要对这些数值进行更改.
;Nameservers 
IN NS ns1.sample.com. ; //这个域的域名主域名服务器
IN NS ns2.sample.com. ; //这个域的域名备份域名服务器
;Domain Mail Handlers ; 
sample.com. IN MX 10 mail //这是MX纪录,指出邮件服务器的信息.
//mail.samle.com的优先级是10.可以列出多个MX
//记录作为邮件服务器的备份.//数字越小优先级越高. 
;Hosts in order ; 
www IN A 212.204.219.71 //A纪录给出了mail.sample.com的IP地址,这是必要的,
ftp IN A 212.204.219.71 //给每个主机名解析成一个IP地址.必须用上面的格式
mail IN A 212.204.219.71 //这样写后当某个用户请求
www.sample.com时,他将会被
//指向该域所在的Web服务器的IP地址212.104.219.71. 
pop IN CNAME mail //CNAME是指canonical name,用于指定IP地址的别名,
//使用这些别名时还要参考已经使用过的A纪录.


次域名服务器的named.conf配置
zone "sample2.com" { 
type slave; 
file "/var/named/sample2.com.zone"; 
master { 10.0.0.1; };


主域名服务器和次域名服务器最主要的两个区别有两个,一个是type项,它既可以是master也可以使slave,二是IP地址指定的是主控DNS服务器.其他的都和Master项相同. 


0 0