HiBlog Linux and Windows Server HiCademy

How to Install MikroTik on Ubuntu with an Automatic Script

  • A. MounesiAuthor
  • Last updated
  • 6 minutesReading time
  • 1,753Views
  • A. Mounesi
  • Last updated:
  • 6 min read
  • 1,753 views
How to Install MikroTik on Ubuntu with an Automatic Script

When you have a VPS running Ubuntu and want to set up MikroTik RouterOS on it, for routing, a firewall, traffic management or network practice, the first obstacle is that on a VPS you cannot simply plug in a USB stick or attach the MikroTik ISO and install from scratch the way you would on an ordinary computer. Many people end up building a virtual machine inside Ubuntu at this point and lose hours to its settings!

That is why we at HiData wrote a script that turns installing MikroTik on Ubuntu into a single command: it writes MikroTik’s cloud edition (CHR) straight onto the server’s disk and brings the server up with MikroTik in a few minutes. In this tutorial we run the script, log in to MikroTik, make the first security settings and cover the CHR licence points too.

Before you start: this script replaces Ubuntu with MikroTik and rewrites the server’s whole disk. All of the server’s current files and data are erased. If there is anything important on the server, back it up first and download the backup to your own computer.

What is MikroTik CHR?

MikroTik makes the RouterOS operating system for routers and network devices. CHR (Cloud Hosted Router) is a version of RouterOS built to run on virtual machines and virtual servers, with all of RouterOS’s features. What sets it apart from other versions is the licence:

  • Free licence: every feature works, but the upload speed of each interface is limited to 1 Mbit/s.
  • Paid P1, P10 and P-Unlimited licences: up to 1 Gbit, 10 Gbit and unlimited speed respectively.
  • 60-day trial: you can try any paid level for 60 days with an account on the MikroTik website.

So if you see a speed of about 1 Mbit after the installation, the server is not slow; that is the free licence’s limit.

Requirements

  • A VPS with Ubuntu; the script has been tested on Ubuntu 20.04 and 22.04.
  • Root access, or a user with sudo rights, over SSH.
  • An internet connection on the server, so the script can download the MikroTik installation file.
  • Access to the VPS panel to turn the server off and on and to open the VNC console, in case you need them after the installation.

CHR does not need many resources: according to MikroTik’s documentation, 256 MB of RAM and 128 MB of disk are enough.

Step 1: Run the MikroTik installation script

Log in to the Ubuntu server over SSH, then copy this command in full and run it. It downloads the installation script from HiData’s download server and runs it:

curl -sSL https://dl.hidata.org/scripts/MikrotikUbuntu.sh -o MikrotikUbuntu.sh && chmod +x MikrotikUbuntu.sh && sudo ./MikrotikUbuntu.sh

The script does these things in order:

  1. It asks for the MikroTik version: 7.14.3, 7.9, 7.7, 6.49.15 or 6.49.13. Unless you have a particular reason for version 6, press 1, which is 7.14.3.
  2. It installs the kpartx package it needs to work with the installation file.
  3. It downloads the CHR installation file from HiData’s download server and unpacks it.
  4. It finds the server’s IP and gateway and shows them. Keep these two values somewhere; you need them if MikroTik’s network does not come up on its own.
  5. It writes the MikroTik file onto the server’s disk and restarts the server.

After the message Installation completed successfully, the SSH connection drops and the server boots into MikroTik. If MikroTik is not reachable after a few minutes, turn the server off and on once from the VPS panel.

Step 2: Log in to MikroTik

Get the Winbox program from the MikroTik download page, type the server’s IP in Connect To and log in with the user name admin and an empty password.

If Winbox cannot connect, open the VNC console from the VPS panel, log in as admin with an empty password and set the IP and gateway the script showed you by hand:

/ip address add address=203.0.113.10/24 interface=ether1
/ip route add gateway=203.0.113.1

Instead of 203.0.113.10/24, write your own server’s IP with the same number after the / that the script showed, and instead of 203.0.113.1 the same gateway.

Step 3: Secure MikroTik

A MikroTik left open on the internet with an empty password gets found sooner or later! Do these things right away, from New Terminal in Winbox or in the VNC console:

  • Set a strong password: /user set admin password="YourStrongPassword"; write your own password instead of YourStrongPassword.
  • Turn off the services you do not need: /ip service disable telnet,ftp,www,api,api-ssl
  • Allow Winbox only from your own IP: /ip service set winbox address=198.51.100.7/32; write your own internet IP instead of 198.51.100.7. If your internet IP keeps changing, skip this, or you will lock yourself out.
  • Update RouterOS: /system package update check-for-updates and then /system package update install.

Check the current licence level with /system license print too. If you need more than 1 Mbit, get the trial or buy a licence from the same section.

Rules for an Iran VPS

On HiData’s Iran VPS, setting up a VPN, proxy or tunnel is forbidden by HiData’s terms, and it also puts the server’s IP at risk of being blocked. Use MikroTik for routing, firewalling, traffic management and network training and testing.

Frequently asked questions

Can I run MikroTik alongside Ubuntu?

Not with this script; MikroTik takes Ubuntu’s place. To run both at once you would need CHR inside a virtual machine (with KVM, for example) on Ubuntu, which requires nested virtualization, and that is not available on most VPSs. If you need both, get two separate servers.

How do I go back to Ubuntu?

Reinstall Ubuntu from the VPS panel. Keep in mind that reinstalling erases all of MikroTik’s settings too; if you need them, export them from MikroTik first.

Should I choose version 6 or 7?

Version 7. New features and security fixes come out for version 7. Choose version 6 only if you have a ready configuration for it that you do not want to change.

A VPS for MikroTik

Order a HiData VPS with Ubuntu, run this same script and have your own MikroTik in a few minutes. On HiData’s Iran VPS, if MikroTik does not come up or you get a network setting wrong, you still reach the server through the VNC console in the server panel, without opening a ticket. And if you would rather install from an ISO file, send the file’s link to the technical team and they attach it to the server.

Sources

Share Post

hidata.org/en/blog/install-mikrotik-on-ubuntu-server/
In Social Media

Add Comment

Related Articles