DHCP classless issues

Hi Guys,

I wonder if someone could be kind enough to point out what I am doing wrong.

What I am trying to achieve is to set a classless route via DHCP as shown below.

https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Server#Options

Now what I am trying to do is the following..

VPN network/server
Network: 172.30.0.0/16
Gateway: 172.30.255.2
Default Route
Default route/gateway: 172.30.255.1

Now in linux you would simply do

ip route add 172.30.0.0/16 via 172.30.255.2

Now I am trying to push these via DHCP so it saves me having to do scripts on the windows and linux systems but I am having some issues.

Now I have figured out the following..

/ip dhcp-server option
add code=121 name=classless value=0x10AC1E0000AC1EFF02
/ip dhcp-server network
set 0 dhcp-option=classless

And this sets the 172.30.0.0/16 but the logs are erroring and its not working on the client. However I did some more research and it was because I didnt have the default route added, so I tried to add that in. Heres the latest code I got but this errors also. So what am I miss understanding?

/ip dhcp-server option
add code=121 name=classless value=0x10AC1E0000AC1EFF02000AC1EFF01
/ip dhcp-server network
set 0 dhcp-option=classless

Can anyone help?

In short this should send default gateway to 172.30.255.1 but anything on 172.30.0.0/16 via 172.30.255.2.

I have a feeling the example they give is slightly wrong but im sure someone can confirm that better then me.

Kind Regards,

Simon

UPDATE
Thanks to the following post:
http://forum.mikrotik.com/t/calculate-dhcp-option-121-classless-static-route-option/43789/1

who shares an awesome ruby script. I have managed to figure out what I was wrong.

Below is the final config for anyone who’s interested.

/ip dhcp-server option
add code=121 name=classless value=0x10ac1eac1eff0200ac1eff01
/ip dhcp-server network
set 0 dhcp-option=classless

I can confirm on the linux box that the route(s) are correct.

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.30.255.1    0.0.0.0         UG    202    0        0 eth0
172.30.0.0      172.30.255.2    255.255.0.0     UG    202    0        0 eth0
172.30.255.0    0.0.0.0         255.255.255.0   U     202    0        0 eth0

Below is the script command(s) to pull out the info you need.

[simon@manage(~)> ./classless-dhcp 172.30.255.2/16 172.30.255.1/0
NET: 172.30.0.0/16	GATEWAY: 172.30.255.2	DHCP(Opt. 121): 10ac1eac1eff02
NET: 0.0.0.0/0	GATEWAY: 172.30.255.1	DHCP(Opt. 121): 00ac1eff01

Then just add 0x at the start of those two concatenated together. So this would become.. 0x 10ac1eac1eff02 00ac1eff01 (without the spaces as they were added so you can see how its made up)

If you are using a built-in Windows VPN client in Windows 10 you can add routes via PowerShell that are toggled only when the VPN is active.

https://technet.microsoft.com/en-us/library/dn262649(v=wps.630).aspx

Add-VpnConnectionRoute