10分钟 dnsmasq 搭建 — 漠然

10分钟 dnsmasq 搭建

2016/09/01 Linux

一、安装

yum install -y dnsmasq

二、配置

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

主要配置如下

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

配置 dns 解析

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

三、测试

首先启动 dnsmasq

systemctl enable dnsmasq
systemctl start dnsmasq
systemctl status dnsmasq

使用 dig 命令测试即可

dig @192.168.1.106 www.baidu.com

; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.3 <<>> @192.168.1.106 www.baidu.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4980
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;www.baidu.com.                 IN      A

;; ANSWER SECTION:
www.baidu.com.          490     IN      CNAME   www.a.shifen.com.
www.a.shifen.com.       201     IN      A       61.135.169.125
www.a.shifen.com.       201     IN      A       61.135.169.121

;; Query time: 5 msec
;; SERVER: 192.168.1.106#53(192.168.1.106)
;; WHEN: 二 8月 30 16:00:21 EDT 2016
;; MSG SIZE  rcvd: 101

四、视频

转载请注明出处,本文采用 CC4.0 协议授权

Search

    Post Directory