1

如何修改Hosts文件访问特定网站

 3 years ago
source link: https://zeqiang.fun/post/techstack/hosts_revise/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

因为搭梯子的问题引出了host问题 有些网站是不需要翻墙,只需要绑定host就可以访问,比如lncn.org 我之前上Coursera,看上面的视频就需要绑定hosts才能流畅观看 还有Cambly口语练习网站,官方就有教我们如何修改Hosts访问 OneDrive也不能幸免,毕竟服务器在海外

2020.04.06更新

以下转至知乎

看了大家的回答, 我自己也用浏览器的开发者工具试了一下.d3c33hcgiwev3.cloudfront.net 确实是视频资源的域名, 但是本机无法ping通, 所以视频一直无法正常播放, 而且域名对应的ip还会变, 因此更新hosts文件不能一劳永逸.

而且本机通过nslookup/ping/host查到的ip地址也是基本用不了的. 考虑到这个域名的ip可能在全球范围有很多个, 我参考了这篇文章, 使用文章中推荐的在线域名解析工具, 返回如下:

d3c33hcgiwev3.cloudfront.net has address 143.204.238.224
d3c33hcgiwev3.cloudfront.net has address 143.204.238.122
d3c33hcgiwev3.cloudfront.net has address 143.204.238.63
d3c33hcgiwev3.cloudfront.net has address 143.204.238.194

并且试了一下这几个ip, 都是可以成功ping通的, 将这个添加到hosts文件里, 像这样:

143.204.238.224  d3c33hcgiwev3.cloudfront.net
143.204.238.122  d3c33hcgiwev3.cloudfront.net
143.204.238.63  d3c33hcgiwev3.cloudfront.net
143.204.238.194  d3c33hcgiwev3.cloudfront.net

刷新就可以正常看视频了, 速度也可以. 如果过一段时间这几个ip失效了, 大家也可以用在线域名解析工具, 看看最新的有效ip, 测试ping得通的话, 就更新hosts文件就好了.解决问题的过程中, 我还找到了这篇文章, 对提供思路也蛮有帮助.总之, 因为网站ip地址是动态的, 所以确实难以有一劳永逸的解决办法, 希望我今天尝试的做法能帮到大家.

nslookup

2020.04.03更新

更新一下内容,关于cousera上看网课的问题,之前很多教程上的hosts地址很多都过时了,现在用以下方法搜索到几个可以使用的,延迟在270ms左右

13.224.164.55
13.224.121.90

具体方法是先在IP查找网站里输入www.coursera.com这个域名,对查找结果进行ping查看延迟情况,如下代码来筛选出延迟较低的地址

    ping 13.224.164.55

在终端输入如下代码打开hosts

    sudo vim /etc/hosts

更新你所查找到的IP地址

# 下面重定向了网页服务器,就是在第二步选定的地址
13.227.243.43    www.coursera.org
# 下面重定向了视频服务器
13.224.161.73    d3c33hcgiwev3.cloudfront.net
52.84.246.90     d3c33hcgiwev3.cloudfront.net
52.84.246.252    d3c33hcgiwev3.cloudfront.net

最后别忘记清空DNS缓存!

    sudo dscacheutil -flushcache

for windows

在本地host文件中将本站域名绑定到 69.194.14.16

安卓可下载 Hosts Go 添加 , windows具体操作方法如下:

  1. 进入目录C:/Windows/System32/drivers/etc,记事本打开host文件
  2. 在最后一行添加(注意空格): 69.194.14.16 lncn.org
  3. win+R 输入cmd回车,执行: ipconfig /flushdns
  4. 重新刷新页面即可,如失效请还原host并用代理访问!

for mac os

in Finder menu, enter Command+Shift+G

go to /private/etc/

then, you can find the hosts file !

Here is my hosts content as following

##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting.  Do not change this entry.
##
127.0.0.1   localhost
255.255.255.255 broadcasthost
::1             localhost
52.84.167.78    d3c33hcgiwev3.cloudfront.net
69.194.14.16    lncn.org

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK