This guide takes inspiration from OpenWRT Mikrotik Guide.
- Nix Package Manager (optional but recommended)
- Vagrant or any other VM software
If you're using NixOS like I am, and want to follow this guide without changing your distribution, consider installing the Nix package manager from here.
-
Create a Directory for TFTP Server
mkdir ~/tftpserver/ cd ~/tftpserver/ mkdir srv/
-
Prepare Boot Files
Place the boot files for your specific router in the
srv/directory. Connect your Ethernet cable to port 1 of your router and the other end to your host machine. Access your router via WinBox or your browser, and navigate toSystem -> RouterBoot -> Settings. Change the following setting:- Boot method: DHCP (optional as dnsmasq supports bootp as well)
Note: If you can't access the router via WinBox through the
eth1port, try connecting the cable to port 2. However, the flash will only work through port 1. -
Initialize a Vagrant VM
cd ~/tftpserver/ vagrant init alpine/alpine64
Edit the generated
Vagrantfileto include the following line, ensuring the VM is on the same subnet as the router:config.vm.network "public_network", dev: "network_interface_placeholder"
Replace
network_interface_placeholderwith the network interface of the Ethernet connection associated with your router. -
Boot and Access the VM
vagrant up vagrant ssh
Change the root password in your VM:
sudo passwd root
-
Transfer Boot Files to the VM
From your host machine, transfer the initramfs file to the VM:
scp tftpserver/srv/openwrt-23.05.0-ath79-mikrotik-mikrotik_routerboard-951ui-2nd-*.bin vagrant@192.168.121.*:/home/vagrant/
-
Install and Configure dnsmasq
sudo apk update sudo apk add dnsmasq which dnsmasq
-
Create and Execute
loader.shScriptCreate a script named
loader.shwith the following content:#!/bin/bash IFNAME=eth1 /sbin/ip addr replace 192.168.88.10/24 dev $IFNAME /sbin/ip link set dev $IFNAME up /usr/sbin/dnsmasq \ --no-daemon \ --listen-address 192.168.88.10 \ --bind-interfaces \ -p0 \ --dhcp-authoritative \ --dhcp-range=192.168.88.100,192.168.88.200 \ --bootp-dynamic \ --dhcp-boot=/home/vagrant/openwrt-19.07-*-initramfs-* \ --log-dhcp \ --enable-tftp \ --tftp-root=/home/vagrant/
Ensure the script is executable and the initramfs file has the correct permissions:
chmod +x loader.sh chmod 644 /home/vagrant/openwrt-23.05.0-ath79-mikrotik-mikrotik_routerboard-951ui-2nd-*.binRun the TFTP server:
su ./loader.sh
-
Boot the Router into OpenWRT
Power off the router, press the reset button, and hold it while powering it back on for 15-20 seconds or until logs appear in the VM terminal. Your router should boot into OpenWRT. On rebooting, it will revert to RouterOS.
Note: Access OpenWRT via your browser at
http://192.168.1.1/.
If the router isn't accessible via WinBox or your browser, try the following:
-
Change the IP address attached to the network interface of your router's Ethernet connection to one in the same network as the router. NixOS users can add this to their
configuration.nix:networking.firewall.enable = false; networking.interfaces.<network_interface_placeholder> = { ipv4.addresses = [ { address = "192.168.88.x"; prefixLength = 24; } ]; useDHCP = true; };
If the router remains inaccessible, power it off, hold the reset button for 15-20 seconds while powering it back on. Access the router configuration page via WinBox or your browser, and go to System -> Reset Configuration to reset the router to the default RouterOS configuration.