There is heaps of information about configuring a Mikrotik Router as an OpenVPN server on the net. The following simply documents what I found when I tried to follow in their footsteps.
The first reference I found was Medo’s instructions on how to configure the VPN, I used this to create the certificates, configure the server and get close to a working solution.
However my configuration was a little different in that the remote device I was connecting too (RB411 over 3G) did not have a FQDN only a fixed IP. So for the ca-template and server-template I used the Fixed IP (xx.xx.xx.xx) for the common name, for the client-template I used the name of the router (RouterName).
/certificate add name=ca-template common-name=xx.xx.xx.xx days-valid=3650 key-size=4096 key-usage=crl-sign,key-cert-sign add name=server-template common-name=xx.xx.xx.xx days-valid=3650 key-size=4096 key-usage=digital-signature,key-encipherment,tls-server add name=client-template common-name=RouterName days-valid=3650 key-size=4096 key-usage=tls-client
I’ve changed both the IP and RouterName to protect the innocent, I’m sure any readers will figure out where to insert their own configuration.
I also found that if you did not change the common name of the client-template certificate then the signing process of Medo’s post would fail with a weird error message.
/certificate sign ca-template name=ca-certificate sign server-template name=server-certificate ca=ca-certificate sign client-template name=client-certificate ca=ca-certificate
Now getting the certs off the remote router was also “interesting”. This wasn’t something that I’d really done before. So after a bit of googling and some trial and error I ended up using the pscp utility that is part of the PuTTY package. You can find the relevant certificates using the /file command.
C:\Program Files (x86)\PuTTY>pscp -r -P 22 firstname.lastname@example.org:/* \temp email@example.com's password: ca-certificate.crt | 1 kB | 1.8 kB/s | ETA: 00:00:00 | 100% server-certificate.crt | 1 kB | 1.8 kB/s | ETA: 00:00:00 | 100% client-certificate.key | 4 kB | 1.8 kB/s | ETA: 00:00:00 | 100%
Once I had the certs on my local machine I could continue to follow Medo’s blog.
Now I didn’t want the VPN users to end up in a different IP address space, so I changed my VPN DHCP pool range to be just under the usual Ethernet pool and then set the VPN local address to be the next address under the VPN pool. Here’s a quick overview;
VPN local_address: xx.xx.xx.64 VPN dhcp_pool: xx.xx.xx.65-xx.xx.xx.75 ethernet dhcp_pool: xx.xx.xx.100-xx.xx.xx.200
So I ended up modifying the following commands;
/ip pool add name="vpn-pool" ranges=xx.xx.xx.65-xx.xx.xx.75 /ppp profile add name="vpn-profile" use-encryption=yes local-address=xx.xx.xx.64 dns-server=xx.xx.xx.64 remote-address=vpn-pool secret add name=user profile=vpn-profile password=p4ssw0rd /interface ovpn-server server set default-profile=vpn-profile certificate=server-certificate require-client-certificate=yes auth=sha1 cipher=aes256 enabled=yes
Now before anyone says anything you need to change the name and password to suit your own VPN user, at the very least make sure you use a good password. You’ll notice I dropped the AES-128 and AES-192 ciphers in preference to the 256bit option. More on this later.
This is where I ran into trouble that took me a while to resolve.
I had installed OpenVPN GUI 2.4.5 which simply refused to connect, it throws TLS errors that are odd. It turns out that as of OpenVPN 2.3.11 there was a change made that makes it incompatible with older Mikrotik routers, you can read all about it here and there is more information here.
This post also talks about being able to use the tls-cipher parameter to force the client to relax it’s checking of certificates, however I wasn’t able to make this work. It appears that the latest version of RouterOS have fixed this issue, but that has to wait until I’m next at the console of this particular router to upgrade it.
So after uninstalling the latest OpenVPN 2.4.5 GUI and installing an older version OpenVPN 2.3.10, I was able to connect to my RB411 with v3.2.2 firmware with the following config;
client dev tun proto tcp-client remote xx.xx.xx.xx 1194 resolv-retry infinite nobind persist-key persist-tun cipher AES-256-CBC verb 3 remote-cert-tls server auth SHA1 auth-user-pass redirect-gateway def1 ca "C:\\Program Files\\OpenVPN\\config\\ca-server.crt" cert "C:\\Program Files\\OpenVPN\\config\\server.crt" key "C:\\Program Files\\OpenVPN\\config\\client.key"
As you may notice I use Windows for my main machine, so Mac and Linux users will have to do a little more googling on how to specify the paths in this file. Now the cipher matches the tweak I made to the ovpn-server within the mikrotik router limiting the choice to AES-256 bit.
The proof is in the pudding, after copying all of the certs and config into the approriate directory I could get the VPN client to connect to my remote Mikrotik RB411 router over the VPN. Many thanks to Medo for blogging his adventures with RouterOS and I hope the suggestions I’ve made above are useful to some.