小米路由器 BE6500 解锁 SSH 以及用作 VLAN 交换机 + AP
· 阅读需 4 分钟
小米路由器 BE6500 解锁 SSH 以及用作 VLAN 交换机 + AP
参考 【BE6500】SSH,固化过程记录,及单线复用方法,路由器拨号并利用光猫lan口
简洁方便的 SN -> root password 计算器 在此
相比这个教程,我修改了 auto_ssh.sh 脚本。因为有线中继模式下不知道为什么似乎不会执行 firewall 里面设置的脚本,所以我用了 crontab 的方法。
#!/bin/sh
logger -t auto_ssh "Script invoked: args=$*"
auto_ssh_dir="/data/auto_ssh"
host_key="/etc/dropbear/dropbear_rsa_host_key"
host_key_bk="${auto_ssh_dir}/dropbear_rsa_host_key"
unlock() {
logger -t auto_ssh "Start unlocking SSH access..."
# Restore the host key.
[ -f $host_key_bk ] && ln -sf $host_key_bk $host_key
# Enable telnet, ssh, uart and boot_wait.
[ "$(nvram get telnet_en)" = 0 ] && nvram set telnet_en=1 && nvram commit
[ "$(nvram get ssh_en)" = 0 ] && nvram set ssh_en=1 && nvram commit
[ "$(nvram get uart_en)" = 0 ] && nvram set uart_en=1 && nvram commit
[ "$(nvram get boot_wait)" = "off" ] && nvram set boot_wait=on && nvram commit
[ "$(uci -c /usr/share/xiaoqiang get xiaoqiang_version.version.CHANNEL)" != 'stable' ] && {
uci -c /usr/share/xiaoqiang set xiaoqiang_version.version.CHANNEL='stable'
uci -c /usr/share/xiaoqiang commit xiaoqiang_version.version 2>/dev/null
}
channel=$(/sbin/uci get /usr/share/xiaoqiang/xiaoqiang_version.version.CHANNEL)
if [ "$channel" = "release" ]; then
sed -i 's/channel=.*/channel="debug"/g' /etc/init.d/dropbear
fi
if [ -z "$(pidof dropbear)" -o -z "$(netstat -ntul | grep :22)" ]; then
/etc/init.d/dropbear restart 2>/dev/null
/etc/init.d/dropbear enable
fi
logger -t auto_ssh "SSH access unlocked successfully."
}
install() {
# unlock SSH.
unlock
# host key is empty, restart dropbear to generate the host key.
[ -s $host_key ] || /etc/init.d/dropbear restart 2>/dev/null
# Backup the host key.
if [ ! -s $host_key_bk ]; then
i=0
while [ $i -le 30 ]; do
if [ -s $host_key ]; then
cp -f $host_key $host_key_bk 2>/dev/null
break
fi
i=$((i + 1))
sleep 1s
done
fi
# Add script to system autostart
cat >/data/auto_ssh/cron_start.sh <<'EOF'
#!/bin/sh
MARKER="/tmp/auto_ssh_started"
LOG="/tmp/auto_ssh_boot.log"
SCRIPT="/data/auto_ssh/auto_ssh.sh"
# Run only once during the current boot.
[ -e "$MARKER" ] && exit 0
# Check whether netifd has registered the LAN interface.
ubus call network.interface.lan status | grep -q '"up": true' || exit 0
# Wait until the persistent script is available.
[ -r "$SCRIPT" ] || exit 0
# Run the startup script and mark this boot as initialized.
if /bin/sh "$SCRIPT" >>"$LOG" 2>&1; then
touch "$MARKER"
logger -t auto_ssh "Startup script executed by cron"
fi
EOF
chmod 755 /data/auto_ssh/cron_start.sh
grep -Fq '/data/auto_ssh/cron_start.sh' /etc/crontabs/root ||
echo '* * * * * /bin/sh /data/auto_ssh/cron_start.sh' \
>>/etc/crontabs/root
echo -e "\033[32m SSH unlock complete. \033[0m"
}
uninstall() {
# Remove the cron entry.
if [ -f /etc/crontabs/root ]; then
sed -i '\|/data/auto_ssh/cron_start\.sh|d' /etc/crontabs/root
fi
# Remove the cron wrapper script.
rm -f /data/auto_ssh/cron_start.sh
# Remove the current boot marker and log.
rm -f /tmp/auto_ssh_started
rm -f /tmp/auto_ssh_boot.log
# Reload cron if it is running.
/etc/init.d/cron restart 2>/dev/null ||
killall -HUP crond 2>/dev/null ||
true
echo -e "\033[33m SSH autostart has been removed. \033[0m"
}
multiplex() {
sleep 40
#
# VLAN10
#
uci set network.vlan10='interface'
uci set network.vlan10.type='bridge'
uci set network.vlan10.proto='none'
uci set network.vlan10.force_link='1'
uci set network.vlan10.ifname='eth1.3 eth0.1.10'
#
# VLAN20
#
uci set network.lan.type='bridge'
uci set network.lan.proto='static'
uci set network.lan.force_link='1'
uci set network.lan.ifname='eth0.2 eth1.4 eth0.1.20'
ubus call network reload
}
main() {
case "$1" in
"")
unlock
multiplex &
;;
install)
install
;;
uninstall)
uninstall
;;
*)
echo -e "\033[31m Unknown parameter: $1 \033[0m"
return 1
;;
esac
}
main "$@"
VLAN 10 桥接光猫和 PVE 小主机
VLAN 20 桥接 WiFi、其余网口和 PVE 小主机
最后由于莫名其妙的断流问题还是放弃了……下次不折腾小米路由器原厂系统了,除非能刷 OpenWrt 否则不买(