Introduction
Are you looking to turn your standard Linux VPS into a powerful network router? MikroTik’s Cloud Hosted Router (CHR) is a version of RouterOS intended for running as a virtual machine. It supports the x86 64-bit architecture and can be used on most popular hypervisors like VMWare, Hyper-V, KVM, and others.
In this tutorial, we will show you how to convert an existing Ubuntu VPS into a MikroTik CHR. We will cover scripts for both RouterOS v7 and v6.
Prerequisites
Before running any scripts, we need to identify your disk name and network interface name. This is crucial because if you use the wrong interface name, your router will not have internet connectivity after installation.
1. Find the Disk Name
Run the following command to check your storage devices:
lsblk
In most cases (and in this tutorial example), /dev/vda is the primary drive.
2. Find the Network Interface Name
Run this command to find your interface name:
ip addr
Note the name displayed. It is usually eth0 or ens6.
Method 1: Installing RouterOS Version 7.x.x
If you want to use the latest features of MikroTik, use Version 7. Use the script below to download and install the CHR image.
Important:
-
Replace ens6 in the script below with your actual interface name found in the previous step.
-
This script assumes the disk is /dev/vda.
Copy and run the following block as a single command in PuTTy or your SSH terminal:
wget https://download.mikrotik.com/routeros/7.19.4/chr-7.19.4.img.zip -O chr.img.zip && \ gunzip -c chr.img.zip > chr.img && \ mount -o loop,offset=17408 chr.img /mnt && \ ADDRESS=`ip addr show ens6 | grep global | cut -d' ' -f 6 | head -n 1` && \ GATEWAY=`ip route list | grep default | cut -d' ' -f 3` && \ echo "/ip address add address=$ADDRESS interface=[/interface ethernet find where name=ether1] /ip route add gateway=$GATEWAY " > /mnt/autorun.scr && \ umount /mnt && \ echo u > /proc/sysrq-trigger && \ dd if=chr.img bs=1M of=/dev/vda && \ reboot
Method 2: Installing RouterOS Version 6.x.x (Legacy)
If you prefer the stability of the older Version 6 or have specific requirements for it, use the script below.
Important:
-
Replace eth0 in the script below with your actual interface name.
-
Note that the mount offset and path differ slightly from Version 7.
Copy and run this command on Ubuntu in PuTTy as root login:
cd /root wget https://download.mikrotik.com/routeros/6.49.17/chr-6.49.17.img.zip apt install -y unzip unzip chr-6.49.17.img.zip mkdir -p /mnt/chr mount -o loop,offset=512 chr-6.49.17.img /mnt/chr ADDRESS=$(ip -4 addr show ens6 | awk '/inet /{print $2}' | head -n1) GATEWAY=$(ip route | awk '/default/{print $3}') cat <<EOF > /mnt/chr/autorun.scr /ip address add address=$ADDRESS interface=ether1 /ip route add gateway=$GATEWAY /ip service disable telnet,ftp,www,api,api-ssl EOF sync umount /mnt/chr dd if=chr-6.49.17.img of=/dev/vda bs=1M conv=fsync status=progress sync reboot -f
Then, do a hard restart from your VPS provider’s control panel.
Troubleshooting & Post-Installation
What if I see an error?
While running the script, the system writes the image directly to the disk header. If you see an error message in PuTTy or the session hangs, ignore it. The VPS might have already started the reboot process or lost SSH connectivity because the OS changed.
Simply go to your VPS provider’s control panel and Force Restart (Reboot) the server manually.
Accessing MikroTik
Once the server reboots, it is no longer Ubuntu; it is now a MikroTik Router.
-
Download Winbox from the MikroTik website.
-
Connect using the IP address of your VPS.
-
Default User: admin
-
Default Password: (Leave blank)
Note: Ensure your VPS provider’s external firewall allows the necessary ports, simply open all ports and manage security via the CHR’s internal firewall.
Conclusion
Congratulations! You have successfully replaced your Ubuntu OS with MikroTik CHR. You can now configure your cloud router for VPNs, firewalls, or bandwidth management just like a physical MikroTik device.
