文章轉自 https://blog.csdn.net/mikyz/article/details/69399987
Windows用戶
XP的在C盤 C:WINDOWS/system32/drivers/etc 目錄下的 hosts文件,我們用記事本打開后 修改里面的內容,添加內容到host文件中保存即可。
ps: Win7、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/hosts
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 multiverse