useradd -r -g users dnsmasq
yum install -y gcc wget https://www.thekelleys.org.uk/dnsmasq/dnsmasq-2.76.tar.gz tar zxvf dnsmasq-2.76.tar.gz cd dnsmasq-2.76 make && make install cp dnsmasq.conf.example /etc/dnsmasq.conf
vi /etc/dnsmasq.conf
user=dnsmasq # 啟動帳號 group=users # 啟動群組 interface=eth0 # 綁定的網路介面 listen-address=192.168.238.135 # 綁定的 IP bind-interfaces resolv-file=/etc/resolv.conf # 上游域名解析檔 addn-hosts=/etc/hosts # 額外的 hosts 檔
echo "192.168.238.135 www.example.com" >> /etc/hosts
/usr/local/sbin/dnsmasq netstat -tnl | grep 53 # tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN # tcp 0 0 192.168.238.135:53 0.0.0.0:* LISTEN
只要 53 埠已成功進入監聽狀態,就代表 DNSmasq 已正常運作。
DNSmasq 的優點是設定極輕量,同時具備 DNS 轉發與 DHCP 能力,很適合內部網路或測試環境使用。
原文出自「唯愛丶琳」部落格:https://love11forever.blog.51cto.com/11313259/1783784