一、Dnsmasq安装
yum install dnsmasq -y service dnsmasq start
注意:dnsmasq只适合小规模网络使用,libero做过压力测试,如果是对外提供服务使用,libero建议大家还是使用专业Bind。
二、Dnsmasq配置
如果您是openwrt 用户,此配置一样适用。
vim /etc/dnsmasq.conf 打开dnsmasq 配置文件。配置:resolv-file=/etc/resolv.dnsmasq.conf,表示dnsmasq 会从这个指定的文件中寻找上游dns服务器。同时取消 strict-order 前面的注册#号。
检查一下no-hosts前面是不是已经有了#号,默认的情况下是有的,dnsmasq 会首先寻找本地的 hosts 文件再去寻找缓存下来的域名, 最后去上游dns 服务器寻找。
设置:listen-address=127.0.0.1,表示这个 dnsmasq 本机自己使用有效。注意:如果你想让本机所在的局域网的其它电脑也能够使用上Dnsmasq,应该把本机的局域网IP加上去:listen-address=192.168.1.123,127.0.0.1。注意:如果想允许所有的用户使用你的DNS解析服务器,把listen-address注释掉即可。
配置/etc/resolv.conf文件。
echo 'nameserver 127.0.0.1' > /etc/resolv.conf cp /etc/resolv.conf /etc/resolv.dnsmasq.conf #下面两个DNS 为AIXYZ官网DNS ,请从https://aixyz.com/获取 echo 'nameserver 115.159.146.99' > /etc/resolv.dnsmasq.conf echo 'nameserver 123.206.21.48' > /etc/resolv.dnsmasq.conf cp /etc/hosts /etc/dnsmasq.hosts echo 'addn-hosts=/etc/dnsmasq.hosts' >> /etc/dnsmasq.conf
?三、配置国内域名走国内
# 指定dnsmasq默认查询的上游服务器,此处以AIXYZ DNS为例# server=115.159.146.99 server=123.206.21.48 # 把所有.cn的域名全部通过114.114.114.114这台国内DNS服务器来解析 server=/cn/114.114.114.114 # 给*.apple.com和taobao.com使用专用的DNS server=/taobao.com/223.5.5.5 server=/apple.com/223.5.5.5 #更多规则您自己指定
四、启动Dnsmasq
chkconfig dnsmasq on /etc/init.d/dnsmasq restart
启动dnmasq 并设置开机自动启动。
注意如果启用了防火墙的主意要开启防火墙。
$ iptables -A INPUT -p udp -m udp --dport 53 -j ACCEPT $ iptables -A INPUT -p tcp -m tcp --dport 53 -j ACCEPT $?service?iptables?save $?service?iptables?restart
五、Dnsmasq配置说明
#/etc/dnsmasq.conf 配置文件 用指定的端口代替默认的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,192.168.0.150,255.255.255.0,12h 自动加载conf-dir目录下的配置文件 conf-dir=/etc/dnsmasq.d 设置dns缓存大小,默认为150条 cache-size=150
成功展示:4k无压力。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
喜欢就支持一下吧