传统运维 - dns缓存

2021-10-14

简要

DNSmasq提供DNS缓存和DHCP服务功能。作为域名解析服务器,DNSmasq可以通过缓存DNS请求来提高对访问过的网址的连接速度;作为DHCP 服务器,DNSmasq可以用于为局域网电脑分配内网IP地址和提供路由。

  1. 安装DNSmasq。
yum install dnsmasq -y
  1. 安装bind-utils。
yum install bind-utils -y

运行和验证

  1. 修改配置文件“/etc/dnsmasq.conf”。
    文件中对应的内容修改如下:

resolv-file=/etc/resolv.dnsmasq.conf
strict-order
no-hosts
user=root
group=root
addn-hosts=/etc/dnsmasq.hosts

  1. 复制“/etc/resolv.conf”文件为“/etc/resolve.dnsmasq.conf”。

cp /etc/resolv.conf /etc/resolv.dnsmasq.conf

  1. 修改“/etc/resolv.conf”文件。
    文件全部内容修改如下:

nameserver 127.0.0.1

  1. 复制“/etc/hosts”文件为“/etc/dnsmasq.hosts”。

cp /etc/hosts /etc/dnsmasq.hosts

  1. 启动DNSmasq服务。

systemctl enable dnsmasq
systemctl start dnsmasq