Skip to content

Instantly share code, notes, and snippets.

@FindHao
Last active April 10, 2019 10:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save FindHao/727f58aedad8e6b8560bbd9619527f8c to your computer and use it in GitHub Desktop.
Save FindHao/727f58aedad8e6b8560bbd9619527f8c to your computer and use it in GitHub Desktop.
update hosts bash脚本
```
ipv6=$1
work_path="/home/find/Downloads/"
rm $work_path/hosts*
cp /etc/hosts $work_path/._backhosts
if [ "$ipv6" = "4" ]
then
#wget https://coding.net/u/onekeyhosts/p/text/git/raw/master/hosts -O hosts
wget https://coding.net/u/scaffrey/p/hosts/git/raw/master/hosts-files/hosts -O $work_path/hosts
# wget https://raw.githubusercontent.com/sy618/hosts/master/FQ -O hosts
else
wget https://raw.githubusercontent.com/lennylxx/ipv6-hosts/master/hosts -O $work_path/hosts
fi
mv $work_path/hosts /etc/hosts
chown find.find /etc/hosts
chmod a+w /etc/hosts
# 追加你的~下tmp.hosts的文件到系统hosts文件里
cat /home/your_username/tmp.hosts >> /etc/hosts
```
使用方法:保存为update.sh chmod +x update.sh增加可执行权限,运行:
update.sh 6 更新为ipv6的host,否则默认为ipv4的hosts。
需要自动更新可加入crontab里。
@Refactoring
Copy link

if [ "$ipv6" = "4" ]的判断是不是和使用方法update.sh 6处理反了?
执行脚本,不带参数默认下载IPV6,只有带了参数4才会下载IPV4。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment