Windows 下编辑 hosts 文件

版权声明:尊重原创,转载请标明出处: https://blog.csdn.net/weixin_42336774/article/details/85930379

hosts 文件目录: 

C:\WINDOWS\system32\drivers\etc\hosts 
  • hosts是一个没有扩展名的系统文件,可以用记事本等工具打开,其作用就是将一些常用的网址域名与其对应的IP地址建立一个关联
  • 当用户在浏览器中输入一个需要登录的网址时,系统会首先自动从hosts文件中寻找对应的IP地址,一旦找到,系统会立即打开对应网页,如果没有找到,则系统会再将网址提交DNS域名解析服务器进行IP地址的解析。
  • hosts文件里包含映射IP 地址和host主机名的规定,每段只能包括一个映射关系,IP地址要放在每段的最前,而空格后再写上映射的主机名。
  • 正常情况下,系统的hosts 文件除了说明信息外,只包含 “127.0.0.1 localhost” 这一段实际内容,如果出现其他的内容就表示被修改过了。如果hosts 文件被修改了会有什么后果昵?

有一种网页劫持的方法就是恶意修改hosts 文件,导致输人某些正常网址时都会转到广告网站。要想解除这种劫持,修复Hosts 文件即可。

  • 另外,我们自己修改hosts文件也可以起到加快网站域名解析、方便局域网用户、屏蔽网站等作用。

比如访问 github 网站速度比较慢,这时我们可以自己修改hosts文件( ip 地址自己查找),

52.74.223.119 github.com

覆盖后,让hosts生效

Windows
开始 -> 运行 -> 输入cmd -> 在CMD窗口输入  : 

ipconfig /flushdns

清空的话用记事本打开他,只保留 127.0.0.1 localhost
其它全部删除


hosts文件原始内容

# Copyright (c) 1993-2009 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

# localhost name resolution is handled within DNS itself.
#    127.0.0.1       localhost
#    ::1             localhost

猜你喜欢

转载自blog.csdn.net/weixin_42336774/article/details/85930379