Bulk configure routers

Hi. I am looking for a solution to configure a large number of MT300N-V2 routers. I was thinking maybe a python script. The Wan port needs to be switched to Lan and the WiFi deactivated. To over simplify, connect 10 routers to a switch and run the script to copy a config file to each one. Can anyone recommend if this is the best approach please?

Build you own image, pre-configured as you need it, flash to router, and done

Thanks. Can you do this with about 10 routers at a time?

There are going to be challenges as they will all come up with the same IP address, so you’d need to either to sequentially connect to the wireless SSIDs that are seen (assuming that they are all different), or do it wired with a managed switch that “activates” one at a time.

Something as simple as

while there_are_still_routers_to_configure do
    activate_next_router_through_switch_cli
    scp path/to/image.bin root@192.168.8.1:/tmp/
    ssh root@192.168.8.1 sysupgrade -n /tmp/image.bin
done

The identical IP address problem was my main worry. I will have to do some more reading to find out what your script is doing. I am a novice. Thank you. This is great!

That’s the magic – and why is it a placeholder there.

It will depend on the CLI of your switch. Basically what it would to is to configure it so that it steps through the “device” ports, sequentially adjusting the VLAN mapping so that it connects one and only one to the port to which your “flasher” is attached. It will depend on the make and model series of your switch as to how that can be done. Consumer-grade switches may not have CLI access that permits this

Does the default stock firmware allow SSH access on the WAN port? If so that would remove the need for the VLANs and dynamic switch configuration… haven’t played with stock in a long time though as we usually just unbox and flash sequentially.

I don’t know the GL.iNet default config all that well, but it shouldn’t matter as you should be able to connect over the LAN port to do the re-flash.

Right, but as you said, if you connect to the LAN port then you can only have one device plugged in at a time… all I was thinking was if you did it using the WAN ports, by default they are configured to be DHCP clients… so assuming your “master flashing device” with the target firmware files available to it could also run a DHCP server, then in theory you could connect and flash as many units as you wanted without worrying about IP conflicts/etc.

For example, assuming SSH is available by default on the WAN port, my take on this would be:
a) Configure DHCP server to execute a script anytime a new DHCP lease is handed out.
b) Said script would check the MAC, make sure it matches a GL-Inet device range
c) wait a specific period of time (or do a ping loop waiting for a response) to give the device a chance to boot fully
d) Use SCP to connect to the device and pull the os_release or some other custom file that would allow you to check and see if device is running proper custom firmware or still at factory stock.
e) If still factory stock, then issue the SCP and sysupgrade commands as you mentioned before.

That way the process would be 100% automated. Literally all you would have to do is plug a bunch of units in and wait until you see them reboot on their own… or be really lazy and just leave them for a long enough time frame for things to complete (say 5 minutes), then unplug them all and do the next batch etc.

Just adding to the thought process as that’s how I’d tackle it, YMMV

SSH is not enabled for the WAN by default, you need to specifically add the port forward via the new firewall interface, or using the dynamic dns page. For older firmware you needed to add it via Luci if i remember correctly.