DEV Community

Tech Tim (@TechTim42)
Tech Tim (@TechTim42)

Posted on • Edited on • Originally published at tim.bai.uno

How to migrate from an old OpenWrt router to a new one, with the least downtime for your home network

As a fan of open source, self host, and privacy focus software, I always try to use transparent, open source, and free software as much as possible.

Long ago I bought a new router, because of work, I didn't get much time to install my favorite router firmware OpenWRT on it. To gain a better performance, I found a time slot to start to install it and migrate from the old one to the new one.

For Apple ecosystem, no matter iPhone or MacBook, Apple offers you some close-source but seamless tool for migration, at macOS, you have Apple Migration Assistant, at iOS you have Quick Start during set-up.

For Android/Lineage OS, it does not have a built-in tool for this, but due to there is a big Android community, there are plenty of tools to do it. I used to use some powerful backup tools for this, there is a paid one Titanium Backup, and an open source one Neo Backup, I tried both of them, both work very well.

But there is no such thing for OpenWrt. It means switching to the new router, users have to do some work to switch to new OpenWrt router, surely, everyone can just simply manually reconfigure the new router through UI to make it work, but it could cause you a lot of time, especially when you have a complex firewall settings. (like me).

In this article, I would like to share what I have found, what could be a good practice to archive it, to be as seamless as possible, to have as least downtime as possible.

1 Copy Software/Add-ons List and Reinstall

luci software list of openWrt

  1. In the original router, login to the router shell through SSH. Execute the following command to generate a list of installed packages and save it to a file:
opkg list-installed > installed_packages.txt
Enter fullscreen mode Exit fullscreen mode
  1. Copy the "installed_packages.txt" file to the new machine's file system, for example, using SCP:
scp installed_packages.txt root@new_openwrt_ip:/tmp/
Enter fullscreen mode Exit fullscreen mode
  1. Execute the following command to install the packages listed in the "installed_packages.txt" file:
opkg update 
opkg install $(cat /tmp/installed_packages.txt | awk '{print $1}')
Enter fullscreen mode Exit fullscreen mode

After all these, the new router should have all the software you have in the old one.

2 Configurations for Firewall, Network etc

Powerful /etc/config folder

etc/config of openWrt

OpenWrt has a very simple and clean structure to manage the configuration, there is no fancy database or encrypted storage, nearly all configurations are in plain text, stored in this folder /etc/config.

Ideally, after copy and paste it will work directly, but due to some router models difference, it is better to have some manually step here to check the configurations whether match or not on a new router.

  1. Pull the config folder from old router to the computer.
scp -r root@old-router:/etc/config /tmp/router-config
Enter fullscreen mode Exit fullscreen mode

It should contain all these settings

  • dhcp
  • firewall
  • wireless
  • network
  • software/add-ons settings
  1. (Optional) backup new router default config
scp -r root@new-router:/etc/config /tmp/new-router-default-config
Enter fullscreen mode Exit fullscreen mode

Just in case any settings go wrong in next step.

  1. Push the config to the new router at the same location

Before doing this, you may manually review the settings, for example,

  • static IP address in DHCP/Firewall (see more in the extra tips section below)
  • you should not need to push system config to new router, especially the new router is a different model.
scp -r /tmp/router-config root@new-router:/etc/config
Enter fullscreen mode Exit fullscreen mode

After all these, simply do a reboot.

3 Scheduled tasks

schedule

OpenWRT's scheduled tasks are actually just cron jobs in Linux.

  1. Go to old router, crontab -e, it will open a vi editor to display all cron jobs
  2. Copy them
  3. Login to the new router, run the command again, crontab -e
  4. Paste them

4 Some extra tips

There is one thing I found quite useful, because for software installation, the new router will require internet access as well, so what I found quite useful is to set the new router as sub-router of the old router, but with different LAN IP.

  • For example, for my old router, it is 192.168.1.1
  • For my new router, it is 172.16.1.1

So that, I can use one computer to login to 2 different router secure shells. It makes it very easy to copy the configuration and set them to new ones.

However, there is a disadvantage for this practice as well, in step 2 to copy configurations, for networks, DHCP, and firewall (if there are some static IP configuration) settings, we need to manually replace the old IP to new ones. It anyone has better idea for this, please share it to me. :)

Summary

After these 3 steps, you should be able to unplug old router and plug the new one, and all the clients supposed to just work without any changes.

If you want to let me know more about OpenWrt

  • How to set up OpenWrt router?
  • How to install it?
  • What are good practices to set up OpenWrt Firewall?

Top comments (0)