Linux Bind 安装

Bind 安装(以下安装是以源码包为主)

安装包下载

rpm下载地址:https://pkgs.org/download/bind 输入Bind搜索,依赖bind-utils、bind-libs、bind-license

rpm安装时才需要安装依赖

rpm所有版本下载地址:
http://rpm.pbone.net/index.php3?stat=3&limit=1&srodzaj=1&dl=40&search=bind-9.9&field[]=1&field[]=2

tar所有版本下载地址:ftp://ftp.isc.org/isc

tar下载地址:https://ftp.isc.org/isc/bind9/9.15.1/bind-9.15.1.tar.gz

可视化管理插件:https://gitee.com/opendevops/codo-dns

解压安装包

tar xvfz bind-9.15.1.tar.gz 

如果你的 tar 命令不支持z选项(用于解压gz后缀的压缩包),你可以分两步做:

gunzip bind-9.3.0.tar.gz
tar xvf bind-9.3.0.tar

这样源代码就解压到bind-9.15.1目录中了。

编译安装

cd bind-9.15.1
./configure --prefix=/usr/local/named  --enable-threads

参数说明:

正像单词的意思一样,configure 是编译前对源代码进行针对具体操作系统的编译参数配置,有很多选项可以选

择,大家可以用 --help 选项来查看所有可用的选项,这里介绍几个最常用的选项:

参数名描述
–prefix=/usr/local/bind设置bind的安装目录,默认是/usr/local,有的人喜欢将bind安装在单独的目录就可 以如此设置
–sysconfdir=/etc/bind设置named.conf配置文件放置的目录,默认是"$prefix/etc"
–localstatdir=/var设置 run/named.pid 放置的目录,默认是"$prefix/var"
–with-libtool将BIND的库文件编译为动态共享库文件,这个选项默认是未选择的,如果不选这个选项,那么编译后的named命令会比较大,lib目录中的库文件都是.a后缀的,如果选上这个选项,那么编译后的named命令会很小,lib目录中的库文件则是.so后缀
–enable-threads如果你的系统有多个CPU,那么可以使用这个选项

如果 ./configure 没有报错的话,那么就可以开始编译源代码了。

执行  make

编译需要一小会时间,编译完成后则开始安装BIND,安装需要 root 用户权限,所以要先转换成root用户。

执行  make install

至此安装完成,执行以下命令查看。

cd /usr/local/named/sbin/
./named -v #查看版本

创建运行用户

#创建用户named用户,使用named用户运行dns

groupadd named  
useradd -g named -s /sbin/nologin named #设置不能登入

创建配置文件目录

mkdir /usr/local/named/zones        #保存dns zone配置文件的目录
mkdir /usr/local/named/log          #保存日志就新建这个目录
touch /usr/local/named/etc/named.conf #保存DNS配置文件

#配置主配置文件

cd /usr/local/named/etc/
/usr/local/named/sbin/rndc-confgen > rndc.conf
cat rndc.conf > rndc.key
chmod 777 /usr/local/named/zones/
tail -10 rndc.conf | head -9 | sed s/#\ //g > named.conf

#配置named.conf解析

ln -s /usr/local/named/etc/named.conf /etc/named.conf
vi /usr/local/named/etc/named.conf 

named.conf 内容说明:

#rndc控制密钥
key "rndc-key" {
	algorithm hmac-sha256;
	secret "c6iamWqbzArFvUn7BUt27c8MNUU+G9TkVz8ADbnXNRI=";
};

#服务监听端口
controls {
	inet 127.0.0.1 port 953
	allow { 127.0.0.1; } keys { "rndc-key"; };
};
#配置zone配置文件目录
options {
	directory "/usr/local/named/zones";
	pid-file "named.pid"; 
	rrset-order {order cyclic;};#轮询访问
};

#配置log日志服务
logging
{
	channel dnsquery.log
	{
		file "/usr/local/named/log/dnsquery.log" versions 3 size 10M;
		severity info;
		print-time yes;
	};
	category queries { dnsquery.log; };
};
view "internal"
{
  #配置根DNS服务器配置文件,以下配置中file的路径都是相对directory指定的路径,及必须放到directory目录下
	zone "." {#可不配做
       type hint;
       file "named.root";#根 dns 服务器的信息
       #下载地址ftp://ftp.rs.internic.net/domain/named.cache named.cache 重命名为 named.root
	};
	zone "localhost" IN{#本地解析,可不配做
		type master;
        file "localhost.zone";
		allow-update {none;};
	};
	zone "0.0.127.in-addr.arpa" IN{#可不配做
		type master;
       file "localhost.local";
		allow-update {none;};
	};
	zone "keeplived.com" IN{
		type master;
       file "keeplived.zone";
		allow-update {none;};
    };
    zone "shiny.com" IN{#正向解析
		type master;
       file "shiny.zone";
		allow-update {none;};
    };
    zone "192.168.1.in-addr.arpa" IN{#反向解析,一般是邮箱才需要配置反向解析
		type master;
		file "shiny.local";
		allow-update {none;};
    };
};

#localhost.zone 正向解析配置
$TTL 86400
@       IN      SOA     localhost.      admin.localhost.(
                        2019061701
                        1H
                        5M
                        7D
                        1D )
        IN      NS      localhost.
localhost.      IN      A       127.0.0.1

#localhost.local 反向解析配置
$TTL 86400
@       IN      SOA     localhost.      admin.localhost.(
                        2019061701
                        1H
                        5M
                        7D
                        1D )
        IN      NS      localhost.
1       IN      PTR     localhost.

#shiny.zone正向解析配置
#admin.163.com 为邮箱,随意指定一个,@为本域,即shiny.com 
$TTL 7200
@       IN      SOA     shiny.com.      admin.163.com.(
                        2019061701
                        1H
                        5M
                        7D
                        1D )
@       IN      NS      www.shiny.com.
www     IN      A       192.168.1.221
        IN      A       192.168.1.222 #一个域名对应多个地址(可以实现负载,ttl设置成1 或者 0)

#shiny.local反向解析配置(根据需要进行配置,一般是邮箱服务才需要)
$TTL 7200
@       IN      SOA     192.168.1.in-addr.arpa.      admin.163.com.(
                        2019061701
                        1H
                        5M
                        7D
                        1D )
@       IN      NS      www.shiny.com.
221     IN      PTR     www.shiny.com.
222     IN      PTR     www.shiny.com.

#授予named访问权限

chown -R named:named /usr/local/named

运行DNS服务

/usr/local/named/sbin/named -g -u named & #-g 打印启动日志 -u 指定用户
tail -f /var/log/message #查看启动日志
/usr/local/named/sbin/named restart #重启服务
/usr/local/named/sbin/rndc status #检查DNS服务器运行状态
dig 域名 #查看域名解析是否成功
#更改配置时可以通过reload及时生效
/usr/local/named/sbin/rndc reload

Linux DNS配置

vi /etc/resolv.conf
nameserver 域名服务器地址

resolv.conf的关键字主要有四个,分别是:
nameserver //定义DNS服务器的IP地址
domain //定义本地域名
search //定义域名的搜索列表
sortlist //对返回的域名进行排序

#Window刷新本地域名缓存,Linux无需刷新
ipconfig /flushdns #当服务器域名对应IP调整后,如果要马上生效,客户端需要刷新缓存

#域配置项说明

配置项说明
TTLtime to live 生存时间,默认为秒
@表示相应的域名,表示一个域名定义的开始这里代表gr.org
IN表示后面的数据使用的是INTERNET标准
SOA表示授权开始
ns.gr.org.该域的主域名服务器
root.gr.org.管理员邮件地址(这里的邮件地址中的用.来代替常见的邮件地址的@.)
20150317serial(d. adams)表示配置文件的修改版本,格式是年月日当日修改的次数,每次修改时都应该修改这个数字,要不然所做修改的不会更新到网上的其它DNS服务器的数据库上,即你所做的更新很可能对于不以你你的所配置的DNS服务器数据库上,即你所做的更新很可能对于不以你的所配置的DNS服务器为DNS服务器的客户端来说就不会反映出你的更新,也就对他们来说你更新是没意义的
6Hrefresh,定义以单位(M分,H时,W周,默认是秒即不带单位)的刷新频率,即规定从域名服务器多长时间查询一个主服务器,以服务器的数据的是最新的
30Mretry,以30分钟的时间间隔重试,即当从服务器试图在主服务器上查询更新时,而连接失败了,则这个值规定了从服务器多长时间后重试
1Wexpire,规定从服务器在向主服务器更新失败之后清除记录的时间
15Mminimum TTL,规定缓冲服务器不能与主服务器联系上的清除记录时间
NSnet server,表示该主机是域名服务器
Aaddress,定义了一条A记录,表示该主机名到IP地址的对应记录
MXmail exchange,定义一条邮件记录
CNAME定义了对应主机的一个别名
PTR指一条反向域名解析PTR记录,类似A记录(PTR指针记录由IP地址提供商提供)

#DNS负载均衡优点

  1. 将负载均衡的工作交给DNS,省去了网站管理维护负载均衡服务器的麻烦。
  2. 技术实现比较灵活、方便,简单易行,成本低,使用于大多数TCP/IP应用。
  3. 对于部署在服务器上的应用来说不需要进行任何的代码修改即可实现不同机器上的应用访问。
  4. 服务器可以位于互联网的任意位置。
  5. 同时许多DNS还支持基于地理位置的域名解析,即会将域名解析成距离用户地理最近的一个服务器地址,
    这样就可以加速用户访问,改善性能

#DNS负载均衡缺点

  1. 目前的DNS是多级解析的,每一级DNS都可能缓存A记录,当某台服务器下线之后,即使修改了A记录,
    要使其生效也需要较长的时间,这段时间,DNS任然会将域名解析到已下线的服务器上,最终导致用户访问失败。
  2. 不能够按服务器的处理能力来分配负载。DNS负载均衡采用的是简单的轮询算法,不能区分服务器之间的差异,
    不能反映服务器当前运行状态,所以其的负载均衡效果并不是太好。
  3. 可能会造成额外的网络问题。为了使本DNS服务器和其他DNS服务器及时交互,保证DNS数据及时更新,
    使地址能随机分配,一般都要将DNS的刷新时间设置的较小,但太小将会使DNS流量大增造成额外的网络问题。

配置文件例子:
named.conf

key "rndc-key" {
	algorithm hmac-sha256;
	secret "YrKX8ketu7iMDv32tndictV7ZmhKU+SuW1bhQhvmGPY=";
};

controls {
	inet 127.0.0.1 port 953
		allow { 127.0.0.1; } keys { "rndc-key"; };
};

options {
	directory "/usr/local/named/zones";
	pid-file "named.pid"; 
	rrset-order {order cyclic;};#轮询访问
};

logging
{
	channel dnsquery.log
	{
		file "/usr/local/named/log/dnsquery.log" versions 3 size 10M;
		severity info;
		print-time yes;
	};
	category queries { dnsquery.log; };
};

view "internal"
{
	  zone "." {
		type hint;
		file "/usr/local/named/etc/named.root";
	  };
    zone "shiny.com" IN{
		type master;
        file "shiny.zone";
		allow-update {none;};
    };
};

shiny.zone

$TTL 7200
@       IN      SOA     shiny.com.      admin.163.com.(
                        2019103001
                        1H
                        5M
                        7D
                        1D )
@       IN      NS      www.shiny.com.
www     IN      A       192.168.1.221
DNS解析BIND 9(适用于WINDOWS桌面系统) 完全改进: Security Fixes Treat an all zero netmask as invalid when generating the localnets acl to workaround bug on Windows platform. [CVE-2013-6230] [RT #34687] Fix crashes when serving some NSEC3 signed zones. memcpy was incorrectly called with overlapping ranges, resulting in malformed names being generated on some platforms. This could cause INSIST failures. (CVE 2014-0591) [RT #35120] Features Changes Add the ability to specify ndots to "nslookup". [RT #34711] Introduce a new tool "dnssec-importkey" to allow externally-generated DNSKEY to be imported into the DNSKEY management framework. [RT #34698] Check that EDNS subnet client options are well formed. [RT #34718] "named" now preserves the capitalization of names when responding to queries. [RT #34737] Include a comment in .nzf files (used for adding new zones via "rndc"), giving the name of the associated view. [RT #34765] Use separate rate limiting queues for refresh and notify requests. [RT #30589] Adjust when a master server is deemed unreachable to be less aggressive. [RT #27075] Create delegations for all "children" of empty zones except "forward first". [RT #34826] Changed the name of "isc-config.sh" developers script (for outputting compiler and linker flags) to "bind9-config". [RT #23825] Add "dig" option to keep the TCP socket open between successive queries (+[no]keepopen). [RT #34918] Add dns_client_createx2() function to DNS Client API to provide a way to specify the local address for use when sending update packets. [RT #34811] "named-checkconf -z" now checks zones of type hint as well as master. [RT #35046] Update config.guess and config.sub to add support for ppc64le (powerpc 64-bit Little Endian). [RT #35060] Update the Windows build system to support feature selection and WIN64 builds. This is a work in progress. [RT #34160] Add "dnssec-signzone -Q" switch to drop signatures from keys that are still published but no longer active. [RT #34990] Add a more detailed "not found" message to "rndc" commands which specify a zone name. [RT #35059] named will now warn when a zone's configured "key-directory" does not exist or is not a directory. [RT #35108] Added improvements to statistics channel XSL stylesheet: the stylesheet can now be cached by the browser; section headers are omitted from the stats display when there is no data in those sections to be displayed; counters are now right-justified for easier readability. (Only available with ./configure --enable-newstats.) [RT #35117] "named-checkconf" can now obscure shared secrets when printing by specifying '-x'. [RT #34465] "named" can now accept integer timestamps in RRSIG records. [RT #35185] The export-library API call for loading "resolv.conf", irs_resconf_load(), has been modified to return ISC_R_FILENOTFOUND when the file does not exist and initializes the resconf structure as if the file had existed and configured with nameservers at the localhost addresses (127.0.0.1 and ::1). [RT #35194] Bug Fixes Treat type 65533 (KEYDATA) as opaque except when used in a key zone. [RT #34238] Fix "host" and "nslookup" so don't need dot after the domain by checking ndots when searching. Only continue searching on NXDOMAIN responses. [RT #34711] Handle changes to sig-validity-interval settings better. [RT #34625] Fix bug where journal filename string could be set incorrectly, causing garbage in log messages. [RT #34738] Address a race condition when shutting down a zone. [RT #34750] Address race condition with manual notify requests. [RT #34806] Fix nslookup crash where some readline clones don't accept NULL pointers when calling add_history. [RT #34842] Fix Linux compilation issue when libcap-devel is installed. [RT #34838] Fix installation on Solaris -- don't add explicit make dependencies/rules for python programs as make won't use the implicit rules. [RT #34835] Fix hanging server with inline-signed zones by addressing lock order reversal deadlock with inline zones. [RT #34856] Fix "host" failure if a UDP query timed out. [RT #34870] Address bugs in dns_rdata_fromstruct and dns_rdata_tostruct for WKS and ISDN types. [RT #34910] Updated OpenSSL PKCS#11 patches to fix active list locking and other bugs. [RT #34855] Fix a potential hang with failure to release lock on error in receive_secure_db. #34944] Fix cast in lex.c which could see 0xff treated as EOF. This fixes issue with potential bad data in a database used by DLZ or SDB. [RT #34993] Fix build issue on newer FreeBSD needing -lhx509 for GSSAPI build. [RT #35001] Address read after free in server side of lwres_getrrsetbyname. [RT #29075] Fix "nsupdate" memory leak if "realm" was used multiple times. [RT #35073] Fix "dig" for cleaning up TCP sockets still waiting on connect(). [RT #35074] Fix "dnssec-importkey" so imported key won't overwrite an existing non-imported private key. Fix issue where queries covered by a disabled Response Policy Zone (query type was '*') are answered with TTL of 0. [RT #35026] Fix "nsupdate" memory leak if "realm" was used multiple times. [RT #35073] Fix "dig" for cleaning up TCP sockets still waiting on connect(). [RT #35074] Fix issue with "rndc retransfer" with inline-signing replacing NSEC3 with NSEC records. [RT #34745] Fix issue with "rndc refresh" failing to sign slave zones using inline-signing. [RT #35105] Fix potential hang (detected by our inline-signing system test) with null pointer dereference in libdns zone_xfrdone. [RT #35042] Address bug in libdns loadnode function that could return a freed node on out of memory. [RT #35106] Fixed a bug causing an insecure delegation from one "static-stub" zone to another to fail with a broken trust chain. [RT #35081] Fixed problem where iterative responses could be discarded when the "query-source" port for an upstream query was the same as the listener port (53). [RT #34925] Fix crashes in RBTDB implementation. Two calls to dns_db_getoriginnode were fatal if there was no data at the node. [RT #35080] Fix a possible race and crash in the socket_search() function in dispatch.c. [RT #35107] Fix "dig" so it can handle AXFR style IXFR responses which span multiple messages. [RT #35137] Fix a "host" tool problem with converting UTF-8 textname to IDN encoding by handling "." as a search list element when IDN support is enabled. [RT #35133] Fix "queryperf" to prevent a possible integer overflow when printing results. [RT #35182] Prevent a theoretically possible race and crash when obtaining a socket in dispatch.c [RT #35128] Use built-in versions of strptime() and timegm() on all platforms to avoid portability issues. [RT #35183] Fix a bug which could cause a crash when running "rndc reconfig" or "rndc reload" after configuration is changed from regular zones to automatic empty zones. [RT #35177]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值