Skip to content

Instantly share code, notes, and snippets.

@FindHao
Last active Apr 10, 2019
Embed
What would you like to do?
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

Refactoring commented Apr 10, 2019

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