加入收藏 | 设为首页 | 会员中心 | 我要投稿 核心网 (https://www.hxwgxz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 电商 > 正文

利用Dnsmasq部署DNS服务

发布时间:2021-01-11 00:10:04 所属栏目:电商 来源:网络整理
导读:《利用Dnsmasq部署DNS服务》要点: 本文介绍了利用Dnsmasq部署DNS服务,希望对您有用。如果有疑问,可以联系我们。 Dnsmasq提供 DNS 缓存和DHCP服务、Tftp服务功能.作为域名解析 服务器 (DNS),Dnsmasq可以通过缓存DNS请求来提高对访问过的网址的连接速度.作
副标题[/!--empirenews.page--]

《利用Dnsmasq部署DNS服务》要点:
本文介绍了利用Dnsmasq部署DNS服务,希望对您有用。如果有疑问,可以联系我们。

Dnsmasq提供DNS缓存和DHCP服务、Tftp服务功能.作为域名解析服务器(DNS),Dnsmasq可以通过缓存DNS请求来提高对访问过的网址的连接速度.作为DHCP服务器,Dnsmasq可以为局域网电脑提供内网ip地址和路由.DNS和DHCP两个功能可以同时或分别单独实现.Dnsmasq轻量且易配置,适用于个人用户或少于50台主机的网络.此外它还自带了一个PXE服务器.

Dnsmasq工作原理

当接受到一个DNS请求时,Dnsmasq首先会查找/etc/hosts这个文件,然后查找/etc/resolv.conf中定义的外部DNS.所以说Dnsmasq是一个很不错的外部DNS中继.

配置Dnsmasq为DNS缓存服务器,同时在/etc/hosts文件中加入本地内网解析,这样一来每当内网机器查询时就会优先查询hosts文件,这就等于将/etc/hosts共享给全内网机器使用,从而解决内网机器互相识别的问题.相比逐台机器编辑hosts文件或者添加Bind DNS记录,仅编辑一个hosts文件,这简直太容易了.

安装Dnsmasq

  • Ubuntu/Debian
$ apt-get install dnsmasq
  • Centos/RHEL
$ yum install dnsmasq

配置Dnsmasq

Dnsmasq处理DNS设置与BIND等其他DNS服务有所不同.所有的配置都在一个文件中完成/etc/dnsmasq.conf.默认情况下dnsmasq.conf中只开启了最后include项,可以在/etc/dnsmasq.d中自己写任意名字的配置文件.

配置文件说明

Dnsmasq配置文件是/etc/dnsmasq.conf,下面对Dnsmasq中和DNS相关的配置项进行说明.

用指定的端口代替默认的DNS 53端口,如果设置为0,则完全禁止DNS功能,只使用dhcp服务
port=5353

以下两个参数告诉Dnsmasq过滤一些查询:1.哪些公共DNS没有回答 2.哪些root根域不可达.

从不转发格式错误的域名
#domain-needed

从不转发不在路由地址中的域名
#bogus-priv

resolv-file配置Dnsmasq额外的向流的DNS服务器,如果不开启就使用linux主机默认的/etc/resolv.conf里的nameserver,通过下面的选项指定其他文件.
resolv-file=/etc/dnsmasq.d/upstream_dns.conf

默认情况下Dnsmasq会发送查询到它的任何上游DNS服务器上,如果取消注释,则Dnsmasq则会严格按照/etc/resolv.conf中的DNS Server顺序进行查询.
#strict-order

以下两个参数控制是否通过/etc/resolv.conf确定上游服务器,是否检测/etc/resolv.conf的变化,则取消注释. 

如果你不想Dnsmasq读取/etc/resolv.conf文件或者其他文件,获得它的servers
# If you don't want dnsmasq to read /etc/resolv.conf or any other
# file,getting its servers from this file instead (see below),then
# uncomment this.
#no-resolv

如果你不允许Dnsmasq通过轮询/etc/resolv.conf或者其他文件来获取配置的改变,则取消注释. 
#no-poll

增加一个name server,一般用于内网域名
#server=/localnet/192.168.0.1

设置一个反向解析,所有192.168.3.0/24的地址都到10.1.2.3去解析
#server=/3.168.192.in-addr.arpa/10.1.2.3

增加一个本地域名,会在/etc/hosts中进行查询
#local=/localnet/

增加一个域名,强制解析到你指定的地址上
#address=/double-click.net/127.0.0.1

同上,还支持ipv6
#address=/www.thekelleys.org.uk/fe80::20d:60ff:fe36:f83

增加查询yahoo google和它们的子域名到vpn、search查找
# Add the IPs of all queries to yahoo.com,google.com,and their
# subdomains to the vpn and search ipsets:
#ipset=/yahoo.com/google.com/vpn,search

你还可以控制Dnsmasq和Server之间的查询从哪个网卡出去
# server=10.1.2.3@eth1

指定源地址携带10.1.2.3地址和192.168.1.1的55端口进行通讯
# and this sets the source (ie local) address used to talk to
# 10.1.2.3 to 192.168.1.1 port 55 (there must be a interface with that
# IP on the machine,obviously).
# server=10.1.2.3@192.168.1.1#55

改变Dnsmasq默认的uid和gid
#user=
#group=

如果你想Dnsmasq监听某个端口为dhcp、dns提供服务
#interface=

你还可以指定哪个端口你不想监听
#except-interface=

设置想监听的地址,如果你本机要使用写上127.0.0.1.
#listen-address=

如果你想在某个端口只提供dns服务,则可以进行配置禁止dhcp服务
#no-dhcp-interface=

# On systems which support it,dnsmasq binds the wildcard address,# even when it is listening on only some interfaces. It then discards
# requests that it shouldn't reply to. This has the advantage of
# working even when interfaces come and go and change address. If you
# want dnsmasq to really bind only the interfaces it is listening on,# uncomment this option. About the only time you may need this is when
# running another nameserver on the same machine.
#bind-interfaces

如果你不想使用/etc/hosts,则取消下面的注释
#no-hosts

如果你项读取其他类似/etc/hosts文件,则进行配置
addn-hosts=/etc/banner_add_hosts

自动的给hosts中的name增加一个域名
#expand-hosts

给dhcp服务赋予一个域名
#domain=thekelleys.org.uk

给dhcp的一个子域赋予一个不同的域名
#domain=wireless.thekelleys.org.uk,192.168.2.0/24

同上,不过子域是一个范围
#domain=reserved.thekelleys.org.uk,192.68.3.100,192.168.3.200

dhcp分发ip的范围,以及每个ip的租约时间
#dhcp-range=192.168.0.50,192.168.0.150,12h

同上,不过给出了掩码
#dhcp-range=192.168.0.50,255.255.255.0,12h

自动加载conf-dir目录下的配置文件
conf-dir=/etc/dnsmasq.d

设置dns缓存大小,默认为150条
cache-size=150

配置实例

配置上游服务器地址

(编辑:核心网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读