首页  编辑  

路由器折腾记:LEDE/Openwrt 17.0 LEDE Reboot 17.01.4 r3560-79f57e422d / LuCI lede-17.01 branch (git-17.290.79498-d3f0685)

Tags: /计算机文档/路由器和网络管理/   Date Created:
联想Lenovo Newwifi Y1,LEDE/Openwrt

不要慌,Don't Panic

联想Y1路由器支持U-boot模式,可以在固件出问题的时候,恢复固件。具体方法:
关机,按住Reset,上电,USB灯和2.5GLED灯会蓝色闪烁,此时进入恢复模式,用电脑连接路由器的LAN口,设置电脑IP为192.168.1.11,掩码255.255.255.0,网关192.168.1.1,然后用浏览器打开 http://192.168.1.1,你会看到要你选择一个固件,此时可以用下面的方法备份的固件或者用别人给你做好的固件刷进去就可以了!

由于这个路由器默认存储空间很小,如果出现空间不足,用下面的指令,找出大文件:
find / -size +500k

记得这里:http://downloads.openwrt.org/releases/17.01.4/packages/mipsel_24kc/
上面这里有所有官方的包的安装程序,可以手动下载和安装!

1. 升级附件的固件 lede-17.01.4-ramips-mt7620-y1-squashfs-sysupgrade.bin
2. 用 winscp,建立一个scp连接,把zip附件中的6个文件上传到路由器和 luci-app-shadowsocks-libev_all.ipk 上传到路由器,用户名是 root,密码为空
3. 用 putty 登录路由器,运行下面的指令:
opkg update     # 更新软件包列表,必须运行该指令,否则会报找不到包错误
opkg install kmod-nf-nathelper-extra    # 这里的命令保证通过路由器上网的电脑,可以进行VPN(PPTP/LT2P)拨号
opkg install kmod-gre kmod-ipt-conntrack-extra kmod-ipt-nat-extra iptables-mod-conntrack-extra   # 本条指令可以选配,如果需要GRE隧道支持,即允许内部的电脑与外部的服务器进行GRE隧道连接,可以运行
opkg install luci-i18n-base-zh-cn  luci-i18n-firewall-zh-cn luci-i18n-diag-core-zh-cn       # 安装中文语言包,防火墙中文语言包
opkg install adblock luci-i18n-adblock-zh-cn   # 安装adblock & 和中文语言包
opkg install shadowsocksr-libev_v20170613-1pre_mipsel_24kc.ipk  # 安装自由世界套件,下面指令必须按顺序运行,否则掉坑
opkg install dns-forwarder_1.2.0-1_mipsel_24kc.ipk 
opkg remove dnsmasq
opkg install shadowsocksr-libev-gfwlist_v20170613-1pre_mipsel_24kc.ipk  --force-overwrite   # 安装自动规则文件
opkg install luci-app-shadowsocks-libev    # 安装配置界面,此处是在线安装影梭配置界面
opkg install luci-app-shadowsocks-libev_all.ipk     # 这里是配置界面的本地安装界面
opkg install luci-app-ddns luci-i18n-ddns-zh-cn   # 安装动态DDNS配置界面和中文语言包
opkg install luci-ssl-openssl libustream-openssl ca-certificates ca-bundle curl # DDYNS要用这个库,如果你需要https获取外部IP的话
opkg install luci-app-wifischedule luci-i18n-wifischedule-zh-cn # 定时开关WIFI 应用
opkg install luci-app-upnp luci-i18n-upnp-zh-cn  # 安装UPNP即插即用支持,一些BT下载软件需要
opkg install luci-app-samba  luci-i18n-samba-zh-cn # 安装Windows共享协议,可以共享打印机,也可以让路由器直接在网上邻居中可以访问
opkg install kmod-usb-ohci kmod-usb2 kmod-usb-storage block-mount kmod-fs-ext4 kmod-fs-vfat ntfs-3g kmod-fs-ntfs  # 安装USB支持,以便插入U盘外部存储和设备
opkg install block-mount e2fsprogs kmod-usb3  # USB 3.0支持
opkg install luci-i18n-qos-zh-cn luci-app-qos  # 安装限速服务
vi /etc/fstab
添加类似下面的行:
# /dev/sda1 /mnt vfat defaults 0 0
/dev/sda1 /mnt vfat rw,umask=000 0 0  # 这句可以让共享的时候具有完全的读写权限,否则默认nobody共享的时候是只读的!
自动挂载mount FAT32的U盘!
chomd 777 /mnt  # 开所有权限
记得,必须用rw那个模式,才可以通过 https://192.168.1.1/cgi-bin/luci/admin/services/samba 中的【只读】来控制是否只读共享,否则nobody用户永远是只读共享!
运行下面指令检测当前磁盘信息:
block detect
然后可以把 block detect 显示的信息写入 /etc/config/fstab,其中 option enable '1' 就可以让路由器启动的时候自动挂载U盘了。

4. 打开浏览器,输入 http://192.168.1.1,以root登录,默认没有密码
切换到 system/system, languages and styles,切换语言languages为中文。
点击菜单,服务,ShadowsockR,基本设置中,配置好服务器信息,然后提交。
点击菜单,服务,Adblock,点击“启用Adblock”,在下面找到并勾选reg_cn,拦截国内的广告

如果动态DDNS不能使用,是因为无聊的防火墙封锁了DDNS的请求,但是大部分国外DDNS都支持HTTPS了,可以修改 vi /etc/ddns/services,把对应服务的URL,改成https开头,例如
"dynu.com"              "http://api.dynu.com/nic/update?hostname=[DOMAIN]&myip=[IP]&username=[USERNAME]&password=[PASSWORD]"
改成:
"dynu.com"              "https://api.dynu.com/nic/update?hostname=[DOMAIN]&myip=[IP]&username=[USERNAME]&password=[PASSWORD]"
修改
/usr/lib/ddns/dynamic_dns_updater.sh,把其中的 http://checkip.dyndns.com 改成 https://myexternalip.com/raw
同样,修改 /usr/lib/lua/luci/model/cbi/ddns/detail.lua,中对应的 http://checkip.dyndns.com 改成 https://myexternalip.com。
就可以让防火墙嗝屁了。

// 为了让你远程可以管理路由器(无论是否有公网IP!),可以用ssh隧道建立一个到公网服务器的隧道(端口反弹),先安装openssh-client和autossh
opkg install autossh openssh-client
然后 运行 ssh-keygen 生成密钥,之后手动运行ssh 用户名@你的远程公网SSH Linux主机地址:端口 一次,记住远程主机key
然后修改 /etc/config/autossh配置
config autossh
        option enable '1'
        option ssh      '-i /root/.ssh/id_rsa -N -T -R 2222:localhost:22 用户名@你的远程公网SSH Linux主机地址:端口'
        option gatetime '0'
        option monitorport      '0'
        option poll     '600'
config autossh
        option enable '1'
        option ssh      '-i /root/.ssh/id_rsa -N -T -R 2223:localhost:443 用户名@你的远程公网SSH Linux主机地址:端口'
        option gatetime '0'
        option monitorport      '1'
        option poll     '600'
再次,修改/etc/init.d/autossh脚本,这个脚本有个bug,不支持多个配置,我们有多个配置,增加下面一行:
local SERVICE_PID_FILE="SERVICE_PID_FILE_BASE.$section"
完整 /etc/init.d/autossh 如下:
#!/bin/sh /etc/rc.common
# Copyright (C) 2007-2011 OpenWrt.org

START=80

start_instance() {
        local section="$1"

        config_get ssh "$section" 'ssh'
        config_get gatetime "$section" 'gatetime'
        config_get monitorport "$section" 'monitorport'
        config_get poll "$section" 'poll'

        export AUTOSSH_GATETIME="${gatetime:-30}"
        export AUTOSSH_POLL="${poll:-600}"
        local SERVICE_PID_FILE="/var/run/autossh.$section.pid"
        service_start /usr/sbin/autossh -M ${monitorport} -f ${ssh}
}

boot() {
        return
}

start() {
        config_load 'autossh'
        config_foreach start_instance 'autossh'
}

stop() {
        service_stop /usr/sbin/autossh
}
让路由器变成BT等下载工具,首先按前面的方法,把U盘、移动硬盘挂载到/mnt目录!
# 安装BT下载工具,可以让路由器下载到移动硬盘中去!
opkg install transmission-web luci-i18n-transmission-zh-cn  luci-app-transmission transmission-daemon-openssl
# 安装流媒体服务器,让移动硬盘可以给电视机,电脑等共享播放!
opkg install minidlna
opkg install luci-app-minidlna
为了让软件可以安装在usb设备,可以这样:
在usb设备建立目录,用于安装:
mkdir /mnt/sda1/packages/
首先挂载硬盘,然后修改opkg配置:
echo dest usb /mnt/sda1/packages/ >> /etc/opkg.conf
安装软件的时候,就可以指定安装目录啦:
opkg --dest usb install python
如果你要备份路由器当前的整个系统和固件,可以用下面的方法:
首先用下面的指令,查看固件分区:
cat /proc/mtd

mtd0: 00030000 00001000 "u-boot"
mtd1: 00010000 00001000 "u-boot-env"
mtd2: 00010000 00001000 "factory"
mtd3: 00fb0000 00001000 "firmware"
mtd4: 001286fd 00001000 "kernel"
mtd5: 00e87903 00001000 "rootfs"
mtd6: 00c58000 00001000 "rootfs_data"
其中 mtd3 就是固件分区了。然后用下面的指令备份:
cat /dev/mtd3 > /mnt/firmware.bin 
其中 /mnt/ 是你挂载的U盘,完成后,在U盘下就有个firmware.bin,这个文件可以用来从网页上进行刷机(该文件是一个sysupgrade固件 ,必须已经存在之前的openwrt,existing OpenWrt installation is required, this is not a "factory" file). This clones the kernel, rootfs and overlay fs, thus all settings and installed packages are preserved)。

下面是安装AirPrint,把打印机接在网络上,就可以实现手机、电脑无线打印的方法。例如如果打印机直接可以接网线,或者把打印机接在台式机上,然后台式机共享这台打印机,也可以直接接在路由器上(如果打印机是USB接口的话)。
1、安装USB支持软件包
opkg update
opkg install kmod-usb-core
opkg install kmod-usb-storage
opkg install kmod-usb-printer #USB口打印机支持
opkg install luci-app-samba # 安装Windows共享,可以让windows电脑在添加打印机时自动发现打印机
2、安装CUPS 软件包
opkg insatll cups
opkg install libcupsdriver         ##注意libcupsdriver不会默认安装,需要手工安装,否则认不到打印机
3、编辑/etc/cups/cupsd.conf
修改/etc/cups/cupsd.conf中<Location /></Location>一段,如下:
<Location />
    AuthClass Anonymous
    AuthType None
    Order Deny,Allow
    Deny From All
    Allow From 192.168.10.0/24 #允许192.168.10.xxx访问
</Location>
4、插上打印机,并给USB设备添加权限
chmod -R 777 /dev/bus/usb/001/
5、启动服务
登陆到http://192.168.10.1到管理台去启动服务,【系统】-【启动项】,把cupsd那一项设置“启用”,并且点击“开始”

6、在网页管理客户端添加打印机
打开路由器http://192.168.10.1:631这个页面,点击“Administration”,这里提示要输入账号和密码,就是路由器的登陆帐号和密码。
然后点击“Find New Printers”,正常情况下就能看到自己连接着的打印机了,
然后选“Add This Printer”,
勾选“Share This Printer”前面的勾,再点击“Continue”进入下一步,
看到“Make”项里面有个“Raw”,选中后先点“Continue”,最后再点“Add Printer”进入下一步,
接着保持默认点击“Set Default Options”,打印机就添加完成了。

7、查看共享的打印机地址
此时在http://192.168.10.1:631的“Printers”页面可以看到自己添加的打印机了,点击自己的打印机,可以在地址栏看到当前打印机的网络地址比如http://192.168.10.1:631/printers/EPSON_LQ-630K,复制这个地址。

8、在电脑上添加打印机
在控制面板的打印机里面,添加打印机,选择“添加网络打印机”,点“我需要的打印机不在列表中”,再选“按名称选择共享打印机”,输入刚才复制的地址http://192.168.10.1:631/printers/EPSON_LQ-630K,下一步就是添加自己打印机的驱动,这里不多说明了。

9、有可能打印机每天需要关机,而不影响正常运行,请编辑脚本放到/etc/cups下面,命名为crontab.sh 
#!/bin/sh
while true
do
        chmod -R 777 /dev/bus/usb/001/
        sleep 3
done
exit 0
将sh /etc/cups/crontab.sh 加放到启动项里面,登陆到openwrt管理界面的系统启动项里,将sh /etc/cups/crontab.sh插入到exit 0 之前即可。
lede-17.01.1-ramips-mt7620-shadowsocksr-libev.zip (844.2KB)
lede-17.01.4-ramips-mt7620-y1-squashfs-sysupgrade.bin (3.5MB)
luci-app-shadowsocks-libev_all.ipk (2.3KB)