文章转自 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