Using DHCP to deliver static routes

How to deliver static routes using DHCP

According to RFC 3442, we can assign static routes using DHCP option 121. This is a very useful resource in all kind of environments, but most people doesn’t know about it.

Basically, using option 121 on your DHCP server, you can deliver static routes to dhcp-clients. Let’s see how to do this using Mikrotik:

ip dhcp-server option
add code=121 name=route_192.168.11 value=0x18c0a80ba010101

And set this option in your network config:

/ip dhcp-server network
add address=192.168.0.0/24 dns-server=192.168.0.1 gateway=192.168.0.1 dhcp-option=route_192.168.11

Alright, if you found this post searching how to add static routes using dhcp, you problably already understood almost everything that we did. Almost… that value is.. what is that?

This is how you build that value to deliver your route:

The first part is the netmask, in our case “18” which means 24 when you convert the decimal 24 to hexadecimal.

The second part is the significant part of destination network, in our example, 192.168.11. Converting this to hexadecimal we get “c0a80b”.

The last part is the gateway. Converting 10.1.1.1 to hexadecimal we get “a010101”.

Now we know that: 0x[mask][significant part of destination network][gateway]

bonus tip

Using fortigate, how to deliver a static route via dhcp?

conf system dhcp server
edit [your server id]
config options

edit 0
set type hex
set code 121
set value 018c0a80ba010101
next
end

You will get this:

config options
  edit 1
    set code 121
    set value "018c0a80ba010101"
  next
end

 Share!

 
comments powered by Disqus