OpenVPN is one of the most effective VPN connection types on MikroTik and, in terms of security and speed, one of the best ways to connect branches, offices and companies over the internet. To connect, users are usually given an OpenVPN configuration file. For this guide, you’ll first need an Iran MikroTik VPS. Once it’s set up, sign in to it.
What is an OpenVPN configuration file?
It’s a simple text file containing everything needed to connect to the server running OpenVPN: the server address, port, encryption algorithm, routes, username, SSL certificates and so on. On mobile phones the file usually has the .ovpn extension.
Before you start
To set up OpenVPN, your MikroTik server needs RouterOS 7.9 or later; in this guide we use 7.16. You’ll also need a license to use MikroTik, so we recommend reading our guide How to Activate a MikroTik License. First, we’ll create three certificates on the MikroTik VPS.
Create the CA certificate
In the left-hand menu, go to System > Certificates and click Add. Enter ca as both the Name and Common Name, and enter your VPS’s IP address in Subject Alt. Name (as shown below).


Under Key Usage, enable crl sign and key cert. sign, then click Sign to sign the certificate (as shown below).


Create the server certificate
Next, create the server certificate. Following the same steps, create a certificate named server. Under Key Usage, enable digital signature, key encipherment and tls server, then click Apply. Sign it as before, making sure you select the ca certificate you created in the CA field.



Create the client certificate
A client certificate isn’t strictly required for OpenVPN, and you could get by with the two certificates above, but for extra security we’ll create a client certificate too. Click Add again, enter client as the Name and Common Name, and enter your VPS’s IP address in Subject Alt. Name.

Under Key Usage, enable tls client, then sign the certificate as before (as shown below), again selecting the ca certificate in the CA field.


Once they’re created, export the ca and client certificates. Go to System > Certificates, right-click each one and choose Export, entering the certificate name as the File Name (as shown below).

The client certificate needs an Export Passphrase; in this guide we used the digits 1 to 9 (123456789).

After exporting, you’ll find the certificate files under Files in the left-hand menu.

Create an IP pool
The OpenVPN server needs an IP pool to assign addresses to clients. Go to IP > Pool, click Add, give it a name, and enter a private IP range under Addresses. For example, we used 192.168.10.2-192.168.10.254. Click OK.

Create a profile for OpenVPN
To connect users to OpenVPN, create a profile. Go to PPP > Profiles and click Add. Create a profile named vpn with Local Address 192.168.10.1, set Remote Address to the IP pool you created, and set DNS Server to 8.8.8.8 and 1.1.1.1.

Configure the OpenVPN server
Now configure the OpenVPN server. Go to PPP > Interface and click OVPN Server. Enable it, set Default Profile to vpn, set Certificate to server, enable Require Client Certificate, and complete the other settings as shown below.

To create the OpenVPN configuration file, click Export .ovpn. Enter your MikroTik VPS’s IP address in the first field, choose the ca certificate in the second, the client certificate in the third and the client certificate’s key in the fourth, then click Start.

Once it’s exported, go to Files, download the .ovpn file and save it on your computer.
Add a firewall NAT rule
Go to IP > Firewall > NAT, click Add and create a rule with Chain srcnat, Src. Address 192.168.10.0/24 and Action masquerade.
Summary
OpenVPN is a secure connection type on MikroTik that you can use to link two branches or companies. Imagine you have a MikroTik router at your workplace running OpenVPN, and you want your users to reach VoIP phones, file sharing or remote desktop over a secure internal connection. With this guide and your OpenVPN configuration file, they can now do that from outside the office. Thanks for reading, and follow the Mizbandade blog for more.

