什么是hosts文件
hosts文件是个什么文件呢?Hosts虽然没有后缀名,其实是个纯文本文件,可以用记事本等文本编辑软件打开。Hosts文件主要用于在本地电脑强制解析域名,Hosts文件里包含映射IP地址和Host主机名的规定,每段只能包括一个映射关系,IP地址要放在每段的最前而,空格后再写上映射的主机名。
hosts文件的路径是%SystemRoot%\system32\drivers\etc\hosts
,一般来说也就是C:\WINDOWS\system32\drivers\etc\hosts
。
hosts文件的一般格式如下:
# copyright (c) 1993-1999 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
127.0.0.1 localhost
其中,以#开头的文字都是注释用的,127.0.0.1 localhost
这一行就是表示把localhost解析到127.0.0.1这个ip上。需要强制解析的域名则按127.0.0.1 localhost这一行的格式添加,一行一个。
hosts文件有什么用
hosts文件用于将某个域名解析到特定的ip上。我们访问一个域名的时候,域名解析的工作是由您所用的当地网络接入商的域名解析DNS服务器负责的,在本地电脑hosts文件作解析也就是由自己电脑强制解析域名,而跳过电信域名解析服务器。我们自己修改Hosts文件可以起到加快网站域名解析、方便局域网用户、屏蔽网站等作用。一般来说,有以下几种情况需要或会改动hosts文件:
1,你的网站尚未上架对外开放访问,而你自己又想通过域名访问,这时就可以先在本地电脑hosts文件作解析;
2,杀毒软件或安全软件比如360安全卫士、瑞星等出于保护你的电脑安全的考虑对某些含有病毒木马的网站域名强行解析到127.0.0.1,让你的电脑无法访问到这些病毒网站;
3,与上一条相反,有些病毒也会通过修改你的hosts文件来让你访问含有病毒木马的网站。
如何打开和编辑hosts文件
hosts文件的路径在%SystemRoot%\system32\drivers\etc\hosts
,一般也就是C:\WINDOWS\system32\drivers\etc\hosts
,我们可以通过“我的电脑”一层层打开文件夹,最后找到hosts文件(没有后缀名),右键点击选用记事本打开即可。另外,直接在“运行”里输入以下代码也可以直接打开hosts文件
%SystemRoot%\system32\notepad.exe %SystemRoot%\system32\drivers\etc\hosts
如上所述,hosts文件对于电脑安全来说是相当重要的一个位置,因此,病毒和杀毒软件双方往往会争相对这个文件的写入权限加以控制,这也就是为什么我们有时候打开hosts文件会提示拒绝访问的原因。
分类目录
- arch/management (17)
- computer (38)
- java/j2ee (305)
- lnmpa (237)
- mac/iphone/ipad/android (11)
- mysql/oracle/postgresql (126)
- os/software (74)
- other (518)
- python (6)
- redis/memcached/mongo (31)
- sitebuild (143)
随便看看
标签云
程序员 创业 人生箴言 eclipse 快捷键 术语 索引 unix命令 vim wordpress java学习笔记 环境变量 oracle内置函数 index 人生 数据类型 nohup tuxedo mysql学习笔记 MS-DOS命令 servlet spring 职场进阶 职业进阶 服务器选购 服务器选型 apache JPA MongoDB 注解 tomcat 子女教育 jquery maven JVM aix命令 网络营销 java异常 seo 人生规划 关键字 css 网络推广 struts 系统优化 成长 frame iframe bluehost jdbc select 我的信仰 oracle函数 cookie HashMap 站长工具 乱码 ArrayList secureCRT jsp session tail find halt 事务 oracle单记录函数 算法 URL window table javascript操作表单元素 String 字符串处理 健康 http 域名 情感 more google A记录 域名解析 netstat 弹出对话框 弹出窗口 框架集 框架 excel 字符串 javascript函数 showModalDialog nginx number 数组 sql frameset 开源程序 java数组 软件 oracle服务友情链接
收藏链接