1.dns服务器一般都是安装bind服务器,如果是小型的域名解析需求,使用dnsmasq即可
2.安装dnsmasq软件
yum install dnsmasq -y
3.查看dnsmasq的主配置文件 /etc/dnsmasq.conf
[root@backup01 ~]# grep -Ev “#|$” /etc/dnsmasq.conf
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
4.修改dnsmasq.conf如下参数:
查找/resolv-file参数修改如下
resolv-file=/etc/resolv.dnsmasq.conf #此参数指定上游dns服务器地址的参数
查找address参数 。vim命令模式下 查找/address,添加如下内容
#自定义某些域名及其子域名,都解析到某一个ip地址
address=/baidu.com/123.206.16.61
address=/taobao.com/123.206.16.61
#定义dnsmasq的监听地址的配置文件
listen-address=192.168.178.189
#定义一个本地域名配置文件,需要自定义的一些用户名解析记录
addn-hosts=/etc/dnsmasq.hosts
#开启记录dns查询的日志参数
log-queries
#启用如下蓝色参数,包含目录的语法,能够包含某一个文件下所有符合定义类型的配置文件
#Include another lot of configuration options.
#conf-file=/etc/dnsmasq.more.conf
conf-dir=/etc/dnsmasq.d
#Include all the files in a directory except those ending in .bak
conf-dir=/etc/dnsmasq.d,.bak
#Include all files in a directory which end in .conf
conf-dir=/etc/dnsmasq.d/,.conf
5.自定义dnsmasq服务的配置文件如下
[root@backup01 ~]# grep -Ev “#|$” /etc/dnsmasq.conf
resolv-file=/etc/resolv.dnsmasq.conf
address=/baidu.com/123.206.16.61
address=/taobao.com/123.206.16.61
listen-address=192.168.178.189
addn-hosts=/etc/dnsmasq.hosts
log-queries
conf-dir=/etc/dnsmasq.d
conf-dir=/etc/dnsmasq.d,.bak
conf-dir=/etc/dnsmasq.d/,.conf
conf-dir=/etc/dnsmasq.d,.rpmnew,.rpmsave,.rpmorig
6.内部解析地址关系,此两个文件需自己创建
[root@backup01 ~]# echo “123.206.16.61 yuchao668.com” > /etc/dnsmasq.hosts
[root@backup01 ~]# cat /etc/dnsmasq.hosts
123.206.16.61 yuchao668.com
7.添加上游dns服务器地址,当dnsmasq在本地找不到解析记录时去上游查找
[root@backup01 ~]# cat /etc/resolv.dnsmasq.conf
nameserver 119.29.29.29
nameserver 223.5.5.5
8.启动ndsmasq服务
[root@backup01 ~]# systemctl start dnsmasq
[root@backup01 ~]# systemctl status dnsmasq
9.修改本地的dns客户端配置文件,指定自定义的dnsmasq服务器地址
[root@backup01 ~]# cat /etc/resolv.conf
#Generated by NetworkManager
#nameserver 119.29.29.29
nameserver 192.168.178.189
10.测试域名解析是否成功
www.baidu.com
Server: 192.168.178.189
Address: 192.168.178.189#53
Name: www.baidu.com
Address: 123.206.16.61
www.pythonav.cn
Server: 192.168.178.189
Address: 192.168.178.189#53
Non-authoritative answer:
Name: www.pythonav.cn
Address: 123.206.16.61
结论:成功,