lazardo DD-WRT User
Joined: 17 Apr 2014 Posts: 141 Location: SF Bay Area
|
Posted: Tue Mar 19, 2024 20:46 Post subject: identity toggle for dual router upgrades |
|
Router A, primary in service and functioning
Router B, backup, upgrades, experiments.
Occasionally it is nice to leave the primary running and do work on secondary, eg, firmware upgrades, major config changes. This script allows swapping LAN identity while both are active and LAN-connected.
Router A
192.168.1.101
ssid 24 + ssid 5g
dns on, dhcp on, LAN+WAN active
Router B
192.168.1.102
ssid 24_ + ssid 5g_
dns->Router A, LAN port->Router A LAN (or switch), dhcp off, WAN off
Running the script on Router B toggles to A. While Router B is rebooting, swap WAN/LAN ethernet to Router B.
Update: case statement corrected.
Code: | #!/bin/sh
set -e
# toggle LAN identity
LAN_1=192.168.1.101
SSID24=24
SSID50=5g
WAN_1='wan_dns="8.8.8.8 8.8.4.4 9.9.9.9"' # Note quoting
LAN_2=192.168.1.102
#########################
CORE_1="lan_ipaddr=$LAN_1 lan_proto=dhcp"
WIFI_1="wl_ssid=$SSID24 wl0_ssid=$SSID24 wl1_ssid=$SSID50"
WAN_2="wan_dns=$LAN_1"
CORE_2="lan_ipaddr=$LAN_2 lan_proto=static"
WIFI_2="wl_ssid=${SSID24}_ wl0_ssid=${SSID50}_ wl1_ssid=${SSID50}_"
#########################
case $( nvram get lan_ipaddr ) in
#case "$1" in # debug
$LAN_1)
echo "$LAN_1 -> $LAN_2"
for NVRAM in $CORE_2 $WIFI_2 "$WAN_2"; do # Note quoting
# echo nvram set $NVRAM
nvram set $NVRAM
done
;;
$LAN_2)
echo "$LAN_2 -> $LAN_1"
for NVRAM in $CORE_1 $WIFI_1 "$WAN_1"; do # Note quoting
# echo nvram set $NVRAM
nvram set $NVRAM
done
;;
esac
sleep 5
nvram commit
reboot # OR restart appropriate services manually
|
|
|