首页 > 编程知识 正文

hosts文件修改器,Windows修改hosts文件

时间:2023-05-06 11:02:36 阅读:215288 作者:621

首先上github链接,复制这个shell脚本,放在某个文件夹下,我是放在/etc/lhosts下

先打开hosts文件vim /etc/hosts,发现其中内容很少,只有10+行,运行刚刚的脚本sudo bash /etc/lhosts之后再看看hosts文件

1 # 远程 hosts 开始标记,请在 上方 添加其他内容 2 # Copyright (c) 2014-2017, racaljk. 3 # https://github.com/racaljk/hosts 4 # Last updated: 2017-04-20 5 6 # This work is licensed under a CC BY-NC-SA 4.0 International License. 7 # https://creativecommons.org/licenses/by-nc-sa/4.0/ 8 9 # Localhost (DO NOT REMOVE) 10 127.0.0.1 localhost 11 ::1 localhost ip6-localhost ip6-loopback 12 13 # Modified hosts start 14 15 # Armorgames Start 16 93.184.220.39 cache.armorgames.com 17 93.184.220.39 gamemedia.armorgames.com 18 93.184.220.39 quests.armorgames.com 19 93.184.220.39 armatars.armorgames.com ....(其后省略3000+行)

之后,你懂的。。。

原因

原因是域名解析到IP地址的DNS过程被阻止了,使得域名无法解析到正确的IP地址,进而无法连接到正确的服务器。而DNS解析的过程是先去本地hosts文件中去找有没有对应的缓存,然后再连接DNS服务器,修改hosts中的内容就可以跳过连接DNS服务器解析域名这一步

附1:定时启动脚本

进入/etc文件夹,打开sudo vim crontab

1 # /etc/crontab: system-wide crontab 2 # Unlike any other crontab you don't have to run the `crontab' 3 # command to install the new version when you edit this file 4 # and files in /etc/cron.d. These files also have username fields, 5 # that none of the other crontabs do. 6 7 SHELL=/yhdlm/sh 8 PATH=/usr/local/syhdlm:/usr/local/yhdlm:/syhdlm:/yhdlm:/usr/syhdlm:/usr/yhdlm 9 10 # m h dom mon dow user command 11 17 * * * * root cd / && run-parts --report /etc/cron.hourly 12 25 6 * * * root test -x /usr/syhdlm/anacron || ( cd / && run-parts --report /etc/ cron.daily ) 13 47 6 * * 7 root test -x /usr/syhdlm/anacron || ( cd / && run-parts --report /etc/ cron.weekly ) 14 52 6 1 * * root test -x /usr/syhdlm/anacron || ( cd / && run-parts --report /etc/ cron.monthly ) 15 #

在14行之后插入5 12 * * * root bash /etc/lhosts,其中5代表分,12代表小时(以24小时制),后面三列分别为年、月、星期,都为*代表是每年每月的每一天,因此插入的命令代表每天的12点5分以root的身份运行命令bash /etc/lhosts

附2:VIM永久显示行号

运行命令vim ~/.vimrc,在最后添加set nu,保存关闭。注:如果.vimrc文件存在则在最后添加命令,不存在则新建文件。

ubuntu的定时工具Cron

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。