Win7/8/10 Mac中hosts文件位置介紹 Mac Linux中hosts文件修改方法
Hosts是一個(gè)沒有擴(kuò)展名的系統(tǒng)文件,其作用就是將一些常用的網(wǎng)址域名與其對(duì)應(yīng)的IP地址建立一個(gè)關(guān)聯(lián)“數(shù)據(jù)庫(kù)”,可以用記事本打開。當(dāng)用戶在瀏覽器中輸入一個(gè)需要登錄的網(wǎng)址時(shí),系統(tǒng)會(huì)首先自動(dòng)從Hosts文件中尋找對(duì)應(yīng)的IP地址,一旦找到,系統(tǒng)會(huì)立即打開對(duì)應(yīng)網(wǎng)頁(yè),如果沒有找到,則系統(tǒng)會(huì)再將網(wǎng)址提交DNS域名解析服務(wù)器進(jìn)行IP地址的解析。下面小編就給大家?guī)?lái)Win7/8/10 Mac中hosts文件位置介紹和Mac Linux中hosts文件修改方法,一起來(lái)看看吧!
這就是為什么通過(guò)修改hosts文件就可以瀏覽谷歌等被墻網(wǎng)站,原因是直接訪問(wèn)目標(biāo)網(wǎng)站對(duì)應(yīng)ip,不通過(guò)DNS。
Windows系統(tǒng)hosts位于C:WindowsSystem32driversetchostsAndroid(安卓)系統(tǒng)hosts位于/system/etc/hostsMac(蘋果電腦)系統(tǒng)hosts跟Linux一樣位于/etc/hostsiPhone(iOS)系統(tǒng)hosts跟Linux Mac一樣位于/etc/hostsLinux系統(tǒng)hosts位于/etc/hosts
你可以用記事本打開并修改
PC建議用Notepad++進(jìn)行編輯。
注意:hosts文件屬于系統(tǒng)核心文件之一,所以Windows用戶必須用管理員身份打開才能修改保存,如果遇到無(wú)法保存,請(qǐng)右鍵文件hosts并找到“屬性” -> “安全”,然后選擇你登陸的用戶名,最后點(diǎn)擊編輯,勾選“寫入”即可。
Android(安卓)必須Root才能修改,Root Explorer管理器或ES文件瀏覽器裝載/system可寫狀態(tài),找到/system/etc/hosts的文件,使用文本編輯器打開編輯后保存。
Linux系統(tǒng)使用Root權(quán)限vi編輯
而iPhone、iPad也必須越獄才能修改!Windows系統(tǒng)跟蘋果系統(tǒng)的hosts文件文本編碼和換行符格式一樣,而Android(安卓)則不一樣,這點(diǎn)你需要注意。
Windows系統(tǒng)原版hosts文件:
123456789101112131415161718192021 # Copyright (c) 1993-2009 Microsoft Corp.## This is a sample HOSTS file used by Microsoft TCP/IP for Windows.## This file contains the mappings of IP addresses to host names. Each# entry should be kept on an individual line. The IP address should# be placed in the first column followed by the corresponding host name.# The IP address and the host name should be separated by at least one# space.## Additionally, comments (such as these) may be inserted on individual# lines or following the machine name denoted by a '#' symbol.## For example:## 102.54.94.97 rhino.acme.com # source server# 38.25.63.10 x.acme.com # x client host# localhost name resolution is handled within DNS itself.# 127.0.0.1 localhost# ::1 localhost
Mac、iPhone、iPad原版hosts文件:
12345678910 ### Host Database## localhost is used to configure the loopback interface# when the system is booting. Do not change this entry.##127.0.0.1 localhost255.255.255.255 broadcasthost::1localhostfe80::10localhost
Linux系列我就不列出了,一般用這個(gè)系統(tǒng)的人都不會(huì)是小白。
大家或許留意到,原版的hosts文件前面都帶有井號(hào)“#”,以#開頭的都是注釋用的,所以并沒什么卵用,如果你想快速恢復(fù)原版hosts文件,那么也可以直接清空里邊的內(nèi)容,一般情況沒有什么影響。
修改hosts文件后生效的方法:
Windows開始 -> 運(yùn)行 -> 輸入cmd -> 在CMD窗口輸入:
1 ipconfig /flushdns
Linux終端輸入
1 sudo rcnscd restart
對(duì)于systemd發(fā)行版,請(qǐng)使用命令
1 sudo systemctl restart NetworkManager
如果不懂請(qǐng)都嘗試下
Mac OS X終端輸入
1 sudo killall -HUP mDNSResponder
Android開啟飛行模式 -> 關(guān)閉飛行模式
通用辦法:
拔網(wǎng)線(斷網(wǎng)) -> 插網(wǎng)線(重新連接網(wǎng)絡(luò)) 或者重啟系統(tǒng)。
清空瀏覽器緩存(不要使用國(guó)產(chǎn)瀏覽器)
以上就是關(guān)于Win7/8/10 Mac Linux等各系統(tǒng)的hosts文件位置的介紹了,希望大家喜歡!
