本文最后更新于2 分钟前,文中所描述的信息可能已发生改变。
linux下记录DNS解析的文件
该文件的路径为/etc/hosts
,使用cat /etc/hosts
查看该文件内容如下:
sh
127.0.0.1 localhost
127.0.1.1 ubuntu # 解析记录 ip 域名/主机名
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
可以通过我们自己配置来实现绕过DNS服务器的解析从而加快网站的访问速度。
配置DNS服务器的地址
我们可以指定DNS服务器从而让我们的请求都让该DNS服务器去解析。
通过在文件/etc/resolv.conf
中添加DNS服务器的地址即可,使用cat /etc/resolv.conf
查看文件内容如下:
sh
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs must not access this file directly, but only through the
# symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a different way,
# replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.
nameserver 127.0.0.53 # DNS服务器的地址
options edns0 trust-ad
search localdomain
windows下的hosts文件
在windows下该文件的路径为C:\Windows\System32\drivers\etc\hosts
,默认是没有权限进行修改的,可以通过文件的属性->安全,在其中修改相应组或用户对于文件的读写权限。修改文件中的内容即可。