identity toggle for dual router upgrades

Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload
Author Message
lazardo
DD-WRT User


Joined: 17 Apr 2014
Posts: 140
Location: SF Bay Area

PostPosted: Tue Mar 19, 2024 20:46    Post subject: identity toggle for dual router upgrades Reply with quote
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
Sponsor
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Contributions Upload All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum