MikroTik CHR on a VPS

Today, we will convert an Ubuntu vps to a Cloud Hosted Router, powered by MikroTik.


First, find the disk name

lsblk

In this tutorial, the example, /dev/vda is the primary drive

Also find the network interface name

ip addr

The interface name may be eth0 or ens6

Now download the MikroTik CHR "Raw Disk Image"

https://mikrotik.com/download

Always use the latest Stable version

Run the below script as one command in PuTTy:


RouterOS Version 7.x.x script:

_____________________

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=1024 of=/dev/vda && \

reboot

___________________________


Wait a minute ! If you see any error in PuTTy just ignore that, and force restart your server.

Login via Winbox, make sure the port 8291 is opened.


___________________


RouterOS Version 6.x.x script:

_____________________


wget https://download.mikrotik.com/routeros/6.49.18/chr-6.49.18.img.zip -O chr.img.zip && \

gunzip -c chr.img.zip > chr.img && \

mount -o loop,offset=33554944 chr.img /mnt && \

ADDRESS=`ip addr show eth0 | 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/rw/autorun.scr && \

umount /mnt && \

echo u > /proc/sysrq-trigger && \

dd if=chr.img bs=1024 of=/dev/vda && \

reboot

Post a Comment