dnsmasq使用注意事项

来源:互联网 发布:娄烨电影知乎 编辑:程序博客网 时间:2024/06/02 20:39
DNS服务器,linux下一般用bind,但bind太复杂了,dnsmasq使用上比dns始祖bind要简便得多,可以做正向dns代理,也可以直接做内部纯dns服务器用。
默认配置下,dnsmasq使用系统的/etc/resolv.conf并读取/etc/hosts,
  /etc/resolv.conf文件是用来配置上一级DNS
  /etc/hosts文件是用来存储dns代理缓存。
  dnsmasq可以用hosts文件来设置域名:
  例:mail.bingo.com是不存在的域名,在dnsmasq中指向到一个ip里,
vi /etc/hosts来添加ip,
192.168.9.199  mail.bingo.com

重启: pkill -9 dnsmasp  && /usr/local/sbin/dnsmasq -h
或者 service dnsmasq restart
对外提供dns
vi /etc/dnsmasq.conf

# Change this line if you want dns to get its upstream servers from
# somewhere other that /etc/resolv.conf
#resolv-file=

用于设置上级dns服务器,用于向上级服务器转发查询请求。不设置,默认使用/etc/resolv.conf
如要解析外网的dns,必须设置此项用于向外转发dns请求。


# Include a another lot of configuration options.
#conf-file=/etc/dnsmasq.more.conf
conf-dir=/etc/dnsmasq.d
去掉这行的注释,用于包含配置文件目录

然后保存

在/etc/dnsmasq.d 新建文件配置文件,文件名随便,例如dns-hosts.conf
添加
address=/mail.bingo.com/192.168.9.199

重启dnsmasq,然后在其他的pc测试
添加范域名的配置

address=/.google.com/203.208.37.0
address=/www.youtube.com/203.208.37.0

还有一种添加方法,
vi /etc/dnsmasq.conf
添加一行  addn-hosts=/etc/dnsmasq.hosts

然后在dnsmasq.hosts添加
192.168.9.253 www.bingo.com
然后重启dnsmasq,不过这样不支持范域名
0 0
原创粉丝点击