[关闭]
@mritd 2016-09-01T10:16:01.000000Z 字数 1172 阅读 2738

10分钟 dnsmasq 搭建

Linux DNS Docker


一、安装

  1. yum install -y dnsmasq

二、配置

  1. # 编辑配置文件
  2. vim /etc/dnsmasq.conf

主要配置如下

  1. # 上游 DNS 定义
  2. resolv-file=/etc/resolv.dnsmasq.conf
  3. # 取消从本地 hosts 读取
  4. no-hosts
  5. # 监听地址
  6. listen-address=127.0.0.1,192.168.1.106
  7. # 指定本地 dns host 配置
  8. addn-hosts=/etc/dnsmasq.hosts
  9. # 设置 dns 缓存大小
  10. cache-size=150

配置 dns 解析

  1. # 增加本地回环
  2. echo 'nameserver 127.0.0.1' >> /etc/resolv.conf
  3. # 增加本地 hosts
  4. cp /etc/hosts /etc/dnsmasq.hosts
  5. # 添加上游 DNS 服务器
  6. echo 'nameserver 8.8.8.8' >> /etc/resolv.dnsmasq.conf
  7. echo 'nameserver 192.168.1.1' >> /etc/resolv.dnsmasq.conf

三、测试

首先启动 dnsmasq

  1. systemctl enable dnsmasq
  2. systemctl start dnsmasq
  3. systemctl status dnsmasq

使用 dig 命令测试即可

  1. dig @192.168.1.106 www.baidu.com
  2. ; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> @192.168.1.106 www.baidu.com
  3. ; (1 server found)
  4. ;; global options: +cmd
  5. ;; Got answer:
  6. ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4980
  7. ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
  8. ;; OPT PSEUDOSECTION:
  9. ; EDNS: version: 0, flags:; udp: 4096
  10. ;; QUESTION SECTION:
  11. ;www.baidu.com. IN A
  12. ;; ANSWER SECTION:
  13. www.baidu.com. 490 IN CNAME www.a.shifen.com.
  14. www.a.shifen.com. 201 IN A 61.135.169.125
  15. www.a.shifen.com. 201 IN A 61.135.169.121
  16. ;; Query time: 5 msec
  17. ;; SERVER: 192.168.1.106#53(192.168.1.106)
  18. ;; WHEN: 8 30 16:00:21 EDT 2016
  19. ;; MSG SIZE rcvd: 101

四、视频


Your browser does not support the video tag.

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注