Linux /etc/resolv.conf 配置DNS

來源:互聯網
上載者:User

檔案/etc/resolv.conf配置DNS客戶,它包含了主機的網域名稱搜尋順序和DNS伺服器的地址,每一行應包含一個關鍵字和一個或多個的由空格隔開的參數。下面是一個例子檔案:

  search mydom.edu.cn
  nameserver 210.34.0.14
  nameserver 210.34.0.2

  合法的參數及其意義如下:

  nameserver 表明DNS伺服器的IP地址。可以有很多行的nameserver,每一個帶一個IP地址。在查詢時就按nameserver在本檔案中的順序進行,且只有當第一個nameserver沒有反應時才查詢下面的nameserver。

  domain   聲明主機的網域名稱。很多程式用到它,如郵件系統;當為沒有網域名稱的主機進行DNS查詢時,也要用到。如果沒有網域名稱,主機名稱將被使用,刪除所有在第一個點( .)前面的內容。

  search   它的多個參數指明網域名稱查詢順序。當要查詢沒有網域名稱的主機,主機將在由search聲明的域中分別尋找。domain和search不能共存;如果同時存在,後面出現的將會被使用。

  sortlist  允許將得到網域名稱結果進行特定的排序。它的參數為網路/掩碼對,允許任意的排列順序。

  Red Hat中沒有提供預設的/etc/resolv.conf檔案,它的內容是根據在安裝時給出的選項動態建立的。

原文連結: Linux下/etc/resolv.conf 配置DNS客戶

在/etc/resolv.conf 設定檔:domain 和search作用是一樣的

下面的說明更清晰

domain linpro.no
search linpro.no uio.no ifi.uio.no

domain function:

Had I typed telnet math.uio.no. with the trailing dot, the resolver would have known it was an FQDN and would have looked up math.uio.no at once, without trying to append the specified domain first. Not all applications are tolerant
of the trailing dot, though, so it can't always be specified.

search function:

When ssh gram is executed, the resolver first looks for gram.linpro.no, which does not exist; then gram.uio.no, which does not exist, either; and finally gram.ifi.uio.no, which will succeed because it does exist

原文連結:/etc/resolv.conf中關鍵字search和domain的作用

關於domain和search與/etc/hosts的區別在《鳥哥的linux私房菜(網路架設)》第十九章 DNS伺服器
小節:Client 端的設定 中有說:
· /etc/hosts :剛剛上面就提過了,這個是最早的 hostname 對應 IP 的檔案;

· /etc/resolv.conf :這個就是設定你 Client 端連上 DNS 主機的 IP 設定檔案;

· /etc/nsswitch.conf:這個檔案則是在『決定』先要使用 /etc/hosts 還是 /etc/resolv.conf的設定!

  一般而言, Linux 的預設 hostname 搜尋都是先 /etc/hosts 來的,為什麼呢?你可以查看一下
/etc/nsswitch.conf ,並找到 hosts 的項目:

[root@linux ~]# vi /etc/nsswitch.conf hosts: files dns
  上面那個 files 就是使用 /etc/hosts 而最後的 dns 則是使用 /etc/resolv.conf 的 DNS 主機 IP搜

尋啦!因此,你可以先以 /etc/hosts 來設定 IP 對應ㄋㄟ!當然啦,你也可以將他調換過來,不過,總是
/etc/hosts 比較簡單,所以將他擺在前面比較好啦!

  好啦,既然我們是要進行 DNS 測試的,那麼 /etc/resolv.conf 的內容,自然就要填寫我們自己的IP
囉!所以你應該這樣寫:

[root@linux ~]# vi /etc/resolv.conf nameserver 192.168.1.254 nameserver 168.95.1.1 nameserver 139.175.10.20
  nameserver 可以設定多個,但是由於 nameserver 是一個一個的追查下來的,所以,你的 DNS 主機的 IP 要寫在最上面喔!然後就可以開始測試了!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.