環境:ubuntu16.04 今天遇到dns被劫持的情況,在此記錄一下: 1.首先如何確定是否被劫持: 那麼查詢一個並不存在的功能變數名稱 nslookup notexit.comrrrr 如果返回了一個ip地址,說明dns被劫持了,假設此ip地址為:123.34.5.6 那麼用8.8.8.8功能變數名稱伺服器解析 ...
環境:ubuntu16.04
今天遇到dns被劫持的情況,在此記錄一下:
1.首先如何確定是否被劫持:
那麼查詢一個並不存在的功能變數名稱
nslookup notexit.comrrrr
如果返回了一個ip地址,說明dns被劫持了,假設此ip地址為:123.34.5.6
那麼用8.8.8.8功能變數名稱伺服器解析一下此錯誤功能變數名稱試試:
nslookup notexit.comrrrr 8.8.8.8
輸出的內容如下:
jello@jello:~$ nslookup notexit.comrrrr 8.8.8.8
Server: 8.8.8.8
Address: 8.8.8.8#53
** server can't find notexit.comrrrr: NXDOMAIN
提示內容說明此功能變數名稱並不存在
2.那麼如何處理這種情況呢?
由於ubuntu16.04使用dnsmasq對功能變數名稱進行解析,那麼修改dnsmasq的配置文件:
因為linux處理dns請求有個限制,在/etc/resolv.conf中只能配置三個dns地址,那麼乾脆在/etc/resolv.conf文件中只保留localhost為功能變數名稱伺服器,然後新建一個存儲外部功能變數名稱伺服器地址的配置文件,並將該配置文件加入到dnsmasq的配置項resolv-file中,例如:
2.1新建配置文件/etc/resolv.my.conf,往其中填入內容如下:
nameserver 8.8.8.8
nameserver 8.8.4.4
2.2往/etc/dnsmasq.conf中添加以下內容:
resolv-file=/etc/resolv.my.conf
2.3重新啟動dnsmasq
systemctl restart dnsmasq
註意:如果重啟dnsmasq超時,那麼就直接打開/var/run/dnsmasq/resolv.conf
裡面有解析不存在功能變數名稱而得到的功能變數名稱伺服器地址,將存在該功能變數名稱伺服器地址的某行刪除即可,假設筆者的該文件內容為:
nameserver 123.34.5.6
nameserver 231.43.5.45
那麼直接刪掉nameserver 123.34.5.6即可
最有效方案如下:
3.還可以直接使用其它的功能變數名稱伺服器地址替換掉這兩個ip,然後再重啟dnsmasq,筆者修改後/var/run/dnsmasq/resolv.conf配置文件內容如下:
nameserver 8.8.8.8
nameserver 8.8.4.4
重啟dnsmasq:
systemctl restart dnsmasq