How to install OpenWrt on Xiaomi Mi Router 3

OpenWrt is an embedded operating system based on Linux. You will get full power of Linux in your home router. OpenWrt has a lot of powerful features that default firmware doesn’t offer. I tried other custom firmware for my Xiaomi Router 3 but I found that Pandorabox (OpenWrt based firmware) is an absolute killer! I’ve been using Pandorabox for almost a year and found no issue.

Let’s see what OpenWrt offers besides the default Xiaomi’s Chinese firmware:

  1. Supports ALL kinds of popular VPN protocols. (OpenVPN, L2TP, PPTP…)
  2. Torrent client. You don’t need to always power up your PC for downloading/seeding the big torrent files anymore. Your router will work as a low powered Seedbox.
  3. Run various servers. You can run a web server, a proxy server, IRC server and more!
  4. Using QoS (quality of service) which handles the packets travelling through your router. You can prioritize certain types of traffic with QoS. This is my favorite use case as I can reduce the lag while gaming by properly configuring the QoS.
  5. Capture the network traffic. You can capture the network traffic by using various network tool and analyze that traffic later. Useful to the network admin
  6. Real time accurate bandwidth monitoring and throttling.
  7. Monitor internet connectivity
  8. Ad blocking

and much much more. OpenWrt’s software repositories contain other packages that extends more functionality.

NOTE: There is no mobile app to control OpenWrt firmware as Xiaomi firmware does. Also, it is not easy to configure OpenWrt firmware. You need to have absolute patience and troubleshooting capability in order to configure it like the way you want. Also, if you are not a techie person, I will not recommend you to proceed.

Disclaimer

I will not take any responsibility if you brick your router by incorrectly following this tutorial. Though I’ve tested every steps several times and successfully install OpenWrt on my Xiaomi Router. I’ve bricked my router many times in order to find the right steps :p

Some basic knowledge of Linux commands and SSH are necessary.

Let’s begin (bricking or succeeding? :p )

What you need:

1. Xiaomi Mi WiFi Router 3 (duh!)
2. LAN Cable
3. USB Drive
4. Enough time
5. Brain/common sense

Step 1: Downgrading the official Xiaomi firmware to dev build

1.1. First, assuming that you are using official Xiaomi firmware. Backup your settings if you needed. Now, we need to downgrade to the dev build in order to enable SSH service. So download dev firmware from here:

1.2. Put downloaded “miwifi_r3_all_55ac7_2.11.20.bin” file on FAT/FAT32 formatted USB drive and rename it to “miwifi.bin” (without quote)

1.3. Power off the router and plug the USB into the router. Now hold the reset button and power it up until the yellow led starts flashing. A solid blue will appear after a few moments. We just flashed the dev firmware. Disconnect the USB.

Step 2: Preparing flash file and download firmware

2.1. Download the firmware file from here
2.2. Download Pandorabox boot file from here
2.3. Put “pb-boot-xiaomi3-20180726-0d8505f.img” file (boot file) to your FAT/FAT32 formatted USB drive

Step 3: Turning on SSH on Router

3.1. Connect your router through wifi with a default password.
3.2. Go to http://miwifi.com or http://192.168.31.1 and setup your router as usual.
3.3. Login to admin panel. Look at the url bar.
3.4. In url bar, after “stok=”, copy the code.


3.5 Replace the <STOCK> code in the below url and visit that url

http://miwifi.com/cgi-bin/luci/;stok=

<STOK>

/api/xqnetwork/set_wifi_ap?ssid=Xiaomi&encryption=NONE&enctype=NONE&channel=1%3Bnvram%20set%20ssh%5Fen%3D1%3B%20nvram%20commit

3.6. If your wifi disconnect, then connect again. Follow 3.3 and 3.4 step again
3.7. Replace the <STOCK> code in below url and visit that url

http://miwifi.com/cgi-bin/luci/;stok=

<STOK>

/api/xqnetwork/set_wifi_ap?ssid=Xiaomi&encryption=NONE&enctype=NONE&channel=1%3Bsed%20%2Di%20%22%3Ax%3AN%3As%2Fif%20%5C%5B%2E%2A%5C%3B%20then%5Cn%2E%2Areturn%200%5Cn%2E%2Afi%2F%23tb%2F%3Bb%20x%22%20%2Fetc%2Finit.d%2Fdropbear

3.8. You will probably disconnect again. Reconnect and follow 3.3 and 3.4 steps.
3.9. Replace the <STOCK> code in below url and visit that url

http://miwifi.com/cgi-bin/luci/;stok=

<STOK>

/api/xqnetwork/set_wifi_ap?ssid=Xiaomi&encryption=NONE&enctype=NONE&channel=1%3B%2Fetc%2Finit.d%2Fdropbear%20start

3.10. Again (one last time) you will be disconnected. Connect again and follow 3.3 and 3.4 steps.
3.11. Replace the <STOCK> code in below url and visit that url. BUT replace <OLD_PASSWORD> with your admin panel password (that you provided in step 3.2) and <NEW_PASSWORD> with your desire password

http://miwifi.com/cgi-bin/luci/;stok=

<STOK>

/api/xqsystem/set_name_password?oldPwd=

<OLD_PASSWORD>

&newPwd=

<NEW_PASSWORD>

Step 4: Entering into SSH and flash Pandorabox

4.0. Connect USB drive to router
4.1. Download and open PUTTY client
4.2. In SSH field, put your router IP address (192.168.31.1) and connect
4.3. Username is ‘root’ and password is <NEW_PASSWORD>
4.4. Now issue below commands:

#cd /extdisks/sda1
#cp pb-boot-xiaomi3-20180726-0d8505f.img /tmp
#cd /tmp
#mtd write pb-boot-xiaomi3-20180726-0d8505f.img Bootloader
#reboot

4.5. wait until the led turns into blue
4.6. Power off the router (disconnect the power cable) and then hold the reset button then power up the router, release the reset button after 2/3 seconds. Breath style yellow led will glow
4.7. Connect your router through LAN cable. Cable will go from router’s LAN port (not internet/wan port) to your PC.
4.8. now go to http://192.168.1.1 (while connected with LAN), you will see a PandoraBox firmware upgrade page. select your Pandorabox firmware (downloaded from step 2.1) and upload it. Router will be restarted when done.
4.9. Access the PandoraBox OpenWrt admin page by going http://192.168.1.1, default password is “admin”. Language is by default Chinese. Don’t panic if you don’t understand anything. Just go to the following link:
4.10. Select language “Chinese” to “auto”
4.11. Save and apply (middle button at the very bottom)

If you come this far, congratulation! You have successfully installed OpenWrt to your Xiaomi R3 router. Now configure internet connectivity.

Leave a Reply

Your email address will not be published. Required fields are marked *