bind centos,redis bind

大家好,bind centos相信很多的网友都不是很明白,包括redis bind也是一样,不过没有关系,接下来就来为大家分享关于bind centos和redis bind的一些知识点,大家可以关注收藏,免得下次来找不到哦,下面我们开始吧!

CentOS系统怎样安装DNS服务器

CentOS系统安装DNS服务器方法

DNS安装配置

在 RHEL5、6中 DNS都是用的是 bind软件包,而在 RHEL/CentOS 7用的是 unbound安装包,配置文件也有了改变。我们来看一下:

2.1.安装:

代码如下:

[root@linuxprobe~]# yum-y install unbound

Loaded plugins: langpacks, product-id, subscription-manager

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Resolving Dependencies

---> Running transaction check

---> Package unbound.x86_64 0:1.4.20-19.el7 will be installed

---> Finished Dependency Resolution

·····

启动服务

代码如下:

[root@linuxprobe~]# systemctl restart unbound//启动DNS服务

[root@linuxprobe~]# systemctl enable unbound

ln-s‘/usr/lib/systemd/system/unbound.service‘‘/etc/systemd/system/multi-user.target.wants/unbound.service‘

//下次系统重启自动启动DNS服务

2.2.修改配置文件

unbound安装好之后,缺省配置文件在/etc/unbound/unbound.conf。

2.2.1.修改端口监听地址

相当于 RHEL6配置文件中的:listen-on port 53{ any;};

查看默认监听地址

代码如下:

[root@linuxprobe~]# netstat-tunlp|grep unbound

tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 3333/unbound

tcp 0 0 127.0.0.1:8953 0.0.0.0:* LISTEN 3333/unbound

tcp6 0 0::1:53:::* LISTEN 3333/unbound

tcp6 0 0::1:8953:::* LISTEN 3333/unbound

udp 0 0 127.0.0.1:53 0.0.0.0:* 3333/unbound

udp6 0 0::1:53:::* 3333/unbound

//默认监听本地回环地址,也就是现在只有自己能访问DNS服务,其它主机不能访问本机的DNS服务

修改监听地址代码如下:

[root@linuxprobe~]# vim/etc/unbound/unbound.conf

……

38# interface: 0.0.0.0

39 interface: 0.0.0.0

……

//找到38行,复制去掉注释行,打开监听全网功能。

重启服务查看

代码如下:

[root@linuxprobe~]# systemctl restart unbound

[root@linuxprobe~]# netstat-tunlp|grep unbound

tcp 0 0 0.0.0.0:53 0.0.0.0:* LISTEN 3461/unbound

tcp 0 0 127.0.0.1:8953 0.0.0.0:* LISTEN 3461/unbound

tcp6 0 0::1:8953:::* LISTEN 3461/unbound

udp 0 0 0.0.0.0:53 0.0.0.0:* 3461/unbound

//现在53号端口监听的是0.0.0.0,即所有网段都监听。

2.2.2.修改允许查询的范围

在 RHEL6中,DNS配置文件中有这样一句:allow-query{ localhost;};。此句定义的是允许向本机查询(迭代&递归)的主机范围,localhost代表只有本机可以向本机查询。而在配置中,经常改 localhost为 any,让所有主机能够向本机查询 DNS。所以,在 RHEL7中,也要做这样的修改,只不过修改内容不同而已,如下:

代码如下:

[root@linuxprobe~]# vim/etc/unbound/unbound.conf

……

177# access-control: 0.0.0.0/0 refuse

178 access-control: 0.0.0.0/0 allow

179# access-control: 127.0.0.0/8 allow

……

找到配置文件/etc/unbound/unbound.conf的第177行,缺省为注释行,把内容改为允许访问,然后保存退出,重启服务即可。

2.2.3.创建解析文件

RHEL/CentOS 5、6系统中,DNS的解析文件分正向和反向两个解析文件,并且有解析文件的模板文件。但是在 RHEL7中,正反向解析文件合并为一个,并且无模板文件,需自己创建,路径可以在主配置文件中查看:

代码如下:

[root@linuxprobe~]# vim/etc/unbound/unbound.conf

……

453# You can add locally served data with

454# local-zone:"local." static

455# local-data:"mycomputer.local. IN A 192.0.2.51"

//正向解析可参考语法

456# local-data:‘mytext.local TXT"content of text record"‘

457#

458# You can override certain queries with

459# local-data:"adserver.example.com A 127.0.0.1"

460#

461# You can redirect a domain to a fixed address with

462#(this makes example.com, www.example.com, etc, all go to 192.0.2.3)

463# local-zone:"example.com" redirect

464# local-data:"example.com A 192.0.2.3"

465#

# Shorthand to make PTR records,"IPv4 name" or"IPv6 name".

467# You can also add PTR records using local-data directly, but then

468# you need to do the reverse notation yourself.

469# local-data-ptr:"192.0.2.3 www.example.com"

//反向解析参考语法

470

471 include:/etc/unbound/local.d/*.conf

472

473# service clients over SSL(on the TCP sockets), with plain DNS inside

……

查看本机FQDN

代码如下:

[root@linuxprobe~]# hostname

linuxprobe.example.com

//由此可知,域名为example.com

创建解析文件代码如下:

[root@linuxprobe~]# vim/etc/unbound/local.d/example.conf

local-zone:"example.com." static

local-data:"example.com. 86400 IN SOA ns.example.com. root 1 1D 1H 1W 1H"

local-data:"ns.example.com. IN A 192.168.10.10"

local-data:"linuxprobe.example.com. IN A 192.168.10.10"

local-data-ptr:"192.168.10.10 ns.example.com."

local-data-ptr:"192.168.10.10 linuxprobe.example.com."

查看RHEL6上解析文件以作对比

代码如下:

[root@linuxprobe~]# vim/var/named/named.localhost

$TTL 1D

@ IN SOA@ rname.invalid.(

0; serial

1D; refresh

1H; retry

1W; expire

3H); minimum

NS@

A 127.0.0.1

AAAA::1

2.3.禁用服务用户

每个服务都是有其专用的服务用户,DNS的服务用户为 unbound,实际情况下服务用户的启用有可能有安全隐患,这里要禁用服务用户。

代码如下:

[root@linuxprobe~]# vim/etc/unbound/unbound.conf

······

211# if given, user privileges are dropped(after binding port),

212# and the given username is assumed. Default is user"unbound".

213# If you give"" no privileges are dropped.

214#username:"unbound"

215 username:""

216

217# the working directory. The relative files in this config

······

如上,找到配置文件的第214行,删除unbound即可,删除后为:username”“。

2.4.验证

代码如下:

[root@linuxprobe~]# unbound-checkconf

unbound-checkconf: no errors in/etc/unbound/unbound.conf

验证无配置问题,即可重启服务

复制代码代码如下:

[root@linuxprobe~]# systemctl restart unbound

dns验证:

修改本机DNS

代码如下:

[root@linuxprobe~]# vim/etc/sysconfig/network-scripts/ifcfg-eth0

HWADDR=00:0C:29:70:····

TYPE=Ethernet

····

IPADDR="192.168.10.10"

PREFIX="24"

···

DNS1=192.168.10.10

NAME=eth0

ONBOOT=no

[root@linuxprobe~]# systemctl restart network

nslookup验证

代码如下:

[root@linuxprobe~]# nslookup

linuxprobe.example.com.

192.168.10.10

ok dns设置成功

PS:关闭防火墙

在本次实验中我们关闭了 linux的3大防火墙。当没有关闭防火墙时,远程主机验证可能出现故障,这时需要在 DNS服务器防火墙上开放 DNS服务。我们以 firewall防火墙为例,修改一下:

代码如下:

[root@linuxprobe~]# systemctl stop iptables

[root@linuxprobe~]# systemctl stop ebtables

[root@linuxprobe~]# systemctl disable iptables

[root@linuxprobe~]# systemctl disable ebtables

[root@linuxprobe~]# firewall-cmd--add-service=dns--permanent

success

[root@linuxprobe~]# firewall-cmd--reload

success

[root@linuxprobe~]# firewall-cmd--list-all

public(default, active)

interfaces: eth0

sources:

services: dhcpv6-client dns ssh

ports:

masquerade: no

forward-ports:

icmp-blocks:

rich rules:

//DNS服务器上Firewall开放DNS访问ok

centos bind服务 中的dns cache缓存时间可以更改吗,如何更改

Option中有下面两个参数,分别定义否定应答和肯定应答在缓存中的生存周期:

max-ncache-ttl

为降低网络流量和提升服务器存储否定回答的性能。 max-ncache-ttl以秒为单位设定这

些回答的保存时间.默认max-ncache-ttl是10800秒(3小时)。 max-ncache-ttl不能超过7

天,如果设成一个更大的值,则将会被自动减为7天。

max-cache-ttl

max-cache-ttl设定了服务器储存普通(肯定)答案的最大时间。默认值一周(7天)

下载中心有bind9的管理员手册,可以多参考一下

centos2003是什么版本

centos2003的版本是:CentOS 7.8版本,并且众所周知,CentOS由 Red Hat Enterprise Linux的源代码重新编译而成,因此 CentOS 7.8的上游版本正是本月初发布的 Red Hat Enterprise Linux 7.8。

centos2003主要变更是:已使用 Python 3,安装 python3组件将提供 Python 3.6解释器,bind已升级为 9.11,chrony已升级为 3.4。

自 1503发行版(abrt>= 2.1.11-19.el7.centos.0.1)开始,CentOS-7可以直接向反馈错误,可在找到更多关于此功能的数据。

如果准备在 Anaconda采用安全性配置文件,很多组件已获得重要更新,ImageMagick已从 6.7.8升级为 6.9.10。

基于redis的IP地址快速查询的方法是:

为了提高查询速度,我们引入redis,redis是目前热门的Nosql数据库,很多大的公司都在用,具体的用法大家可以查查资料。

redis中有一种数据结构是有序集合 sortset,我的IP数据库可以转化为sortset存储,一个sortset中存储所有的IP记录,结构为value中存储IP的开始,结束,省份等,分别依照逗号隔开,score中存放的是IP的结束值。

比如我们查询一个IP,IP转化为长整型的数字为 2,然后我们查询的时候就通过sortset的zrangebyscore ranges 2+inf LIMIT 0 1这样我们就查询出来大于2的第一条记录。

这样我们查询出来记录为“1,5,中国移动,北京市”然后我们在判断一下我们要查询的地址在不在 1,5之间,2在1,5之间,所以查出来了2对应的IP地址为中国移动北京市。

再比如我们要查询的IP地址数字为 8,通过zrangebyscore ranges 8+inf LIMIT 0 1我们查询到了 10,20,中国联通,上海市,但是8不在10,20之间,所以查询不到此IP对应的地址。

阅读剩余
THE END