软硬件环境
- windows 10 64bit
- ubuntu 19.10 64bit
视频看这里
此处是youtube的播放链接,需要科学上网。喜欢我的视频,请记得订阅我的频道,打开旁边的小铃铛,点赞并分享,感谢您的支持。
hosts文件

我们在上网的时候,一般都是输入网站的域名(如IP地址,在我们输入域名后,就需要DNS对域名进行解析,而hosts文件就是负责域名解析的,而且它的优先级高于DNS服务器,很多的恶意软件就是通过修改系统的hosts文件来达到劫持网站的目的。
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
# 0.0.0.0 account.jetbrains.com
127.0.0.1  cbs.wondersahre.com
# Added by Docker Desktop
192.168.1.2 host.docker.internal
192.168.1.2 gateway.docker.internal
# To allow the same kube context to work on the host and the container:
127.0.0.1 kubernetes.docker.internal
# End of section
每一行都是ip地址跟上一个空格,然后是域名或者是主机名。在internet中是域名,在局域网中则可以说主机名。
windows修改hosts文件
hosts文件存放于C:\Windows\System32\drivers\etc,需要管理员权限进行编辑,如果该文件夹下没有hosts文件,是因为文件被隐藏了,可以通过下面方法显示出来

如果在此文件夹下无法修改文件,可以将hosts文件拷贝到桌面,编辑完成后拷贝回去进行覆盖即可。
ubuntu修改hosts文件
在我们打开Terminal时

在@之前的字符是登录系统的用户名,之后就是主机名
hosts文件存放在/etc/目录下,编辑的话,方法和windows下是一样的。
