How to migrate from an old OpenWrt router to a new one, with the least downtime for your home network
Tags: openwrt, opensource, security, networking
Published: 2023-07-15 09:00:00

> 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](https://support.apple.com/guide/macbook-pro/transfer-your-data-apda75cd668e/mac), at iOS you have [Quick Start](https://support.apple.com/en-nz/HT201269) 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](https://www.lifewire.com/how-to-use-titanium-backup-pro-on-android-4771843), and an open source one [Neo Backup](https://f-droid.org/en/packages/com.machiav3lli.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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3cmm2e5tpvzgssi435q3.png)


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:

```shell
opkg list-installed > installed_packages.txt
```

2. Copy the "installed_packages.txt" file to the new machine's file system, for example, using SCP:

```shell
scp installed_packages.txt root@new_openwrt_ip:/tmp/
```

3. Execute the following command to install the packages listed in the "installed_packages.txt" file:

```shell
opkg update 
opkg install $(cat /tmp/installed_packages.txt | awk '{print $1}')
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cj21xxx6cnr5x7q813lo.png)




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.

```shell
scp -r root@old-router:/etc/config /tmp/router-config
```

It should contain all these settings
- dhcp
- firewall
- wireless
- network
- software/add-ons settings



2. (Optional) backup new router default config
```shell
scp -r root@new-router:/etc/config /tmp/new-router-default-config
```
Just in case any settings go wrong in next step.


3. 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.


```shell
scp -r /tmp/router-config root@new-router:/etc/config
```


After all these, simply do a reboot.


## 3 Scheduled tasks

![schedule](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uiwk7ltq7xy7v6caqkfh.png)



> 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?