编译OpenWrt全自动翻墙固件 for D-Link DIR-505 A1
除了增加模式转换开头,其他和编译 TP-LINK WR2543N翻墙固件一样。
下载适合D-Link DIR505无线路由器的Image Builder
Image Builder又叫Image Generator,利用它我们可以方便地定制适合自己无线路由器的固件。
选择 OpenWrt版本:
* 进入 http://downloads.openwrt.org/
* Development Snapshots 最新开发版,我们的选择
* Binary Releases, 最后发行的稳定版本
* 进入 http://downloads.openwrt.org/snapshots/trunk/
选择 CPU 类型:
* 选择 ar71xx: http://downloads.openwrt.org/snapshots/trunk/ar71xx/
选择 Flash 类型:
* 选择 generic: http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/
下载 Image Builder for DID-505 (Version: 23-Dec-2015 16:38)
* 页面搜索 dir-505 如果找到,说明我们找对了目录
* 下载 Image Builder:
cd ~/Downloads
wget http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/OpenWrt-ImageBuilder-ar71xx-generic.Linux-x86_64.tar.bz2
tar -xjf OpenWrt-ImageBuilder-ar71xx-generic.Linux-x86_64.tar.bz2
确定OpenWrt无线路由器的PROFILE值
cd OpenWrt-ImageBuilder-ar71xx-generic.Linux-x86_64
make info
找到自己固件的型号,D-Link DIR 505 A1的PROFILE值是DIR505A1。如下图:
找出默认应该包含进OpenWrt固件的包
对于D-Link DIR-505 A1 无线路由器来说,可以这样获取:
echo $(wget -qO - http://downloads.openwrt.org/snapshots/trunk/ar71xx/generic/config | sed -ne 's/^CONFIG_PACKAGE_\([a-z0-9-]*\)=y/\1/ip')
2015-12-24的基础包:
base-files busybox dnsmasq dropbear firewall fstools jsonfilter libc libgcc mtd netifd opkg procd swconfig ubox ubus ubusd uci usign kmod-ledtrig-usbdev kmod-lib-crc-ccitt kmod-nls-base kmod-ip6tables kmod-ipt-conntrack kmod-ipt-core kmod-ipt-nat kmod-nf-conntrack kmod-nf-conntrack6 kmod-nf-ipt kmod-nf-ipt6 kmod-nf-nat kmod-ipv6 kmod-ppp kmod-pppoe kmod-pppox kmod-slhc kmod-gpio-button-hotplug kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-ath kmod-ath9k kmod-ath9k-common kmod-cfg80211 kmod-mac80211 libip4tc libip6tc libxtables libblobmsg-json libexpat libiwinfo libjson-c libnl-tiny libubox libubus libuci ip6tables iptables hostapd-common iw odhcp6c odhcpd ppp ppp-mod-pppoe wpad-mini iwinfo jshn libjson-script uboot-envtools
2014-09-01查询得到的基础包是:
base-files busybox dnsmasq dropbear firewall fstools jsonfilter libc libgcc mtd netifd opkg procd swconfig ubox ubus ubusd uci kmod-crypto-aes kmod-crypto-arc4 kmod-crypto-core kmod-ledtrig-usbdev kmod-lib-crc-ccitt kmod-nls-base kmod-ip6tables kmod-ipt-conntrack kmod-ipt-core kmod-ipt-nat kmod-ipt-nathelper kmod-ipv6 kmod-ppp kmod-pppoe kmod-pppox kmod-slhc kmod-gpio-button-hotplug kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-ath kmod-ath9k kmod-ath9k-common kmod-cfg80211 kmod-mac80211 libip4tc libip6tc libxtables libblobmsg-json libiwinfo libjson-c libnl-tiny libubox libubus libuci ip6tables iptables hostapd-common iw odhcp6c odhcpd ppp ppp-mod-pppoe wpad-mini iwinfo jshn libjson-script uboot-envtools
默认包要包含在PACKAGES命令行参数中,并再加上必要的包:
luci-ssl ipset wget shadowsocks-libev iptables-mod-nat-extra bind-dig
注意,在编译前要把 shadowsocks-libev 及其他要用到的 .ipk 文件放到目录下:
~/Downloads/OpenWrt-ImageBuilder-ar71xx-generic.Linux-x86_64/packages/base/
如果你的openWrt版本是 ATTITUDE ADJUSTMENT,可能加上iptables-mod-nat-extra包,如果没安装的话iptables的端口转发会不支持。
按照教程 编译shadowsocks-libev for OpenWrt ipk安装包
下载和设定自定义翻墙配置文件
下面以linux系统 ~/Downloads 下操作为例。
cd ~/Downloads
git clone https://github.com/softwaredownload/openwrt-fanqiang
本地项目文件夹是: ~/Downloads/openwrt-fanqiang
建立一个配置文件夹,以路由器型号结束,如 ~/Downloads/openwrt-dir505。
cd ~/Downloads
mkdir openwrt-dir505
cd openwrt-fanqiang
cp -R openwrt/default/* ~/Downloads/openwrt-dir505/
cp -R openwrt/dir505/* ~/Downloads/openwrt-dir505/
上面的操作,先复制共用的配置文件 openwrt/default/ 到 openwrt-dir505目录下
然后复制dir505专用的配置文件到 openwrt/dir505/ 到 openwrt-dir505目录下,如果有同名文件就覆盖。
设置可执行权限
cd ~/Downloads/openwrt-dir505
chmod +x usr/bin
chmod +x usr/bin/*
chmod +x etc/uci-defaults
chmod +x etc/uci-defaults/defaults
说明:etc/uci-defaults目录下的文件会在路由器第一次启动时执行一次。在这里我们设置一些常用值。
必须修改的DIR505翻墙配置文件:
- ~/Downloads/openwrt-dir505/etc/shadowsocks.json
- server改成你的服务器实际IP
- ~/Downloads/openwrt-dir505/usr/bin/router
- wan-username 和 wan-password改成实际值
- ~/Downloads/openwrt-dir505/usr/bin/shadowsocks-firewall
- 1.0.9.8必须改成你的服务器实际IP
自动复制和修改DIR-505翻墙设置文件
config-dir505.sh:
#!/bin/bash
# Author: https://github.com/softwaredownload/openwrt-fanqiang
# Date: 2015-12-24
REPOSITORY=~/Downloads/openwrt-fanqiang
CONFIG=~/Downloads/openwrt-dir505
createdir() {
rm -rf $CONFIG
mkdir $CONFIG
}
copy() {
cp -R $REPOSITORY/openwrt/default/* $CONFIG/
cp -R $REPOSITORY/openwrt/dir505/* $CONFIG/
}
setmod() {
chmod +x $CONFIG/usr/bin/shadowsocks-firewall
chmod +x $CONFIG/etc/uci-defaults
chmod +x $CONFIG/etc/uci-defaults/*
}
modify() {
# server ip address
sed -i 's/1.0.9.8/server_ip/' $CONFIG/etc/shadowsocks.json
# server_port
sed -i 's/1098/server_port/' $CONFIG/etc/shadowsocks.json
# local_port
sed -i 's/7654/7654/' $CONFIG/etc/shadowsocks.json
# password
sed -i 's/killgfw/killgfw/' $CONFIG/etc/shadowsocks.json
# method
sed -i 's/aes-256-cfb/aes-256-cfb/' $CONFIG/etc/shadowsocks.json
# server ip addresss
sed -i 's/1.0.9.8/server_ip/' $CONFIG/usr/bin/shadowsocks-firewall
# local_port
sed -i 's/7654/7654/' $CONFIG/usr/bin/shadowsocks-firewall
# ppoe username
sed -i 's/wan-username/wan-username/' $CONFIG/usr/bin/router
# ppoe password
sed -i 's/wan-password/wan-password/' $CONFIG/usr/bin/router
# wifi password
sed -i 's/icanfly9876/icanfly9876/g' $CONFIG/usr/bin/ap
sed -i 's/icanfly9876/icanfly9876/g' $CONFIG/usr/bin/router
# root password
sed -i 's/\\nfanqiang/\\nfanqiang/' $CONFIG/etc/uci-defaults/defaults
}
if [ "$1" = "createdir" ]; then
createdir
elif [ "$1" = "copy" ]; then
copy
elif [ "$1" = "setmod" ]; then
setmod
elif [ "$1" = "modify" ]; then
modify
else
echo "usage: createdir copy setmod modify"
fi
用法:在 config-dir505.sh所在目录运行:
./config-dir505.sh createdir
./config-dir505.sh copy
./config-dir505.sh setmod
./config-dir505.sh modify
开始编译OpenWrt自动翻墙固件
cd ~/Downloads/OpenWrt-ImageBuilder-ar71xx-generic.Linux-x86_64
make image PROFILE=DIR505A1 PACKAGES="base-files busybox dnsmasq dropbear firewall fstools jsonfilter libc libgcc mtd netifd opkg procd swconfig ubox ubus ubusd uci usign kmod-ledtrig-usbdev kmod-lib-crc-ccitt kmod-nls-base kmod-ip6tables kmod-ipt-conntrack kmod-ipt-core kmod-ipt-nat kmod-nf-conntrack kmod-nf-conntrack6 kmod-nf-ipt kmod-nf-ipt6 kmod-nf-nat kmod-ipv6 kmod-ppp kmod-pppoe kmod-pppox kmod-slhc kmod-gpio-button-hotplug kmod-usb-core kmod-usb-ohci kmod-usb2 kmod-ath kmod-ath9k kmod-ath9k-common kmod-cfg80211 kmod-mac80211 libip4tc libip6tc libxtables libblobmsg-json libexpat libiwinfo libjson-c libnl-tiny libubox libubus libuci ip6tables iptables hostapd-common iw odhcp6c odhcpd ppp ppp-mod-pppoe wpad-mini iwinfo jshn libjson-script uboot-envtools luci-ssl ipset wget shadowsocks-libev iptables-mod-nat-extra bind-dig" FILES=~/Downloads/openwrt-dir505
报告错误:
opkg_install_cmd: Cannot install package kmod-ipv6
移除kmod-ipv6再次编译,成功。
查看编译好的固件:
cd ~/Downloads/OpenWrt-ImageBuilder-ar71xx-generic.Linux-x86_64/bin/ar71xx/
ls -lh *505*.bin
... 7.6M Dec 24 15:20 openwrt-ar71xx-generic-dir-505-a1-squashfs-factory.bin
... 5.4M Dec 24 15:20 openwrt-ar71xx-generic-dir-505-a1-squashfs-sysupgrade.bin
升级固件要用到的是 openwrt-ar71xx-generic-dir-505-a1-squashfs-sysupgrade.bin,如果在原厂固件上刷要用openwrt-ar71xx-generic-dir-505-a1-squashfs-factory.bin
先本地修改好配置文件再编译,然后把翻墙固件刷进D-Link DIR-505 A1后,就能零设置智能、自动翻墙。
只要配置文件设置不出差错,编译固件一般都能成功,保存好这个固件,以后随便折腾路由器,出现问题大不了重刷一次,几分钟时间就一切都恢复正常。