自动修改hosts文件

首先上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=/bin/sh
  8 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  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/sbin/anacron || ( cd / && run-parts --report /etc/    cron.daily )
 13 47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/    cron.weekly )
 14 52 6    1 * *   root    test -x /usr/sbin/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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值