屏蔽网站

准备

workspace

cd ~
mkdir g
cd g

#准备域名列表文件
mkdir /etc/g/
touch /etc/g/block.txt

#准备dnsmasq配置文件
mkdir /etc/dnsmasq.d/
touch /etc/dnsmasq.d/block.conf
echo "conf-dir=/etc/dnsmasq.d">>/etc/dnsmasq.conf

gadd.sh

cd ~/g
touch gbadd.sh && chmod a+x gbadd.sh && vi gbadd.sh
#!/bin/sh
touch /etc/g/block.txt
echo "$1">>/etc/g/block.txt

touch /etc/g/guniq.txt
cat /etc/g/block.txt | sort | uniq > /etc/g/blockuniq.txt
cat /etc/g/blockuniq.txt > /etc/g/block.txt

touch /etc/dnsmasq.d/block.conf
cat /etc/g/block.txt | awk '{print "server=/"$1"/0.0.0.0"}'>/etc/dnsmasq.d/block.conf

/etc/init.d/dnsmasq restart

使用方法

./gbadd.sh facebook.com

gbdelete.sh

cd ~/g
touch gbdelete.sh && chmod a+x gbdelete.sh && vi gbdelete.sh
#!/bin/sh
touch /etc/g/block.txt
sed -i "/$1/d" /etc/g/block.txt

touch /etc/g/blockuniq.txt
cat /etc/g/block.txt | sort | uniq > /etc/g/blockuniq.txt
cat /etc/g/blockuniq.txt > /etc/g/block.txt

touch /etc/dnsmasq.d/g.conf
cat /etc/g/g.txt | awk '{print "server=/"$1"/0.0.0.0"}'>/etc/dnsmasq.d/g.conf

/etc/init.d/dnsmasq restart

使用方法

./gbdelete.sh facebook.com

gblist.sh

touch gblist.sh && chmod a+x gblist.sh && vi gblist.sh
#!/bin/sh
cat /etc/g/block.txt

安装

cd ~/g/
ln -s `pwd`/gbadd.sh /usr/bin/gbadd
ln -s `pwd`/gblist.sh /usr/bin/gblist
ln -s `pwd`/gbdelete.sh /usr/bin/gbdelete

安装后可以直接使用

gbadd google.com
gblist
gbdelete google.com
gblist

卸载

rm /usr/bin/gbadd
rm /usr/bin/gblist
rm /usr/bin/gbdelete

你可能感兴趣的:(屏蔽网站)