請選擇 進入手機版 | 繼續訪問電腦版
搜索
熱搜: 活動 交友 discuz
查看: 8493|回復: 0

[Windwos] hosts DNS - 設定網址對應 IP 的方式 - for Windows/Linux (主機 IP 域名對應檔 hosts)

[複製鏈接]
發表於 2013-9-19 00:39:15 | 顯示全部樓層 |閱讀模式
無論是 Windows 主機或 Linux 主機都有個 hosts 檔案,裡面定義著讓本機使用的 Domain Name <--> IP 對應表,任何程式在進行網路連線時通常會進行 DNS 伺服器進行 IP 的查詢,不過在查詢之前都一定會先來 hosts 檔查詢是否已經有定義過該 Domain Name 的對應 IP,如果沒有的話才會正式進行 DNS 查詢。

在 Windows 下通常 hosts 檔的路徑如下:(winXP/win7皆相同)

  1. C:\WINDOWS\system32\drivers\etc\hosts
複製代碼


在 Linux 下通常 hosts 檔的路徑如下:

  1. /etc/hosts
複製代碼


在 Windows 下的 hosts 檔案格式與 Linux 下的 hosts 檔案格式完全相同,以 Windows 為例,通常預設的內容如下:

  1. # Copyright (c) 1993-2009 Microsoft Corp.
  2. #
  3. # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
  4. #
  5. # This file contains the mappings of IP addresses to host names. Each
  6. # entry should be kept on an individual line. The IP address should
  7. # be placed in the first column followed by the corresponding host name.
  8. # The IP address and the host name should be separated by at least one
  9. # space.
  10. #
  11. # Additionally, comments (such as these) may be inserted on individual
  12. # lines or following the machine name denoted by a '#' symbol.
  13. #
  14. # For example:
  15. #
  16. #      102.54.94.97     rhino.acme.com          # source server
  17. #       38.25.63.10     x.acme.com              # x client host

  18. # localhost name resolution is handled within DNS itself.
  19. #        127.0.0.1       localhost
  20. #        ::1             localhost

  21. 127.0.0.1 genuine.microsoft.com
  22. 127.0.0.1 mpa.one.microsoft.com
  23. 127.0.0.1 sls.microsoft.com
複製代碼


127.0.0.1       localhost
預設只會有一筆資料,也就是 localhost 對應到 127.0.0.1 (本機IP),這就是為什麼我們常常看到 localhost 的原因。

我們如果要新增新的 Domain Name <--> IP 對應,只要用記事本(Notepad)開啟該檔,並新增一行到最後面即可完成,第一欄輸入 IP 然後加些空白,再輸入 Domain Name 即可。例如:

  1. 127.0.0.1 sls.microsoft.com
複製代碼


參考資料:http://blog.miniasp.com/



補充:

windows7修改hosts時可能遇到狀況:please check whether if this file is opened in another program

解決:設定該檔案或資料夾的使用者權限即可!
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

本論壇為非營利之網路平台,所有文章內容均為網友自行發表,不代表論壇立場!若涉及侵權、違法等情事,請告知版主處理。


Page Rank Check

廣告刊登  |   交換連結  |   贊助我們  |   服務條款  |   免責聲明  |   客服中心  |   中央分站

手機版|中央論壇

GMT+8, 2024-4-18 17:31 , Processed in 0.018670 second(s), 17 queries .

Powered by Discuz!

© 2005-2015 Copyrights. Set by YIDAS

快速回復 返回頂部 返回列表