文章轉自 https://blog.csdn.net/mikyz/article/details/69399987html
Windows用戶
XP的在C盤 C:WINDOWS/system32/drivers/etc 目錄下的 hosts文件,咱們用記事本打開後 修改裏面的內容,添加內容到host文件中保存便可。
ps: Win七、Win8等系統用戶
Win7及之後的系統涉及到管理員權限問題,須要用管理員身份運行記事本,再打開Host文件,進行修改
其餘用戶的host文件位置:
Android用戶:首先必須root手機,而後安裝root explorer管理器,打開進入/system/etc目錄,長按host文件,彈出菜單拉到下面會看到「文本編輯器方式打開」。編輯輸入便可
Mac OS用戶: host位置爲:/private/etc/hosts
iPhone用戶:需越獄,使用 iFunBox、PP助手、同步助手、iFile 等訪問設備文件系統,備份並修改該文件後覆蓋:/etc/hosts
Linux用戶 : 修改/etc/hostsubuntu
Linux用戶 /etc/hosts文件修改後如何生效
修改/etc/hosts以後正常狀況應該是保存以後當即生效的,可是有時不是。使用uname -a 能夠查看hostname是多少,就能夠知道是否修改生效了。若是沒有
這時的策略有:
1) 重啓機器
2) 重啓服務
Ubuntu: $sudo /etc/init.d/networking restart
Gentoo: /etc/init.d/net.eth0 restart
3)使用hostname命令
hostname 定義的主機名服務器
ps: hosts 不斷更新ing...
http://blog.my-eclipse.cn/host-google.html
ps:
hostname與/etc/hosts的關係
不少人一提到更改hostname首先就想到修改/etc/hosts文件,認爲hostname的配置文件就是/etc/hosts。其實不是的。
hosts文件的做用至關如DNS,提供IP地址到hostname的對應。早期的互聯網計算機少,單機hosts文件裏足夠存放全部聯網計算機。 不過隨着互聯網的發展,這就遠遠不夠了。因而就出現了分佈式的DNS系統。由DNS服務器來提供相似的IP地址到域名的對應。具體能夠man hosts。
Linux系統在向DNS服務器發出域名解析請求以前會查詢/etc/hosts文件,若是裏面有相應的記錄,就會使用hosts裏面的記錄。/etc /hosts文件一般裏面包含這一條記錄
127.0.0.1 localhost.localdomain localhost
hosts文件格式是一行一條記錄,分別是IP地址 hostname aliases,三者用空白字符分隔,aliases可選。
127.0.0.1到localhost這一條建議不要修改,由於不少應用程序會用到這個,好比sendmail,修改以後這些程序可能就沒法正常運行。
附Ubuntu14.04 repo:
### aliyun repo
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiversedom