Mikrotik openvpn server push routes

Hi. sorry for my english :slight_smile:. I have a problem. server is configured to mikrotik openvpn. I would want that Mikrotik pushing routes client to the local network. But I would not succeed. Mikrotik support this feature? If not, what are the alternatives?

MT doesn’t push the routes. You have to set them in the config file. I think you cannot set the default route because of permission problems, but you can create a set of rules that route everything through the vpn interface except the address to the VPN server itself. Usually you can make it with 10-15 rules

Here is a small perl app that can do this

run it from command line and give it the IP of the server as the first parameter and the IP of the new default GW as the second.

You need to install the Net::CIDR and NetAddr::IP modules.

… and I apologize for any possible mistypes.


#!/usr/bin/perl -w

use Net::CIDR;
use Net::CIDR β€˜:all’;
use NetAddr::IP;

@c2s=(
β€˜0.0.0.0’,
β€˜128.0.0.0’,
β€˜192.0.0.0’,
β€˜224.0.0.0’,
β€˜240.0.0.0’,
β€˜248.0.0.0’,
β€˜252.0.0.0’,
β€˜254.0.0.0’,
β€˜255.0.0.0’,
β€˜255.128.0.0’,
β€˜255.192.0.0’,
β€˜255.224.0.0’,
β€˜255.240.0.0’,
β€˜255.248.0.0’,
β€˜255.252.0.0’,
β€˜255.254.0.0’,
β€˜255.255.0.0’,
β€˜255.255.128.0’,
β€˜255.255.192.0’,
β€˜255.255.224.0’,
β€˜255.255.240.0’,
β€˜255.255.248.0’,
β€˜255.255.252.0’,
β€˜255.255.254.0’,
β€˜255.255.255.0’,
β€˜255.255.255.128’,
β€˜255.255.255.192’,
β€˜255.255.255.224’,
β€˜255.255.255.240’,
β€˜255.255.255.248’,
β€˜255.255.255.252’,
β€˜255.255.255.254’,
β€˜255.255.255.255’);

$ip=$ARGV[0];
$gw=$ARGV[1];

my $prv=NetAddr::IP->new($ip) - 1;
my $nxt=NetAddr::IP->new($ip) + 1;

my @mi=Net::CIDR::range2cidr(β€œ0.0.0.0-”.$prv);
foreach $mi(@mi)
{
($elso,$masodik)=split(///,$mi);
print β€œroute β€œ.$elso.” β€œ.$c2s[$masodik].” β€œ.$gw.” \n”;
}

my @mo=Net::CIDR::range2cidr($nxt.β€œ-255.255.255.255”);
foreach $mo(@mo)
{
($elso,$masodik)=split(///,$mo);
print β€œroute β€œ.$elso.” β€œ.$c2s[$masodik].” β€œ.$gw.” \n”;
}