与诸位爱墙人士分享一个关于DNS的小脚本
我说要有光2016/04/15软件综合 IP:河北
科学上网要求使用未被污染的 DNS ,但使用 ISP 提供之外的 DNS 通常会导致使用者无法享受各种 CDN 带来的加速福利。

为此,小光编写了一个方便实用的小脚本供大家参考,使用此脚本时请配合 iptables 中的 geoip 模块共同使用,将目标为墙内的 IP 分离出来进行直接连接,以便使其真正发挥效果。

在例子 "|08|bilibili|03|com" 中,第一个08是指 “bilibili” 这一域名包含8个字节,03则指“com”包含3个字节,您可以依此规则根据自己的需要增加修改这个列表。

<code class="lang-bash"># Create new chain
iptables -t nat -N DNSCRYPTPROXY
  
# MiniLight's whitelist
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|05|baidu|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|06|taobao|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|08|bilibili|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|05|hdslb|03|net" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|05|hdslb|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|05|iqiyi|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|02|qq|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|04|sina|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|06|wechat|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|05|weibo|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|03|163|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|07|tencent|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|06|alipay|03|com" --algo bm -j RETURN
iptables -t nat -A DNSCRYPTPROXY -m string --hex-string "|06|alicdn|03|com" --algo bm -j RETURN
  
# redirected DNS packet to dnscrypt-proxy
iptables -t nat -A DNSCRYPTPROXY -p tcp --dport 53 -j DNAT --to-destination 127.0.0.1:5353
iptables -t nat -A DNSCRYPTPROXY -p udp --dport 53 -j DNAT --to-destination 127.0.0.1:5353
  
# redirected DNS packet to DNSCRYPTPROXY chain
iptables -t nat -A OUTPUT -p tcp --dport 53 -j DNSCRYPTPROXY
iptables -t nat -A OUTPUT -p udp --dport 53 -j DNSCRYPTPROXY</code>
来自:计算机科学 / 软件综合
1
已屏蔽 原因:{{ notice.reason }}已屏蔽
{{notice.noticeContent}}
~~空空如也

想参与大家的讨论?现在就 登录 或者 注册

所属专业
所属分类
上级专业
同级专业
我说要有光
进士 学者 机友 笔友
文章
317
回复
5531
学术分
15
2008/03/06注册,4时59分前活动

Inspiration, Innovation, Discovery

主体类型:个人
所属领域:无
认证方式:手机号
IP归属地:未同步
文件下载
加载中...
{{errorInfo}}
{{downloadWarning}}
你在 {{downloadTime}} 下载过当前文件。
文件名称:{{resource.defaultFile.name}}
下载次数:{{resource.hits}}
上传用户:{{uploader.username}}
所需积分:{{costScores}},{{holdScores}}下载当前附件免费{{description}}
积分不足,去充值
文件已丢失

当前账号的附件下载数量限制如下:
时段 个数
{{f.startingTime}}点 - {{f.endTime}}点 {{f.fileCount}}
视频暂不能访问,请登录试试
仅供内部学术交流或培训使用,请先保存到本地。本内容不代表科创观点,未经原作者同意,请勿转载。
音频暂不能访问,请登录试试
支持的图片格式:jpg, jpeg, png
插入公式
评论控制
加载中...
文号:{{pid}}
投诉或举报
加载中...
{{tip}}
请选择违规类型:
{{reason.type}}

空空如也

加载中...
详情
详情
推送到专栏从专栏移除
设为匿名取消匿名
查看作者
回复
只看作者
加入收藏取消收藏
收藏
取消收藏
折叠回复
置顶取消置顶
评学术分
鼓励
设为精选取消精选
管理提醒
编辑
通过审核
评论控制
退修或删除
历史版本
违规记录
投诉或举报
加入黑名单移除黑名单
查看IP
{{format('YYYY/MM/DD HH:mm:ss', toc)}}