A set of Bash scripts for Linux that automate MikroTik Netinstall, making it easy to recover or reinstall RouterOS when a router is stuck, misconfigured, or needs a clean reset.
Mikrotik documentation to netinstall can be found from: https://help.mikrotik.com/docs/spaces/ROS/pages/24805390/Netinstall
These scripts were created with the assistance of AI tools, specifically Gemini 2.5 Pro and ChatGPT-5 models.
This repository contains two bash scripts to simplify the process of reinstalling MikroTik RouterOS using Netinstall on a Linux machine.
fetch_mikrotik_stable.sh
: A downloader that automatically finds and fetches the latest stable RouterOS.npk
package and the correspondingnetinstall
archive.auto_netinstall_mikrotik_stateful.sh
: A stateful installer that prepares your host machine's network for the Netinstall process, runs the tool, and safely restores your network configuration afterward.
This script automates downloading the necessary files from MikroTik's servers.
Features:
- Auto-Version Detection: Automatically detects the latest stable v7 RouterOS version from MikroTik's changelogs.
- Specific Version Support: You can specify a version to download with the
--version
flag. - Architecture Selection: Downloads for a specific hardware architecture (defaults to
arm64
). - Automatic Extraction: Can optionally unpack the
netinstall
archive and make thenetinstall-cli
binary executable. - Smart Fallback: Tries to download the
.tar.gz
archive first and falls back to.zip
if the first is unavailable.
Make the script executable first: chmod +x fetch_mikrotik_stable.sh
# Download the latest stable arm64 package and Netinstall into the current directory
./fetch_mikrotik_stable.sh
# Download to your Desktop and automatically extract the Netinstall archive
./fetch_mikrotik_stable.sh --dir ~/Desktop --extract
# Download a specific version and architecture
./fetch_mikrotik_stable.sh --version 7.15.1 --ros-arch mmips
This is a wrapper script for the netinstall-cli
binary that safely manages your host computer's network state, making the process much smoother and less error-prone. It only uses local files and does not download anything.
It must be run with sudo
because it needs to modify network interfaces and firewall rules.
Features:
- Stateful Network Management: It temporarily configures a static IP on your machine for Netinstall and automatically restores your previous network settings (like DHCP) on exit, even if the script is interrupted (Ctrl+C).
- File Auto-Discovery: Automatically finds the
netinstall-cli
binary and the RouterOS.npk
package in the current directory. - Interactive Interface Picker: If you don't specify a network interface, it provides a menu to choose from, preventing you from using the wrong one.
- Pre-flight Checks & Helpers:
- Warns you if other active network links (like Wi-Fi) might interfere.
- Asks if you want to temporarily disable Wi-Fi (
nmcli
) and your firewall (ufw
/firewalld
) to ensure a successful connection. - Uses
tcpdump
(if available) to listen for the MikroTik device's BOOTP request, confirming it's in the correct mode. - Pings the device at its default IP (
192.168.88.1
) after installation to verify success.
Make the script executable first: chmod +x auto_netinstall_mikrotik_stateful.sh
# Run interactively - the script will prompt you to select an interface
# and ask about disabling Wi-Fi/firewall.
sudo ./auto_netinstall_mikrotik_stateful.sh
# Specify the network interface directly (avoids the picker)
sudo ./auto_netinstall_mikrotik_stateful.sh --iface enp3s0
# Specify custom paths and IPs, and skip the configuration reset
sudo ./auto_netinstall_mikrotik_stateful.sh \
--iface enx001122334455 \
--host-ip 10.0.0.10 \
--npk ./routeros-arm-7.14.npk \
--netinstall-cli ./netinstall-7.14/netinstall-cli \
--no-reset
# Automatically say "yes" to disabling Wi-Fi
sudo ./auto_netinstall_mikrotik_stateful.sh --wifi-off
-
Download Files: Run the
fetch
script to get all the necessary files from MikroTik. Use--extract
for convenience../fetch_mikrotik_stable.sh --extract
-
Prepare for Install:
- Connect your PC directly to the MikroTik device's ether1 port with an Ethernet cable.
- Power off the MikroTik device.
-
Run Installer: Execute the
netinstall
script withsudo
. Follow the on-screen prompts.sudo ./auto_netinstall_mikrotik_stateful.sh
-
Enter Etherboot Mode: When the script tells you, press and hold the
RESET
button on the MikroTik device, apply power, and keep holding it until the script detects the device. -
Start Transfer: Press Enter in the terminal to begin the installation. The script will handle the rest and clean up your network settings when it's done.