本文基于系统raspbian-stretch。
首先安装:
aptitude install -y dnsmasq
dnsmasq的配置文件是/etc/dnsmasq.conf。我们先备份dnsmasq.conf:
cd /etc
sudo mv dnsmasq.conf dnsmasq.conf.bak
然后新建dnsmasq.conf:
sudo touch dnsmasq.conf
sudo vi dnsmasq.conf
配置好的dnsmasq.conf文件内容如下:
strict-order
listen-address=172.16.0.1
cache-size=10000
log-queries
log-facility=/var/log/dnsmasq.log
然后重新启动dnsmasqa服务:
sudo service dnsmasq restart
由于树莓派的raspbian-stretch系统默认安装了openresolv这个软件,这个软件的存在会使/etc/resolv.conf这个文件变得很难修改,所以我们把它卸载掉(想要详细了解openresolv和resolvconf这两个软件包和resolv.conf文件的关系,请自行百度):
sudo aptitude purge openresolv
然后重新启动树莓派:
sudo reboot
接下来将局域网内的客户端的dns服务器设置为树莓派接入局域网接口的ip地址即可。
在客户端上可以用nslookup检验(linux可以用dig)