Linux /etc/hosts文件
来源:互联网 发布:java lamda表达式语法 编辑:程序博客网 时间:2024/05/17 08:04
hosts文件
hosts —— the static table lookup for host name(主机名查询静态表)。
hosts文件是Linux系统上一个负责ip地址与域名快速解析的文件,以ascii格式保存在/etc/目录下。hosts文件包含了ip地址与主机名之间的映射,还包括主机的别名。在没有域名解析服务器的情况下,系统上的所有网络程序都通过查询该文件来解析对应于某个主机名的ip地址,否则就需要使用dns服务程序来解决。通过可以将常用的域名和ip地址映射加入到hosts文件中,实现快速方便的访问。
优先级 : dns缓存 > hosts > dns服务
hosts格式配置
hosts文件可以配置主机ip与对应的主机名。在局域网或者是万维网上,每台主机都有一个ip地址,它区分开每台主机,并可以根据ip进行通讯。但是Ip地址不符合人脑的记忆规律,因此出现了域名,例如www.baidu.com.在一个局域网中,每台机器都有一个主机名,用于区分主机,便于相互访问。
hosts文件格式
<code class=" hljs " style="display: block; padding: 0.5em; color: rgb(0, 0, 0);">ip地址 主机名/域名 (主机别名)</code>
主机名和域名的区别在于:
- 主机名通常在局域网内使用,通过hosts文件,主机名就被解析到对应的ip。
- 域名通常在internet上使用,但是优先级低于hosts文件中内容,因此如果你不想使用internet上的域名解析,可以更改自己的hosts文件,加入自己的域名解析。
hosts文件作用
一个主要的作用是:线下环境模拟,通信双方在同一个局域网内想通过internet上的域名相互访问,则只需要修改自己的/etc/hosts文件内容即可。
例如,修改www.baidu.com的ip为127.0.0.1:
修改/etc/hosts之后,ping百度的效果如下图所示:
0 0
- Linux /etc/hosts文件
- Linux /etc/hosts文件
- linux /etc/hosts 文件作用
- linux系统/etc/hosts文件
- linux /etc/hosts文件作用
- linux /etc/hosts文件作用
- linux /etc/hosts文件作用
- linux /etc/hosts文件作用
- linux /etc/hosts文件作用
- Linux /etc/hosts文件配置 总结
- Linux操作系统下/etc/hosts文件详解
- linux /etc/hosts文件的内容解析
- Linux操作系统下/etc/hosts文件详解
- linux上/etc/hosts文件域名映射
- Linux 如何编辑/etc/hosts文件
- Linux操作系统下/etc/hosts文件详解
- /etc/hosts文件
- /etc/hosts文件简介
- JAVA_SE基础——17.方法的重载
- eclipse使用link方式安装android ADT插件
- Bitmap类getPixels()方法中参数stride理解
- how to make the XVim still available on xcode7
- 1049. Counting Ones (30)
- Linux /etc/hosts文件
- 用独立键盘实现数码管计数的启动与停止
- iOS 国际化简单记录
- spi flash驱动代码分析(二)
- 相同的雪花
- Newstate: 对新闻点击流数据的可视分析
- Linux键盘快捷键
- eclipse安装svn插件图文
- Android初学之路(二)