linux的dns被劫持,linuxdns被劫持

來源:互聯網
上載者:User

linux的dns被劫持,linuxdns被劫持

環境: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

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.