OpenWrt如何脱机(离线)下载BT文件

 

1.编译aria2

来源:http://www.jianshu.com/p/1042483f90fe

到处搜了下,知识都很零散和碎片,这里做下整理。
想要编译aria2要先编译openwrt。编译平台是debian8。
1.获取openwrt的代码
从openwrt拿到官方代码,见官方页面https://dev.openwrt.org/wiki/GetSource
想要最新的就拉trunk的代码,我之前路由刷的是15.05分支的,创建一个文件夹,拿这个分支的代码:

mkdir openwrt
cd openwrt
git clone git://git.openwrt.org/15.05/openwrt.git

2.安装编译需要的依赖

sudo apt-get install gcc g++ binutils patch bzip2 flex bison make autoconf gettext texinfo unzip sharutils subversion libncurses5-dev ncurses-term zlib1g-dev

3.进入源码文件夹,更新软件包

./scripts/feeds update -a

4.安装一下

./scripts/feeds install -a

5.定制固件

make menuconfig

选择平台,Target System我这里选Broadcom BCM63XX。
选择路由器型号,Target Profile我这里选华为HG556a C版。

默认是不编译aria2的,这里我们要让它编译aria2。
向下翻找到Network–>File Transfer–>aria2,按空格键选中。

默认配置不支持BT和磁力链,我们要配置一下,让我们编译出来的支持这2种下载方式。
选择aria2下面的Aria2 configuration,把里面的Enable bittorent support和Enable metalink support用空格键选中。

好,现在用方向键选Exit一路退出,最后退出时选YES保存一下

6.开始编译

make -j4 V=99

j后面的数字代表用几个线程来编译。
7.编译中遇到的坑
①因为在编译种需要联网下载一些包下来,所以编译的时候一定要联网。
②有的包联网了还不行,还要翻墙才能下载。
③有的包的下载地址用的http开头的无法下载,可以修改openwrt/include/download.mk文件,将第8行的http换成git

④第一遍编译时最好用make -j1 V=99来编译,即用一个线程来编译,以便编译出错时好定位哪里有问题。
8.编译完成
编译完成后在openwrt/bin/brcm63xx/packages/packages文件夹就会有一个aria2的ipk文件了。但是,这个版本是15.05自带的版本,我们需要最新的版本,所以接下来我们就要重新编译一下aria2.
9.下载最新的aria2代码
打开aria2的github项目,在Releases里面下载最新的代码,现在最新的是1.22.0
https://github.com/aria2/aria2/releases
我们选择下载aria2-1.22.0.tar.bz2这个版本
10.替换aria2的代码
将刚才下载的压缩包(不要解压)复制到openwrt/dl目录下,删掉原来的aria2 1.18的压缩包。
修改openwrt/feeds/packages/net/aria2/Makefile文件
将第10行的版本号修改为1.22.0
将第15行的MD5校验注释掉(前面加#号)

11.重新编译
好,现在可以重新编译了
先清除掉原来的编译结果

make package/feeds/packages/aria2/clean V=99

现在查看openwrt/bin/brcm63xx/packages/packages目录,前面编译的aria2 1.18版本已经被清除掉了。
重新编译

make package/feeds/packages/aria2/install V=99

等待一段时间,编译完成
再进到openwrt/bin/brcm63xx/packages/packages,已经可以华丽丽地看到aria2_1.22.0-1_brcm63xx.ipk出现在里面了。
大功告成。

 

2.配置

路由器OpenWrt如何脱机(离线)下载BT文件

来源:https://www.ytyzx.org/index.php?title=%E8%B7%AF%E7%94%B1%E5%99%A8OpenWrt%E5%A6%82%E4%BD%95%E8%84%B1%E6%9C%BA(%E7%A6%BB%E7%BA%BF)%E4%B8%8B%E8%BD%BDBT%E6%96%87%E4%BB%B6&oldid=4055
Ytyzx讨论 | 贡献2016年10月9日 (日) 02:34的版本
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

本例中所使用之方法为在路由器(OpenWrt维基百科)里面安装Aria2(实测下载速度快于Transmission),直接下载文件到路由器上连接的U盘里(移动硬盘的方法相似), 使用的路由器型号为巴法络(Buffalo)WZR-HP-G450H-CH(刷OpenWrt),前提为需保证路由器可正常连接上互联网。 需要使用以下软件:[PuTTY], WinSCP, Notepad++, FileZilla FTP Client。 如需使用DD-WRT并安装Transmission进行脱机下载,请点击路由器(DD-WRT)如何脱机下载BT文件

1.首先到如下网址下载OpenWrt固件(确保为您使用路由器型号)。 http://downloads.openwrt.org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-wzr-hp-g450h-squashfs-sysupgrade.bin

2.路由器升级完毕后在telnet命令行输入192.168.1.1(默认地址)连接到路由器(暂时断开上网路由器),默认密码为空,输入“passwd”命令修改密码,修改成功后输入“exit”退出。 如无法开启Telnet,则请点击[Telnet]开启Telnet.

3.在PuTTY中输入192.168.1.1并点击“Open”连接到路由器。关于PuTTY的使用请点击[如何安装及使用PuTTY]。

4.因路由器固件更新,出现如下提示,点击“是(Y)”继续。

5.输入账号(本例中为root)及密码登录。

6.输入“ifconfig”查看网络设置。

7.因本例中经另一个路由器(192.168.1.1)上网,故需修改网络设置,输入“vi /etc/config/network”。

8.按“i”进入编辑状态,将下图中蓝色方框内内容修改为正确的设置,本例中设置此路由器地址为192.168.1.250/24,网关和DNS均为192.168.1.1。 设置完毕后按ESC键并输入“:x”保存退出。

9.输入“/etc/init.d/network restart”重启服务,并连接上网路由器(192.168.1.1)。

10.重新打开PuTTY输入新地址(192.168.1.250)连接到路由器,如还是无法连接Internet,则输入“cd /etc”转到/etc目录,继续输入“vi resolv.conf”编辑文件, 亦可直接输入“vi /etc/resolv.conf”。

11.将下图蓝色方框内内容修改为另一路由器地址(本例中为192.168.1.1),即“nameserver 192.168.1.1”,修改完毕后按“ESC”并输入“:x”保存退出。

12.输入“opkg update”升级opkg。

13.输入“opkg install luci-ssl”安装luci。

14.提示luci安装完毕。

15.在浏览器地址栏输入此路由器地址(本例中为192.168.1.250),出现如下错误提示。

16.在PuTTY里输入“wget -O/etc/config/luci http://svn.luci.subsignal.org/luci/trunk/modules/base/root/etc/config/luci” 下载文件后, 重新安装luci-theme-bootstrap(opkg install luci-theme-bootstrap),安装完毕后输入“reboot”重启此路由器。

17.路由器重启完毕后再浏览器地址栏输入“192.168.1.250”即可打开luci,将U盘正确连接到路由器。

18.输入帐号密码登录,将鼠标移动到“System”,发现无“Mount Points”选项。

19.输入如下命令安装block-mount kmod-fs-ext4 kmod-usb-storage kmod-usb-storage-extras。建议首先运行“opkg update”更新opkg。 opkg install block-mount kmod-fs-ext4 kmod-usb-storage kmod-usb-storage-extras

20.重启路由器后用浏览器登录路由器,在“System”下已出现“Mount Points”选项(可与18步比较)。

21.用PuTTY登录,输入“ls /dev”查看到U盘已被正确识别(蓝色框内sda)。

22.输入“opkg install fdisk e2fsprogs”安装fdisk和e2fsprogs。

23.安装完毕后输入“fdisk /dev/sda”进行分区。

24.输入“m”可查看fdisk命令帮助,输入“n”开始添加新分区。

25.将U盘第一个分区设置为7000M,剩余空间设置为第二个分区。

26.输入“t”将第二个分区设置为交换分区(82),继续输入“w”设置分区表。

27.输入“fdisk -l”或者“ls /dev”即可发现sda1和sda2。

28.输入“mkfs.ext4 /dev/sda1”将第一个分区格式化为ext4格式。

29.输入“mkdir -p /mnt/aria2”在/mnt目录下新建名为aria2的目录,继续输入“mount -t ext4 /dev/sda1 /mnt/aria2 -o rw,sync”将sda1挂载到/mnt/aria2目录下。 注意:如出现类似以下错误,则需检查U盘是否正确连接到路由器或者检查路由器openwrt版本是否正确。 mount: mounting /dev/sda1 on /mnt/aria2 failed: No such device mount: mounting /dev/sda1 on /mnt/aria2 failed: Invalid argument

30.输入“mkswap /dev/sda2”将sda2设置为交换分区,继续输入“swapon /dev/sda2”挂载交换分区,输入“free”即可发现交换分区已正确挂载。 继续输入“df -h”查看sda1是否被正确挂载。

31.因需路由器启动时自动挂载U盘,故输入“block detect > /etc/config/fstab”生成标准fstab文件。

32.输入“vi /etc/config/fstab”编辑fstab文件。

33.本例中修改为如下配置并按ESC键,然后输入“:x”保存退出。如需详细了解各参数请点击以下网址。 http://wiki.openwrt.org/doc/uci/fstab

34.输入“/etc/init.d/fstab enable”使fstab文件在路由器启动时自动启动。 注意:以上修改完毕后,建议重启路由器,并使用“df -h”及“free”命令查看是否正确挂载。

35.用WinSCP连接到路由器,并将下载之aria2文件复制到/tmp目录,因aria2从1.18.5版本后默认不支持BT,故不建议使用“opkg install aria2”安装。

36.在PuTTY里输入“opkg install /tmp/aria2.ipk”安装aria2。

37.安装完毕后输入“aria2c -v”查看aria2版本,本例中版本为1.18.5.

38.安装完毕后输入“touch /mnt/aria2/aria2.session”新建aria2.session文件。

39.输入“aria2c –enable-rpc=true –rpc-listen-all=true –rpc-allow-origin-all -c”启动aria2,需确保可以正常启动再进行下一步。

40.为开机自动启动aria2需新建一个配置文件,首先按“ctrl+c”中止aria2,然后输入“vi /etc/aria2.conf”在/etc目录下新建名为aria2.conf的配置文件。

41.按“i”键进入输入状态,输入如下内容,确保无误后按ESC键并输入“:x”保存退出,注意蓝色框内部分需和您的设置一致。

   #Aria2 configuration
   # RPC Setting
   enable-rpc=true
   rpc-listen-all=true
   rpc-allow-origin-all=true
   rpc-listen-port=6800
   # General Setting
   dir=/mnt/aria2
   input-file=/mnt/aria2/aria2.session
   save-session=/mnt/aria2/aria2.session
   save-session-interval=60
   log=/mnt/aria2/aria2.log
   log-level=warn
   #event-poll=select
   disk-cache=8M
   #enable-mmap=true
   file-allocation=trunc
   user-agent=uTorrent/2210(25130)
   # Connection Setting
   continue=true
   max-connection-per-server=5
   max-concurrent-downloads=3
   min-split-size=5M
   split=5
   max-overall-download-limit=0
   max-overall-upload-limit=0
   max-upload-limit=0
   lowest-speed-limit=0
   auto-save-interval=300
   # BT Setting
   bt-require-crypto=true
   bt-max-peers=100
   enable-peer-exchange=true
   follow-torrent=true
   listen-port=6881-6999

42.亦可在NotePad++里面编辑,然后修改名字为“aria2.conf”。

43.使用WinSCP连接到路由器,将此文件(aria2.conf)复制到“/etc”目录下。

44.输入命令“aria2c –conf-path=/etc/aria2.conf”从配置文件启动aria2。

45.确认可以从配置文件正常启动后,使用浏览器登录路由器,在“System”下点击“Startup”并向下拉动右侧滑动条,找到“Local Startup”框, 输入“aria2c –conf-path=/etc/aria2.conf -D”,并点击右下方“Submit”保存,使aria2在路由器启动是自动在后台运行。

46.因aria2默认为命令行界面,为方便起见,安装图形管理界面YAAW(Yet Another Aria2 Web),点击这里下载。 亦可将以下网址复制到浏览器打开,然后点击右下方的“Download ZIP”按钮下载。 https://github.com/binux/yaaw

47.解压此文件,将文件夹名修改为一个您喜欢的名字(本例中修改为aria2),并使用WinSCP将此文件夹复制到路由器“/www”目录下。

48.在浏览器地址栏输入“路由器IP地址/文件夹名字”(本例中为192.168.1.250/aria2)即可打开YAAW,点击“Add”添加种子文件。 如出现“internal server error”错误,则需检查aria2是否已正常运行或查看YAAW作者网页

49.点击“Upload Torrent”添加种子文件,亦可直接输入下载地址。注意在下图蓝色框内“Dir”输入您设置的下载目录(本例中为/mnt/aria2),点击“Add”按钮确定。

50.开始下载文件。

51.文件下载完毕。

52.因OpenWrt默认不支持FTP,故需要安装vsftpd(very secure FTP daemon),在PuTTY里面输入“opkg install vsftpd”安装。

53.在浏览器里打开路由器控制界面,点击“System”并选择“Startup”,确认vsftpd已经默认启动,建议重启路由器查看是否启动。

52.使用FileZilla把文件复制到本机即可。

 

openwrt手动指定dns服务器

v配置文件为/etc/config/dhcp

config dhcp ‘lan’
option interface ‘lan’
option start ‘100’
option limit ‘150’
option leasetime ’12h’
option dhcpv6 ‘server’
option ndp ‘relay’
option ra ‘relay’
list dns ‘221.228.255.1’
list dns ‘2001:470:0:9d::2’
option ra_management ‘1’

openwrt wget支持https

openwrt使用https的源出错
openwrt wget: can’t execute ‘openssl’: No such file or directory
解决:为openwrt安装ssl支持

opkg install wget ca-certificates

用wget建立网站镜像

为openwrt建立镜像
wget -c -r -np -k -L -p http://downloads.openwrt.org/chaos_calmer/15.05.1/ar71xx/nand/

以下为参考文章:http://www.cnblogs.com/lidp/archive/2010/03/02/1696447.html
需要下载某个目录下面的所有文件。命令如下
wget -c -r -np -k -L -p www.xxx.org/pub/path/

在下载时。有用到外部域名的图片或连接。如果需要同时下载就要用-H参数。

wget -np -nH -r –span-hosts www.xxx.org/pub/path/

-c 断点续传
-r 递归下载,下载指定网页某一目录下(包括子目录)的所有文件
-nd 递归下载时不创建一层一层的目录,把所有的文件下载到当前目录
-np 递归下载时不搜索上层目录,如wget -c -r www.xxx.org/pub/path/
没有加参数-np,就会同时下载path的上一级目录pub下的其它文件
-k 将绝对链接转为相对链接,下载整个站点后脱机浏览网页,最好加上这个参数
-L 递归时不进入其它主机,如wget -c -r www.xxx.org/
如果网站内有一个这样的链接:
www.yyy.org,不加参数-L,就会像大火烧山一样,会递归下载www.yyy.org网站
-p 下载网页所需的所有文件,如图片等
-A 指定要下载的文件样式列表,多个样式用逗号分隔
-i 后面跟一个文件,文件内指明要下载的URL

还有其他的用法,我从网上搜索的,也一并写上来,方便以后自己使用。

wget的常见用法

wget的使用格式
Usage: wget [OPTION]… [URL]…

* 用wget做站点镜像:
wget -r -p -np -k http://dsec.pku.edu.cn/~usr_name/
# 或者
wget -m http://www.tldp.org/LDP/abs/html/

* 在不稳定的网络上下载一个部分下载的文件,以及在空闲时段下载
wget -t 0 -w 31 -c http://dsec.pku.edu.cn/BBC.avi -o down.log &
# 或者从filelist读入要下载的文件列表
wget -t 0 -w 31 -c -B ftp://dsec.pku.edu.cn/linuxsoft -i filelist.txt -o
down.log &

上面的代码还可以用来在网络比较空闲的时段进行下载。我的用法是:在mozilla中将不方便当时下载的URL链接拷贝到内存中然后粘贴到文件filelist.txt中,在晚上要出去系统前执行上面代码的第二条。

* 使用代理下载
wget -Y on -p -k https://sourceforge.net/projects/wvware/

代理可以在环境变量或wgetrc文件中设定

# 在环境变量中设定代理
export PROXY=http://211.90.168.94:8080/
# 在~/.wgetrc中设定代理
http_proxy = http://proxy.yoyodyne.com:18023/
ftp_proxy = http://proxy.yoyodyne.com:18023/

wget各种选项分类列表

* 启动

-V, –version 显示wget的版本后退出
-h, –help 打印语法帮助
-b, –background 启动后转入后台执行
-e, –execute=COMMAND
执行`.wgetrc’格式的命令,wgetrc格式参见/etc/wgetrc或~/.wgetrc

* 记录和输入文件

-o, –output-file=FILE 把记录写到FILE文件中
-a, –append-output=FILE 把记录追加到FILE文件中
-d, –debug 打印调试输出
-q, –quiet 安静模式(没有输出)
-v, –verbose 冗长模式(这是缺省设置)
-nv, –non-verbose 关掉冗长模式,但不是安静模式
-i, –input-file=FILE 下载在FILE文件中出现的URLs
-F, –force-html 把输入文件当作HTML格式文件对待
-B, –base=URL 将URL作为在-F -i参数指定的文件中出现的相对链接的前缀
–sslcertfile=FILE 可选客户端证书
–sslcertkey=KEYFILE 可选客户端证书的KEYFILE
–egd-file=FILE 指定EGD socket的文件名

* 下载

–bind-address=ADDRESS
指定本地使用地址(主机名或IP,当本地有多个IP或名字时使用)
-t, –tries=NUMBER 设定最大尝试链接次数(0 表示无限制).
-O –output-document=FILE 把文档写到FILE文件中
-nc, –no-clobber 不要覆盖存在的文件或使用.#前缀
-c, –continue 接着下载没下载完的文件
–progress=TYPE 设定进程条标记
-N, –timestamping 不要重新下载文件除非比本地文件新
-S, –server-response 打印服务器的回应
–spider 不下载任何东西
-T, –timeout=SECONDS 设定响应超时的秒数
-w, –wait=SECONDS 两次尝试之间间隔SECONDS秒
–waitretry=SECONDS 在重新链接之间等待1…SECONDS秒
–random-wait 在下载之间等待0…2*WAIT秒
-Y, –proxy=on/off 打开或关闭代理
-Q, –quota=NUMBER 设置下载的容量限制
–limit-rate=RATE 限定下载输率

* 目录

-nd –no-directories 不创建目录
-x, –force-directories 强制创建目录
-nH, –no-host-directories 不创建主机目录
-P, –directory-prefix=PREFIX 将文件保存到目录 PREFIX/…
–cut-dirs=NUMBER 忽略 NUMBER层远程目录

* HTTP 选项

–http-user=USER 设定HTTP用户名为 USER.
–http-passwd=PASS 设定http密码为 PASS.
-C, –cache=on/off 允许/不允许服务器端的数据缓存 (一般情况下允许).
-E, –html-extension 将所有text/html文档以.html扩展名保存
–ignore-length 忽略 `Content-Length’头域
–header=STRING 在headers中插入字符串 STRING
–proxy-user=USER 设定代理的用户名为 USER
–proxy-passwd=PASS 设定代理的密码为 PASS
–referer=URL 在HTTP请求中包含 `Referer: URL’头
-s, –save-headers 保存HTTP头到文件
-U, –user-agent=AGENT 设定代理的名称为 AGENT而不是 Wget/VERSION.
–no-http-keep-alive 关闭 HTTP活动链接 (永远链接).
–cookies=off 不使用 cookies.
–load-cookies=FILE 在开始会话前从文件 FILE中加载cookie
–save-cookies=FILE 在会话结束后将 cookies保存到 FILE文件中

* FTP 选项

-nr, –dont-remove-listing 不移走 `.listing’文件
-g, –glob=on/off 打开或关闭文件名的 globbing机制
–passive-ftp 使用被动传输模式 (缺省值).
–active-ftp 使用主动传输模式
–retr-symlinks 在递归的时候,将链接指向文件(而不是目录)

* 递归下载

-r, –recursive 递归下载--慎用!
-l, –level=NUMBER 最大递归深度 (inf 或 0 代表无穷).
–delete-after 在现在完毕后局部删除文件
-k, –convert-links 转换非相对链接为相对链接
-K, –backup-converted 在转换文件X之前,将之备份为 X.orig
-m, –mirror 等价于 -r -N -l inf -nr.
-p, –page-requisites 下载显示HTML文件的所有图片

* 递归下载中的包含和不包含(accept/reject)

-A, –accept=LIST 分号分隔的被接受扩展名的列表
-R, –reject=LIST 分号分隔的不被接受的扩展名的列表
-D, –domains=LIST 分号分隔的被接受域的列表
–exclude-domains=LIST 分号分隔的不被接受的域的列表
–follow-ftp 跟踪HTML文档中的FTP链接
–follow-tags=LIST 分号分隔的被跟踪的HTML标签的列表
-G, –ignore-tags=LIST 分号分隔的被忽略的HTML标签的列表
-H, –span-hosts 当递归时转到外部主机
-L, –relative 仅仅跟踪相对链接
-I, –include-directories=LIST 允许目录的列表
-X, –exclude-directories=LIST 不被包含目录的列表
-np, –no-parent 不要追溯到父目录

openwrt DNScrypt

DNSCrypt

DNSCrypt offers a way to protect clients against attacks related to the modification and manipulation of DNS traffic — The main objective of DNSCrypt is authentication of the communication channel between the client (you) and a resolver supporting the protocol — This will protect the client fromman in the middle attacks. In addition, encryption of DNS communication improves the client’s privacy. DNSCrypt is the client-side version ofdnscrypt-wrapper.

The dnscrypt-proxy client project is maintained by Frank Denis jedisct1

DNSCrypt verifies that responses you get from a DNS provider have been actually sent by that provider, and haven’t been tampered with.

This is not a VPN. It doesn’t mask your IP address, and if you are using it with a public DNS service, be aware that it will (and has to) decrypt your queries.

If you are using it for privacy, it might do the opposite of what you are trying to achieve. If you are using it to prevent VPN “leaks”, this isn’t the right tool either: the proper way to prevent VPN “leaks” is to avoid sending data to yet another third party: use a VPN service that operates its own DNSresolvers.

Installation

dnscrypt-proxy and libsodium is in the official repository for Chaos Calmer 15.05 and up.

opkg update
opkg install dnscrypt-proxy
  • If installed skip to configuration.
  • If somehow you can’t install it that way, proceed with the following instructions.

ar71xx and Barrier Breaker

The OpenWrt package for ar71xx is maintained by black-roland.

Differences with OpenWrt packages:

Package Difference
dnscrypt-proxy Newest version for Chaos Calmer. Barrier Breaker support. Procd support and possibility of launching multiple instances.
libsodium Newest version for Chaos Calmer. Barrier Breaker support.
iodine Memory usage reduce patch.

This will install dnscrypt-proxy as well as any dependent libraries such as libsodium

Add third-party source to your opkg configuration file /etc/opkg.conf according to your OpenWRT version.

Chaos Calmer:

cd /tmp
wget 'http://exopenwrt.roland.black/exopenwrt.pub'
opkg-key add exopenwrt.pub
echo 'src/gz exopenwrt http://exopenwrt.roland.black/chaos_calmer/15.05/ar71xx/packages/exopenwrt/' >> /etc/opkg.conf

Barrier Breaker:

http://exopenwrt.roland.black/barrier_breaker/14.07/ar71xx/packages/exopenwrt

And proceed with the installation itself:

opkg update
opkg install dnscrypt-proxy

Forum thread

Configuration

DNSCrypt is listening on address and port: 127.0.0.1:5353. We need to set OpenWRT to send DNS request to that address.

Server configuration

dnscrypt-proxy

The config file /etc/config/dnscrypt-proxy is simple and should be edited according to your needs. Possible values for the ‘resolver’ option are the first column in the list of public DNSCrypt resolvers.

config dnscrypt-proxy option address '127.0.0.1' option port '5353' # option resolver 'cisco' # option resolvers_list '/usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv' # option ephemeral_keys '1'

Description:

Name Type Required Default Description
address string yes 127.0.0.1 The IP address of the proxy server.
port string yes 5353 Listening port for DNS queries.
resolver string no cisco DNS service for resolving queries. You can’t add more than one resolver.
resolvers_list string no /usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv Location of CSV file containing list of resolvers.
ephemeral_keys boolean no 0 Improve privacy by using an ephemeral public key for each query. Recommended if you are not using your own server. Ephemeral keys option requires extra CPU cycles and can cause huge system load. Disable it in case of performance problems.

If you need to specify other options, you will have to edit the /etc/init.d/dnscrypt-proxy script.

Note: I’ve had a little bit of confusion at setup, so I want to remind you; address and port strings are for local proxy server, you just have to pick a dnscrypt server from the resolvers list, put its name in resolver string and comment out resolvers and resolvers list settings.

Now we will start DNSCrypt and enable auto boot for it:

/etc/init.d/dnscrypt-proxy enable
/etc/init.d/dnscrypt-proxy start

Note: If dnscrypt-proxy is not starting after a router reboot, it may be trying to start before the network interface is fully up. Add the following to /etc/rc.local, above the line “exit 0”:

sleep 10
/etc/init.d/dnscrypt-proxy start

dnsmasq

Assuming you are using dnsmasq, edit the bold lines in /etc/config/dhcp

config dnsmasq option domainneeded 1 option boguspriv 1 option filterwin2k 0 option localise_queries 1 option rebind_protection 1 option rebind_localhost 1 option local '/lan/' option domain 'lan' option expandhosts 1 option nonegcache 0 option authoritative 1 option readethers 1 option leasefile '/tmp/dhcp.leases' # option resolvfile '/tmp/resolv.conf.auto' option noresolv 1 list server '127.0.0.1#5353' list server '/pool.ntp.org/208.67.222.222' # list server '208.67.222.222' # list server '208.67.220.220'
  • We have disabled /tmp/resolv.conf.auto file since it instruct dnsmasq to use your ISP’s DNS.
  • noresolv option also disables /etc/resolv.conf file for similar reason.
  • 127.0.0.1#5353 is the DNSCrypt address.
  • /pool.ntp.org/208.67.222.222 adds an exception for pool.ntp.org, which will be resolved through the standard unencrypted DNS channel. DNSCrypt requires precise time, otherwise it will not resolve any domain, including pool.ntp.org. So if your device’s time was incorrect, it could never update its time, and therefore DNSCrypt would never work. So we set this exception so that pool.ntp.org queries will always bypass DNSCrypt and resolve with the standard unencrypted OpenDNS method.

Reboot router or restart dnsmasq for the changes to take effect.

/etc/init.d/dnsmasq restart

Client configuration

Note: you may need admin privileges to run the commands below.

Linux

sudo /etc/init.d/nscd restart

or

sudo /etc/init.d/networking restart

Windows

ipconfig /flushdns

Mac OS X

  • Mac OSX 10.4 (Tiger)
    • lookupd -flushcache
  • Mac OSX 10.5/10.6 (Leopard/Snow Leopard)
    • dscacheutil -flushcache

Troubleshooting

How to check what features are supported by your resolver

  1. The DNS leak test or DNS randomness test will show the actual IP of your DNS. You can check here if the IP is associated with the service you are using (put the IP in the search field).
  2. DNSSEC resolver test determines whether your DNS resolver validates DNSSEC signatures.
  3. If you can access DNSCrypt.bit, your resolver can resolve domain names using Namecoin.

How to check if your DNS queries are using dnscrypt

On the router:

pkill -STOP dnscrypt-proxy

DNS resolution should not work any more.

To restore service, unfreeze the client proxy:

pkill -CONT dnscrypt-proxy

How to check if dnscrypt-proxy is set up and running

The easy way is to look in the log.

  1. Check if dnsmasq is using only dnscrypt. Only the last block of logged nameservers is relevant.
    • logread | grep -n "using nameserver"
    • 132:Jan  1 01:01:00 openwrt daemon.info dnsmasq[1883]: using nameserver 208.67.222.222#53 for domain pool.ntp.org
      133:Jan  1 01:01:00 openwrt daemon.info dnsmasq[1883]: using nameserver 127.0.0.1#5353
  2. Check that dnscrypt-proxy is working.
    • logread | grep "Proxying from"
    • Jul 1 12:00:00 openwrt daemon.info dnscrypt-proxy[1831]: Proxying from 127.0.0.1:5353 to 208.67.220.220:443

Suspicious certificate received

A “suspicious” certificate can be reported:

root@OpenWrtRouter:/tmp# ./dnscrypt-proxy -R dnscrypt.eu-nl -a 127.0.0.1:5353 [INFO] Generating a new key pair [INFO] Done [ERROR] Suspicious certificate received [ERROR] No useable certificates found [INFO] Refetching server certificates [ERROR] Suspicious certificate received [ERROR] No useable certificates found

Check the date and time on your router: this kind of behavior is usually caused by a system clock that hasn’t been set properly.

利用dnsmasq自动翻墙及防dns劫持

首先dnsmasq是什么
它是一个dns缓存转发器,它先缓存一些dns记录,我们再用的时候就是直接访问路由里面的dns条目,而不会再去解析一次,节省了时间
比如说我们访问g.cn,因为最近这个域名会被先转到google.cn,再转到google.com.hk,所以每次解释域名就得等待10来秒,用dnsmasq之后这个时间就省了
当然第一次的时候还是要解析一次,以后就好了,缓存过多自动删掉一些就另当别论了
最近网上出现各种hosts,虽然可以直接放到电脑和手机里,但是用路由器更加方便一点
好谈翻墙的问题
将dd切换到服务界面,会看到dnsmasq下面有一个很空的地方让你填,这个就是今天最主要的地方了

address=/.youtube.com/203.208.46.30
address=/.ytimg.com/203.208.46.30
address=/.googlevideo.com/203.208.46.30
address=/.2mdn.net/203.208.46.30
将上面的复制进去就行了
在开浏览器试试上youtube就可以了
意思很简单address后面的域名会自动解析到后面的ip,类似于hosts 的效果
不过不用像hosts一样复制一长串,因为这个有点通配符的意思,*.youtube.com都是到203.208.46.30

我还尝试加ipv6的地址,可惜路由会挂掉,只能插网线,并且电脑配固定ip改回来
address=/.blogger.com/2001:4860:8006::bf
address=/.blogspot.com/2001:4860:8006::62
address=/.appspot.com/2001:4860:8006::8d
有兴趣的看可以尝试一下
照http://www.linuxidc.com/Linux/2011-03/33072.htm 看是支持这样写ipv6的,可能是dd里面的不支持

当然dnsmasq是支持hosts文件的,它会默认读取/etc/hosts文件
不过有一个问题重启后hosts文件就还原了,总不能一次次传吧
当然你可以把hosts文件传到网上去,然后用命令wget下来(可以到管理里面设为开机命令,cd /tmp wget http://xxx.xxx/host(放在tmp比较好))
对了dnsmasq可以指定hosts
addn-hosts=/tmp/dnsmasq.hosts
还是填在刚才的地方,那地方相当于在配置dnsmasq的配置文件linux上在/etc/dnsmasq.conf可惜dd上找不到在哪

一般情况下dns解析是从你的isp的dns服务器那缓存下来的,当然也可以改
设置#不读取/etc/resolv.conf文件
no-resolv
#不扫描/etc/resolv.conf和/etc/dnsmasq.conf文件的改动,如果有改动直接重启程序即可
no-poll
#设置dns服务器
server=8.8.8.8
server=8.8.8.4 #google的dns,你也可以使用opendns的server
这样以后就会从google的dns缓存

至于dns劫持,比较常见的一种情况就是输错网址然后跳动isp的广告页面如 http://nfdnserror8.wo.com.cn:8080/?HOST=fuck.U&R=/&
这种一般勉强还能接受,严重的如这里 http://www.cnbeta.com/articles/23851.htm
我这的会劫持一些它不想我访问的网站如google的一些服务
先获得这些地址的ip
然后还是刚才的地方
bogus-nxdomain=123.129.254.11
bogus-nxdomain=123.129.254.12
bogus-nxdomain=123.129.254.13
bogus-nxdomain=123.129.254.14
bogus-nxdomain=123.129.254.15
bogus-nxdomain=123.129.254.16
bogus-nxdomain=123.129.254.17
bogus-nxdomain=123.129.254.18
这些填进去,后面的ip换成你的可以有多个

更新:关于这个,这里还有 http://blog.kangkang.org/index.php/archives/141 跟我们没关系,上面已经实现了,这是openwrt的(其实也可以改配置文件)留着作为研究之用

前面有写server=8.8.8.8这里是全部的
也可以只让部分网站从自定义的dns解析
用server=/google.com/8.8.8.8
详见这里http://bbs.pku6.edu.cn/bbs/bbstc … p;threadid=12826958

参考资料,除了上面的还有
http://server.blog.163.com/blog/static/1076358201162424629295/

openwrt的配置文件在/etc/dnsmasq.conf直接改就行了

OpenWRT 设置 IPv6 的问题

发信人: MasterXJ (Master), 信区: Networking
标 题: Re: OpenWRT 设置 IPv6 的问题
发信站: 北大未名站 (2015年07月16日20:48:44 星期四), 站内信件

1. 有。
2. 不是。

OpenWrt安装之后的默认配置是在wan口使用DHCPv6的客户端,在lan口开启RA和DHCPv6的
服务端(odhcpd)。这个默认配置应该适用于国外主流ISP,因为他们通过DHCPv6-PD (pre
fix delegation)把一个至少/64的地址段都分配用户使用。不过我们学校现在采用SLAAC
的方式分配地址(除了畅春新园正在测试DHCPv6,每个用户单一地址的那种),所以得修
改/etc/config/dhcp,在LAN和WAN之间relay RA和NDP(WAN是master),像下面这样:
config dhcp ‘lan’
option interface ‘lan’
……(省略)
option ndp ‘relay’
option ra ‘relay’

config dhcp ‘wan’
option interface ‘wan’
#option ignore ‘1’ (注释掉这行)
option ndp ‘relay’
option ra ‘relay’
option master ‘1’

但是改完之后ND proxy还有问题:odhcpd从wan口收到NS请求之后会在lan接口ping一下目
标地址(比如2001:da8:201:xxxx::yyyy),但如果路由表里lan接口到达不了这个地址,
lan就收不到NS以及这个echo request,NDP就不能工作。所以还需要给lan口增加你所在
网段的路由:
route -A inet6 add 2001:da8:201:xxxx::/64 dev br-lan
或者用iproute2:
ip -6 r a 2001:da8:201:xxxx::/64 dev br-lan
这样内网应该就能正常访问IPv6了。

不过可能不久以后就会推广DHCPv6,到时这个方法就没什么用了。
现在用OpenWrt/odhcpd relay DHCPv6似乎问题更多,大概有以下几点:
1. 校园网的DHCPv6服务器(目前)不支持relay-forward请求,所以不能relay
2. odhcpd在向上级DHCPv6服务器发送relay-forward的时候似乎用错了socket
3. 上面提到的那个lan接口没有路由的问题依然存在
4. 用DHCPv6以后,OpenWrt自己的路由表的默认路由绑定在自己的地址上的,例如
default from 2001:da8:201:xxxx::yyyy/128 via fe80::xxxx
所以还要手动增/改默认路由

【 在 Leedy (LeeDY) 的大作中提到: 】
: 1. 有人现在设置成功了吗?
: 2. 学校似乎不提供获取 IPv6 prefix 的功能,是不是意味着没法用 odhcpd 了?

※ 来源:·北大未名站 bdwm.net·[FROM: 162.105.220.29]

IPv6 配置指南(Backfire及更高版本适用)

本页面替代 旧的 IPv6指南页面。本页面内容有待进一步完善,如有疑问可到 IRC 频道(#openwrt)寻求帮助。本页面内容会不定时更新。

这篇帮助文档将讲述如何在基于Openwrt的路由器上配置IPv6。

我们为什么需要IPv6?(ipv6.theory)

开启 IPv6 支持

可以按照这篇帮助文档的介绍在您的路由上开启完整的IPv6支持: ipv6.essentials。

主要有两个大步骤,分几步进行:

设置路由器,使之通过隧道(SixXs、TSP、6to4等)或原生IPv6网络,连接到IPv6公共网络。
使用radvd或者DHCPv6在LAN口广播IPv6子网信息。
还有第三个小一点的步骤:

设置ipv6tables,按防火墙规则隔离和保护LAN网络。
准备并检验 IPv6 连网

大多数ISP服务商都在向IPv6迁移。IPv6路由使用了好几种不同的技术,其中包括tunnel brokers 。

要启用 IPv6,我们需要安装如下几个东西:

IPv6内核模块(必须)
IPv6路由软件(必须,用于实现IPv6路由功能)
ip6tables的内核模块(可选,如果想安装IPv6防火墙的话,就必须安装)
ip6tables命令行工具(可选,用于配置IPv6防火墙及其规则)
opkg install kmod-ipv6 radvd ip kmod-ip6tables ip6tables

用上述命令安装好IPv6内核模块及相关工具软件之后,telnet或ssh到路由器上,敲入 ping6 ipv6.google.com,应该能ping通。

如果 ping6 ipv6.google.com ping不通,而 ping6 [2a00:1450:8002::93] 却能ping通,这说明你的DNS不支持IPv6域名解释,得更改DNS设置使支持IPv6域名解释(见下文相关章节)。

如果路由开启了防火墙,要记得在防火墙设置文件里面启用IPv6(默认规则下凡IPv6被全部丢弃):

config defaults
option syn_flood 1
option drop_invalid 1
option input ACCEPT
option output ACCEPT
option forward REJECT
# 取消注释下面这一行,将禁止IPv6规则:
# option disable_ipv6 1

有固定IPv6地址前缀的原生IPv6网络连接

“有固定IPv6地址前缀”指的是你的ISP服务商为每一个客户端提供了至少一个/64地址前缀,如果服务商提供/56或者/48地址前缀,则更好(相当于IPv4网络的“固定IP”)。很多专业ISP服务商都会提供这种固定IPv6地址前缀。以下是目前已知的提供这样的地址前缀的ISP服务商列表:

Nerim (法国)
FDN (法国)
Internode (澳大利亚)
TekSavvy (加拿大)
[..] ❗ 请补充更多提供原生IPv6网络地址前缀的ISP服务商。
在下面的例子中,假设ISP服务商分派的网络地址前缀为2001:123:456::/48。在这个前缀所包括的地址范围内,我想让LAN网络使用2001:123:456:789::/64地址子范围,路由器本身对LAN端的固定IPv6地址设置为2001:123:456:789::1。

/etc/config/network:

config interface lan
option ifname eth1
option type bridge
option proto static
option ipaddr 192.168.1.1
option netmask 255.255.255.0
option ip6addr ‘2001:123:456:789::1/64’

如果使用 PPPoEv6,要开启ipv6。可能还要进一步将MTU值减小到1452:根据经验,这样设置可避免许多问题。你可以把MTU值设大一点,但不要超过1492。

config interface wan
option ifname eth0
option proto pppoe
option username ‘<username>’
option password ‘<password>’
option keepalive 5
option defaultroute 1
option peerdns 1
option ipv6 1
option mtu 1452

6in4 隧道连接

|6in4是一种将IPv6传输封装进IPv4管道内的技术。该技术多由 tunnel brokers 使用,需要手动配置。

关于这种连接方式,这里有一个非常棒的论坛主题讨论。

Both imply a static prefix, and thus a manual configuration.

The ISP known to use this are:

Comcast (USA)
Free.fr (France)
❗ 必须安装 6in4 才能使用该协议。

❗ 6to4 隧道的例子在页面 config/network 。

对于这种连接技术,另一个”interface”会建立并成为IPv6封包默认的出站接口

允许6in4流量总是能到达你的隧道终端,你可能需要在你的防火墙配置中添加如下规则

config rule
option src wan
option proto 41
option target ACCEPT

固定 6in4 隧道

/etc/config/network 固定隧道的配置:

config interface henet
option proto 6in4
option ipaddr ‘178.24.115.19’
option peeraddr ‘216.66.80.30’
option ip6addr ‘2001:0DB8:1f0a:1359::2/64’

动态 6in4 隧道

以下的例子描述了he.net动态隧道配置并可以更新IP地址的设置文件。本地的IPv4地址会自动获取,tunnelid,username及password是用于更新IP地址。 /etc/config/network 动态隧道配置:

config interface henet
option proto 6in4
option peeraddr ‘216.66.80.30’
option ip6addr ‘2001:0DB8:1f0a:1359::2/64’
option tunnelid ‘12345’
option username ‘098f6bcd4621d373cade4e832627b4f6’
option password ‘secret’

在这些以下例子中:

178.24.115.10 是本端的IPv4地址 (由ISP分配)
216.66.80.30 是对端的IPv4地址 (隧道的另一端)
2001:0DB8:1f0a:1359::2/64 是本端的IPv6(由隧道提供者分配的)
tunnelid,username,password is provided by the ISP or the tunnel broker (这里username是HE帐户主页中的UserID).
这个隧道,如同VPN一样,建立了另一个网络接口,本例中称作henet

隧道的网络接口成功的连接后,默认的ipv6路由会自动添加

❗ 对隧道接口添加IPv6防火墙规则,把它加入防火墙的WAN区域 /etc/config/firewall: config ‘zone’
option ‘name’ ‘wan’
option ‘network’ ‘wan henet’
option ‘input’ ‘REJECT’
option ‘forward’ ‘REJECT’
option ‘output’ ‘ACCEPT’
option ‘masq’ ‘1’

❗ 没有经过测试,请根据需要自行修改

你同样需要添加你的前缀到LAN接口,使得路由器知道在LAN口发送IPv6封包:

config interface lan
option ifname eth0
option type bridge
option proto static
option ipaddr 192.168.1.1
option netmask 255.255.255.0
option ip6addr ‘2001:0DB8:1f0b:1359:1::1/64’

6to4, 6rd

6to4 是使用特定中继服务器的,将IPv6与IPv4封包互转的连接技术.
6rd (for rapid deployment) 同6to4很近似的,但具有一定限制的,供大型ISP路由使用。

但由于特定的路由机制,这只在等于或高于2.6.33的kernel支持

你需要安装在10.03.1-rc4版本之后支持的6to4安装包,以便6to4能正常工作。

opkg install 6to4

如果你的Openwrt的平台是10.03,你仍然可以从较新版本的源码下载该包来安装。

opkg install http://downloads.openwrt.org/backfire/10.03.1-rc4/brcm47xx/packages/6to4_2-1_all.ipk

❗ 将 brcm47xx 替换为你所使用的分支.

对于这种连接原理,另一个“interface”会被建立来提供默认的IPv6出站接口。 例子/etc/config/network 对ISP是 “Qfast.nl”, 或者是其它使用该技术的ISP的配置大概如下:

config interface 6rd
option proto 6to4
option adv_subnet 1 # Selects the advertised /64 prefix, default 1 if not specified

尽管还有更多的“options”,多数的配置是默认的(例如 “ipaddress”和“advertising interface”) 参见 /etc/config/network 这里有关于6to4信息.

“radvd”和你的lan接口默认是自动配置的,替换lan接口和外部IP地址段所提供的一个/64的路由前缀

你只需要在接口将“ignore 1”修改为“ignore 0”。

我的/etc/config/radvd 如下:

config interface
option interface ‘lan’
option AdvSendAdvert 1
option AdvManagedFlag 0
option AdvOtherConfigFlag 0
option ignore 0

config prefix
option interface ‘lan’
# If not specified, a non-link-local prefix of the interface is used
option prefix ” #These are supposed to be 2 single-quotes
option AdvOnLink 1
option AdvAutonomous 1
option AdvRouterAddr 0
option ignore 1

将IPv6规则应用到这个隧道, 将它加入”wan”区域/etc/config/firewall:

config zone
option name ‘wan’
option network ‘wan wan6’
option input REJECT
option forward REJECT
option output ACCEPT
option masq 1
将一下规则加入 /etc/config/firewall 来允许IPv6封包入站:

config ‘rule’
option ‘target’ ‘ACCEPT’
option ‘_name’ ‘6to4’
option ‘src’ ‘wan’
option ‘proto’ ’41’

这些配置也可以在web接口“luci”中完成

:!:经过测试. 与wan区域比较,尽管我不确定该将wan6加入防火墙的作用。

也许它会阻止没有被防火墙屏蔽的IPv4从IPv6接口进入。有谁能提示一下?

由于/etc/config/firewall 只控制IPv4, 你仍然需要根据它编写你自己的ip6tables规则

TSP Tunneling

Tunnel Setup Protocol 用于一些隧道服务. Gogo6 (ex Freenet6) 是为私人提供的最流行的免费隧道服务

❗ 必须安装 gw6c 来使用这个协议 (e.g.: opkg update && opkg install gw6c).

gw6c在这个文件中配置: /etc/config/gw6c.

首先你需要注册你的freenet6帐户 here 接下来就是在你的路由器上配置gw6c

以下例子适用于用户已有注册帐号,并需要在lan分发一个前缀

其中的userid/passwd 区域必须填写为你在上面注册的来进行认证。

config gw6c basic
#Comment out next line to enable gw6c
option disabled 0

#Leave empty if connecting anonymously
option userid <YOURFREENET6USERID>
option passwd <YOURFREENET6PASSWD>

#For anonymous use anon.frenet6.net and
#account holders should use broker.freenet6.net
option server authenticated.freenet6.net

#auth_method <anonymous|any|passds-3des-1|digest-md5|plain>
#Use anonymous with anonymous access and
#any if you are account holder
option auth_method any

config gw6c routing
#host_type <host|router>
option host_type router
option prefixlen 56
option ifprefix br-lan

#DNS server list to which the reverse prefix
#will be delegated. Separate servers with :
option dns_server

config gw6c advanced
#Location where to store configuration file
option gw6c_conf /tmp/gw6c.conf
option gw6c_dir /usr/share/gw6c
option auto_retry yes
option retry_delay 30
option keepalive yes
#keepalive interval
option interval 30
#tunnel_mode <v6v4|v6udpv4|v6anyv4|v4v6>
option if_tunnel_mode v6anyv4
option if_v6v4 sit1
option if_v6udpv4 tun
option if_v4v6 sit0
option client_v4 auto
option client_v6 auto
option template openwrt
option proxy_client no

config gw6c broker
option broker_list /etc/config/gw6c-broker-list.txt
option last_server /etc/config/gw6c-last-server.txt
# Always use last known working server? <yes|no>
option always_same_serv no

config gw6c logging
option log_console 0
option log_stderr 1
option log_file 0
option log_syslog 0

option log_filename /var/log/gw6c.log
option log_rotation yes
#Max size when using log file rotation
#possible values: 16|32|128|1024
option log_maxsize 32

#<USER|LOCAL[0-7]>
option syslog_facility USER

❗ 安装程序 gw6c 自动会添加很多所需细节包括radvd : 这就是说, 不需要手动配置radvd: /etc/config/radvd 必须 保持被禁用状态.

用以下命令启动Gateway6客户端: /etc/init.d/gw6c start
如果要让它在路由器启动之后自动运行: /etc/init.d/gw6c enable

❗ 未经过测试-请自行修改配置

NAT64 tunneling

NAT64 是一种为nat用户提供可路由的ipv6同时不影响IPv4网站访问的技术(客户可能不再具有可路由的IPv4地址).
一些ISP在测试它: AAISP (UK)

❗ to be completed – please help ?

使用radvd或者DHCPv6在LAN口广播IPv6子网信息

一旦路由器上的IPv6运行起来, 那就必定会在内部网络中广播IPv6信息. 广播IPv6的方法有N多种,从静态路由到DHCP自动配置,等等多。为此,以后,有以下两种可供您选择:

1.RADVD

这个 router advertisement daemon (radvd) 已经完美支持OpenWRT了。 请参考 radvd UCI 页, 该页面有全套的配置选项。

使用如下命令安装radvd:
opkg update && opkg install radvd

最简单的例子是配置静态的IPv6,配置如下:

/etc/config/radvd:

config interface
option interface ‘lan’
option AdvSendAdvert 1
option AdvManagedFlag 0
option AdvOtherConfigFlag 0
option AdvLinkMTU 1452 # Optional – only provide it is also provided in /etc/config/network
option ignore 0

config prefix
option interface ‘lan’
# If not specified, a non-link-local prefix of the interface is used
option prefix ‘2001:123:456:789::/64’
option AdvOnLink 1
option AdvAutonomous 1
option AdvRouterAddr 0
option ignore 0

上述配置将启用路由器上的radvd ,广播IPv6并自动为局域网中的客户机进行配置IPv6。需要注意以下:

IPv6前缀必须注明
关于MTU,MTU比较特殊, 指定必须是/etc/config/network 相同的一节中设置一个的, 如若提供有的话。 如果你通过一个隧道连接,确保您的MTU匹配的隧道。否则,不要填写。
别忘记将radvd设成开机启用。 你可在LuCI的WEB管理界面中的 Administration管理 → Services服务 → Initscripts初始化脚本中进行此操作。 查找radvd并检查其是否启用。 如果希望不重启就立即启用radvd并设置为自动启动,可以采用如下命令:
/etc/init.d/radvd enable
/etc/init.d/radvd start
可以使用 logread 命令检查启动信息

2.种 DHCPv6

这说明你如何设置的DHCPv6使LAN客户端池,而不是连接随机数,或一些其MAC地址的功能与您的前缀,IPv6地址。

首先,你得安装一个DHCPv6服务器

opkg update opkg install wide-dhcpv6-server

至此处 /etc/config/dhcp6sdhcp6c服务:

config ‘dhcp6s’ ‘basic’
option ‘enabled’ ‘1’
option ‘interface’ ‘lan’
option ‘config_file’ ‘/etc/dhcp6s.conf’

然后创建一个像/etc/dhcp6s.conf 这样的配置文件,大概如下:

interface br-lan {
address-pool pool1 86400;
};

pool pool1 {
range 2001:xxxx:yyyy:zzzz::1000 to 2001:xxxx:yyyy:zzzz:2000 ;
};

这种分配的地址池从4096开始,租用时间为24小时。

最后, 你需要改变一些radvd并将设置,以便它告诉客户使用DHCPv6获取其设置的其余部分:

config interface
option interface ‘lan’
option AdvSendAdvert 1
option AdvManagedFlag 1
option AdvOtherConfigFlag 1
option ignore 0

然后重新启动服务(祝你好运!)

DNS的检查与配置

如果你在路由器上“ping6 ipv6.google.com”可以ping通,说明你的DNSmasq成功地请求了IPv6地址,你的网路已经具有IPv6连接。

恭喜!

如果以上情况的“ping6”没有成功,但你可以ping6 [2a00:1450:8002::93],则是你的DNSmasq(或者是DNSmasq请求的上游服务器)没有成功获取IPv6地址,你需要修复这个问题。

(TBD)

IPv6 only access

❗ (使用中间件来联系IPv4-only服务器)

(TBD)

NAT64

NAT-PT

DSTM

使能路由

不要在你的设备忘记开启 IPv6 路由。

你可以通过修改 /etc/sysctl.conf

vi /etc/sysctl.conf

取消如下注释

# net.ipv6.conf.all.forwarding=1

改为

net.ipv6.conf.all.forwarding=1

重启sysctl

/etc/init.d/sysctl restart

检查路由是否被使能,

cat /proc/sys/net/ipv6/conf/all/forwarding

显示 1则表示已经使能

用ip6tables来保护你的LAN

现在在LAN的每个用户都有一个可路由的IPv6地址,这说明他们可以被外网访问到。你可以在你的每个LAN设备上配置防火墙, 或者是在路由上添加防火墙规则来保护他们,这可能会更方便一些。

如果你是用Hurricane Electronic隧道,他们提供 portscan service 你可以自己使用他们。

配置文件/etc/config/firewall 主要使用于IPv4,但你可以在/etc/firewall.user自定义IPv6 ip6tables规则

主要的ip6tables配置文件是关于FORWARD链,它可以控制LAN客户连接,INPUT和OUTPUT主要是关系到直接传到你的路由器的流量,大多数是无需修改的。INPUT和OUTPUT主要控制ICMPv6流量.(e.g. 可能是来自于你隧道提供者的ping)

主要是要允许通过路由器出站的包,并只允许与这些出站连接相关而传回的包。现在版本的v2防火墙有内置的正确规则,但是老版本的v1防火墙需要如下的规则(Backfire 10.03。1-rc4和更老版本)

ip6tables -A FORWARD -i br-lan -j ACCEPT
ip6tables -A FORWARD -m state <nowiki>–</nowiki>state ESTABLISHED,RELATED -j ACCEPT

# forward ident requests
ip6tables -A FORWARD -p tcp –dport 113 -j ACCEPT
|
Note regarding firewall version:

The current Firewall_v2 in trunk (and also in Backfire since r25353) already has some basic rules, so special ip6tables rules are not needed except for allowing special ports.
Old Firewall v1 in older releases and still in Backfire 10.03.1-rc4 (and upto r25353) had practically no default rules at all and ip6tabels configuration needs to be done from scratch.
Firewall v2

对现在v2版本的双栈防火墙规则,将自己的转发规则放置在forwarding的子链。 ‘forwarding_rule’, 是FORWARD链的一部分:

# Put your custom iptables rules here, they will
# be executed with each firewall (re-)start.

## Allow incoming SixXS IPv6 traffic from tunnel PoP in IPv4 firewall
iptables -A input_wan -s 62.78.96.38 -p 41 -j ACCEPT

# Filter all packets that have RH0 headers: (recommended rule)
ip6tables -I INPUT 2 -m rt –rt-type 0 -j DROP
ip6tables -I FORWARD 2 -m rt –rt-type 0 -j DROP
ip6tables -I OUTPUT 2 -m rt –rt-type 0 -j DROP

## Example: allow packects to port 113 to get forwarded
ip6tables -A forwarding_rule -p tcp –dport 113 -j ACCEPT
ip6tables -A forwarding_rule -p udp –dport 113 -j ACCEPT
Firewall v1

以下例子是针对于没有配置过的空ip6tables。这些规则清楚地展示了v1防火墙最基本的原理,使用于v1防火墙。 (e.g. 在较老版本和仍在Backfire r25353之前的版本)。

例子 /etc/firewall.user 立足于没有配置过的空ip6tables。可以参考该例 this slideshow 了解为何要禁止RH 0封包

# start with a clean slate
ip6tables -F
ip6tables -X

# allow icmpv6
ip6tables -I INPUT -p ipv6-icmp -j ACCEPT
ip6tables -I OUTPUT -p ipv6-icmp -j ACCEPT
ip6tables -I FORWARD -p ipv6-icmp -j ACCEPT

# allow loopback
ip6tables -A INPUT -i lo -j ACCEPT
ip6tables -A OUTPUT -o lo -j ACCEPT

# allow anything out of the tunnel
ip6tables -A OUTPUT -o 6in4-henet -j ACCEPT

# allow LAN
ip6tables -A INPUT -i br-lan -j ACCEPT
ip6tables -A OUTPUT -o br-lan -j ACCEPT

# drop packets with a type 0 routing header
ip6tables -A INPUT -m rt –rt-type 0 -j DROP
ip6tables -A OUTPUT -m rt –rt-type 0 -j DROP
ip6tables -A FORWARD -m rt –rt-type 0 -j DROP

# allow link-local
ip6tables -A INPUT -s fe80::/10 -j ACCEPT
ip6tables -A INPUT -s fe80::/10 -j ACCEPT

# allow multicast
ip6tables -A INPUT -s ff00::/8 -j ACCEPT
ip6tables -A OUTPUT -s ff00::/8 -j ACCEPT

# allow forwarding
ip6tables -A FORWARD -i br-lan -j ACCEPT
ip6tables -A FORWARD -m state –state ESTABLISHED,RELATED -j ACCEPT

# forward ident requests
ip6tables -A FORWARD -p tcp –dport 113 -j ACCEPT

# default policy…
ip6tables -P INPUT DROP
ip6tables -P FORWARD DROP
ip6tables -P OUTPUT DROP
注意:尽管你将隧道接口命名为’henet’,它会自动添加一个前缀’6in4-‘,因此对于ip6tables规则来说,该接口是’6in4-henet’.

来源: 根据SixXS论坛相关内容改写 Hannu Nyman’s post .

LuCI 要点

LuCI 要点

在uHTTPd上安装LuCI

这是安装Web用户界面LuCI的要点。运行”opkg update && opkg list luci-*“命令查找所有可用的能通过LuCI管理OpenWrt的软件包。

如果你不熟悉 命令行界面, 可查询 命令行帮助 和/或 opkg

安装

  1. 在软件库中检索可用软件包的最新列表:
opkg update
  • 完整安装一个不需要HTTPS支持的LuCI:
opkg install luci
  • 完整安装一个需要HTTPS支持的LuCI:
opkg install luci-ssl

OPKG 安装 luci

本地语言支持

基本的LuCI Web用户界面是英文的。但是,志愿者们正积极的把它翻译成许多语言。参见http://i18n.luci.subsignal.org/pootle/ 可以参与!有关可用包的列表,运行

opkg list | grep luci-i18n-

您会看到一个可用语言包的列表。要安装你的母语,例如运行

opkg install luci-i18n-chinese

您还可以通过网页界面安装语言包,你可以同时安装多个LuCI语言包,要在它们之间切换可通过网页界面或编辑这个文件 → /etc/config/luci

开始使用Web服务器(uHTTPd)

Web服务器uHTTPd是LuCI安装包的一个依赖软件,它会在你安装LuCI时自动安装。 安装后,Web服务器是未运行的!你需要手动开启它。你还应该使能Web服务器,以使它在你重启路由器时自动启动。 下面的第一个命令启动Web服务器,第二个使它在重启时启动。

/etc/init.d/uhttpd start
/etc/init.d/uhttpd enable

现在,你应该能够连接到Web服务器 http://192.168.1.1 享受LuCI提供的服务了。

详细资料

LuCI做为“元包”安装,它同时安装了其他几个被定义为依赖关系的包。 尤其是,它安装了uHTTPd Web服务器,配置为供LuCI使用。 安装的依赖包如下(更多信息参见LuCI技术参考):

  • uhttpd
  • uhttpd-mod-ubus
  • luci-mod-admin-full
  • luci-theme-bootstrap
  • luci-app-firewall
  • luci-proto-core
  • luci-proto-ppp
  • libiwinfo-lua

要使用uHTTPd做Web界面,你仅需要很少的配置就行,因为uHTTPd配置了CGI以使LuCI可以使用Lua解释器来工作。 默认配置如下。默认情况下/www是标准的文档根目录。 因此,通过请求该文档根目录(在浏览器中输入设备IP地址)可以找到一个如index.html的索引文件(uHTTPd设置)。 配备的/www/index.html(与LuCI一起安装)文件会在收到请求时把你重定向到/cgi-bin/luci目录, 这是LuCI的默认CGI通道。这仅是一个脚本,它主要是在/usr/bin/lua中调用Lua。 uHTTPd默认配置为用CGI加载/cgi-bin路径下的页面,从而通过/cgi-bin/luci 脚本为这些网页开启服务。

另外,也可以把Lua作为嵌入式进程来运行LuCI。uHTTPd支持这一点; 可以参考uHTTPd Web服务器配置上uHTTPd的UCI配置的相关文章和章节 。

配置

默认Web服务器uhttpd的配置文件为/etc/config/uhttpd
该LuCI的Web界面配置文件为/etc/config/luci

LuCI运行在其他WEB服务器上

LuCI 运行在 lighttpd 上

LuCI 运行在 nginx 上

LuCI 运行在 …

简易离线安装

下载并传输(如用SCP)以下列表中的软件包到你的OpenWrt路由器上,放到RAM盘/tmp/luci-offline-packages

mkdir -p /tmp/luci-offline-packages; cd /tmp/luci-offline-packages
  • liblua
  • lua
  • libuci-lua
  • libubus-lua
  • uhttpd
  • luci-lib-ipkg
  • luci-i18n-english
  • luci-sgi-cgi
  • luci-lib-core
  • luci-lib-nixio
  • luci-lib-sys
  • luci-lib-web
  • luci-proto-core
  • luci-theme-base
  • luci-theme-openwrt
  • luci-mod-admin-core
  • luci-mod-admin-full

并用下面命令安装:

for pkg in liblua lua libuci-lua libubus-lua uhttpd luci-lib-ipkg luci-i18n-english luci-sgi-cgi luci-lib-core luci-lib-nixio luci-lib-sys luci-lib-web luci-proto-core luci-theme-base luci-theme-openwrt luci-mod-admin-core luci-mod-admin-full; do opkg install /tmp/luci-offline-packages/$pkg*.ipk; done

此外,基本的无线配置还需要以下包:libiw, libiwinfo, libiwinfo-lua。

杂项

安全访问luci网络服务器

如果你想配置Luci网页服务器安全访问, 参考这里的说明.

故障排除

注意事项

OpenWRT路由器unbound+dnsmasq解决DNS污染与劫持

出处:http://blog.csdn.net/conupefox/article/details/8557253

 

鉴于境外技术网站经常有河蟹出没,所以有必要折腾一下。

 

关于DNS劫持和DNS污染的概念和区别,就不多说了。网上都有很多解释。解决方案无非就几种。

 

1.使用非53的udp端口。这个方法显然不具备实操意义,好少有开放非53UDP端口的dns服务器。

2.使用TCP 53端口查询,其中google的8.8.8.8就支持

3.使用加密的DNS协议,opendns貌似提供了解决方案。

 

查了一下openwrt有提供unbound这个软件包,可以非常方便地部署到路由器上。

unbound支持使用TCP协议进行DNS查询,所以只需要把DNS请求用TCP协议转发出去境外的DNS,就可以解决污染问题了。

虽然DNS的协议规定TCP协议也是其可以使用的协议,一般软件发出都是UDP 53端口来,所以需要做一个UDP转TCP的DNS转发器。

利用Openwrt里面自带了dnsmasq就能实现了。以下是实现方法。

 

先下载unbound。

[plain] view plaincopy

  1. opkg update
  2. opkg install unbound

需要注意的是,如果使用Dreambox,他提供的unbound版本过低,不能提供TCP转发功能。我已提交了patch给Dreambox项目了,不过貌似项目管理者太繁忙没有处理这个任务单….

https://dev.openwrt.org.cn/ticket/84#

如果在Dreambox强行安装trunk或者Attitude Adjustment提供的unbound,会有lib依赖的问题,无法正常使用。

所以要么就不要用Dreambox,要么就按照我那个任务单里面说的方法把新版的unbound移植过来并编译Dreambox,十分折腾,呵呵。

 

由于dsmasq使用了udp53端口,所以unbound要换成另一个端口,我这里改成5353,然后打开tcp-upstream选项,意思是使用TCP协议转发请求至上游DNS。

安装完成之后,编辑unbound的配置文件/etc/unbound/unbound.conf,加入或找到相应的行去掉注释。

[plain] view plaincopy

  1. port: 5353
  2. tcp-upstream: yes
  3. forward-zone:
  4.         name: “.”
  5.         forward-addr: 8.8.8.8
  6.         forward-first: no

 

把unbound设置成开机启动,然后启动unbound

[plain] view plaincopy

  1. /etc/init.d/unbound enable
  2. /etc/init.d/unbound start

接下来配置dnsmasq,编辑dnsmasq的配置文件/etc/dnsmasq.conf,把指定的域名转发到unbound,用unbound进行解析。一行一个域名例如,

  1. server=/xxx.com/127.0.0.1#5353

 

把被污染掉的域名加进去就可以了,重启dnsmasq生效。

此外还要配置dnsmasq的默认转发DNS地址,普通的dns请求继续用udp协议转发到运营商的DNS就可以,这样才能保证国内CDN网站正常使用,如下图。

 

google上面有几个项目都可以获取到最新的污染域名列表,在这就不详细说了,哈哈。自己写了个脚本取下来,并通过计划任务定时更新,基本上都可以解决污染问题了。

以下放出脚本,具体不解释,该懂的都懂,需要使用完整版的wget。小tips:使用IPV6连接google code获取列表会方便很多。

make_dnsmasq_conf.sh

[plain] view plaincopy

  1. #!/bin/ash
  2. #Anti DNS Pulltion
  3. #make dnsmasq.conf
  4. #Script By D2O
  5. #
  6. #v0.1 2012/8/13
  7. #v0.2 2012/11/17
  8. local DNS_DIR=/tmp/dns
  9. local DNSMASQ_CONF=$DNS_DIR/dnsmasq.conf
  10. wget –no-check-certificate -O $DNS_DIR/gfwlist.txt https://autoproxy-gfwlist.googlecode.com/svn/trunk/gfwlist.txt
  11. wget -O $DNS_DIR/smarthosts http://smarthosts.googlecode.com/svn/trunk/hosts
  12. echo please wait…
  13. echo ##Anti DNS Pulltion >$DNSMASQ_CONF
  14. $DNS_DIR/getlist.py $DNS_DIR/gfwlist.txt >>$DNSMASQ_CONF
  15. #rm gfwlist.txt
  16. #cp $DNSMASQ_CONF /etc/
  17. /etc/init.d/dnsmasq reload

getlist.py,修改自网上大牛的脚本。

 

[python] view plaincopy

  1. #!/usr/bin/env python
  2. #   Aug 19 2011
  3. #   Copyleft@2011 Published Under BSD Lisense
  4. #           Ronald Liu
  5. #   [email protected]
  6. #   FYI  http://lzsblog.appspot.com/%3Fp%3D291001
  7. #   
  8. #   Mod By D2o 2012/8/13
  9. #   http://conupefox.csdn.net
  10. import sys,re,base64
  11. def splitList(txt):
  12.     arr = txt.split(“n”)
  13.     pattern =‘^([01]?dd?|2[0-4]d|25[0-5]).([01]?dd?|2[0-4]d|25[0-5]).([01]?dd?|2[0-4]d|25[0-5]).([01]?dd?|2[0-4]d|25[0-5])$’
  14.     l = []
  15.     for line in arr:
  16.         if (not len(line)): #empty line
  17.             continue
  18.         if (line[0] == “!”): #Comment line
  19.             continue
  20.         elif(line[0:2] ==“@@”):#Forbidding line
  21.             continue
  22.         elif(line.find(“/”)!=-1 or line.find(“*”)!=-1 or line.find(“[“)!=-1 or line.find(“%”)!=-1 or line.find(“.”)==-1 ): #URL is ignored, only domains left
  23.             continue
  24.         elif(re.search(pattern, line)):#IP address
  25.             continue
  26.         #In this case, domain name is irrelevant to protocol(http or https)
  27.         elif(line[0:2] ==“||”):
  28.             l.append(line[2:])
  29.         elif(line[0] == “.”):
  30.             l.append(line[1:])
  31.         else:
  32.             l.append(line)
  33.     return l
  34. #Decode and decorate the input string
  35. f = open(sys.argv[1],“r”)
  36. txt = f.read()
  37. txt = base64.decodestring(txt)
  38. domains = splitList(txt)
  39. per_line=””
  40. forwarddns=“127.0.0.1#5353”
  41. for line in domains:
  42.     if (line!=per_line):
  43.         print “server=/” + line + “/” + forwarddns
  44.     per_line=line

 

 

Enjoy!!

原文首发CSDN博客,转载请保留作者和出处,谢谢