Recently, I needed to push a static route out to all DHCP clients on a network. With my memory full of Cisco ios commands, I figured this would be a piece of cake to implement before going on about my day. Well, come to find, things aren’t as straight forward on a Mikrotik Hex router (which I shouldn’t say was a huge surprise). Options like this are set using the hexadecimal values rather than the dot-decimal octets you’re likely familiar with.
If you want to advertise a static route to your DHCP clients from a DHCP server that you have configured in RouterOS, follow these steps:
- Confirm the subnet mask of the network you want to advertise and convert it to hexadecimal.
Confirm the network address of the network you want ot advertise and convert the significant octets into hex.
- so for a 10.10.10.0/24 network, you only convert 10.10.10 into hex
- for a 10.10.0.0/16 network, you only convert the 10.10 into hex
Confirm the gateway address of the network you want to advertise and convert the entire IP into hex.
Under IP> DHCP Server> Options, add an option with code 121 (signifying a static route) and the data you converted to hex as one long string.
- so for a 10.10.10.0/24 network, reachable via 18.104.22.168 you would input 0x180A0A0A0C0C0C96
- 0x - to signify hex
- 18 - the hex value for the subnet mask /24
- 0A0A0A - the hex value for the significant octets of the Network Address, 10.10.10
- 0C0C0C96 - the hex value of the gateway ip of 22.214.171.124
Under IP> DHCP Server> Networks, choose the network you want to advertise this on, then edit the configuration and select the name of the new option you just defined. Making sure to apply your changes before leaving this config screen.
Done, your DHCP server should now be serving the static route you set. Wait for client leases to expire or release and renew on client side. Confirm the new route is present in your DHCP clients routing table before calling it done.
Maybe this is more commonplace than I think, but specifying this information in hexadecimal is not something I was expecting. With a couple minutes and a blank spreadsheet I was able to do the conversion but to make IP to hex conversion easier in the future I am writing a script that will do the work for me. I’ll set it up as a bash script or in python (or both) and will be posting the code to my site when it’s finished. Should be pretty soon.
Hope this was helpful to someone out there! This is all in the documentation from Mikrotik if you look for it but should still be helpful laid out step-by-step.