[ubuntu]dnsmasq安裝(輕量化DNS服務)

參考網址:如何在Ubuntu 20.04上使用Dnsmasq設置本地DNS解析器

dnsmasq安裝(輕量化DNS服務)

 

Dnsmasq使用参考入门 http://www.freeoa.net/osuport/servap/dnsmasq-use-intro-refer_2480.html

 

Dnsmasq – Lightweight Name Resolution For Your Home Lab
https://dev.to/joeneville_/dnsmasq-lightweight-name-resolution-for-your-lab-2gim

 

在lubuntu 22.04安裝過程
參考書籍:O'REILLY Linux錦囊妙計 第二版 碁峯 P401~426
roki.tw tni設置
在系統中禁用Systemd解析的服務

systemctl disable --now systemd-resolved
rm -rf /etc/resolv.conf #需先刪除,它原本是一個link
echo "nameserver 192.168.1.9" > /etc/resolv.conf
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
apt-get install dnsmasq dnsutils ldnsutils -y

/etc/NetworkManager/NetworkManager.conf 的[main]加入
dns=none
否則/etc/resolv.conf會一直被改掉
client端亦同
改完後要系統reboot才會生效
 

先把兩片網路卡裝好
eth0 192.168.1.19 負責對外
eth1 192.168.66.1 負責內部網路
兩片網卡透通 iptables -t nat -A POSTROUTING -o eth0 -s 192.168.66.0/24 -j MASQUERADE


vi /etc/dnsmasq.conf

##########DNS
resolv-file=/etc/resolv.conf
domain-needed
bogus-priv
expand-hosts
#no-host的項目預設是關閉的,這個啟用的話會變成最先去找local端的host檔案。
no-hosts

#通常與no-hosts對應的是addn-hosts設定檔部分,
#這個就不是讀取/etc/hosts,而是自己定義要對應到哪個檔案去。
#(這邊的格式要跟/etc/hosts的一樣)
#addn-hosts=/etc/add_hosts

#domain=sp.idv.tw
#local=/sp.idv.tw/ #這兩行設了反而無法連線到sp.idv.tw
listen-address=127.0.0.1
listen-address=192.168.1.19

server=8.8.8.8

#要擋掉的網站
address=/tw.yahoo.com/192.168.1.19
address=/edition.cnn.com/192.168.1.19
address=/pchome.com.tw/192.168.1.19
address=/facebook.com/192.168.1.19

###########DHCP
dhcp-leasefile=/var/lib/misc/dnsmasq.leases
listen-address=192.168.66.1
dhcp-option=eth1,3,192.168.66.1  #router
dhcp-option=eth1,1,255.255.255.0 #mask
dhcp-option=eth1,6,192.168.66.1  #dns-server
dhcp-range=eth1,192.168.66.100,192.168.66.200,24h
#dhcp-host=08:00:27:3c:da:1a,192.168.1.101
# Always give the host with Ethernet address 11:22:33:44:55:66
# the name fred and IP address 192.168.0.60 and lease time 45 minutes
#dhcp-host=11:22:33:44:55:66,fred,192.168.0.60,45m

 

service dnsmasq restart

netstat -rn 查詢gateway

dnsmasq –help dhcp 查詢服務的選項編號

https://thekelleys.org.uk/dnsmasq/doc.html 官方文件

client端的/etc/resolv.conf 設定
nameserver 192.168.1.9
nameserver 8.8.8.8

nslookup 指定server的用法
 

#先執行nslookup 出現>後再輸入server 192.168.1.9
nslookup
>server 192.168.1.9

dig指定server的用法
dig @192.168.1.9

目前問題
1.dnsmasq server中的/etc/hosts 無法直接下放給windows 10 client使用
  (nslookup可以查到該網站的對應,瀏覽器卻出不去。在ubuntu系統是可行的)
2.address=/tw.yahoo.com/192.168.1.19 檔不住網站,但address=/pchome.com.tw/192.168.1.19 卻可以檔掉

本篇發表於 Linux系統。將永久鏈結加入書籤。