PCC with DHCP clients

Environment: RouterOS v6.42.5 (stable) on 2011UiAS-2HnD NB: I’d prefer to RTFM, but I’m not sure where the FM is. Simple answers welcomed, but reading assignments are really appreciated - I’m here to learn.

I have feeds from two ISPs that require the DHCP client to get IP and Gateway information - no fixed IP is available. The PCC examples and command docs I can find only show fixed IPs. I’m guessing that there is a way to store the DHCP data in variables and use that in commands, but I haven’t found it yet.

Rich

FM and the part you’re looking for is here:

https://wiki.mikrotik.com/wiki/Manual:IP/DHCP_Client#Lease_script_example

Thank you very much. That looks like exactly what I need.

FWIW, here is my current DHCP Client script based on the article referenced above. . I'm not sure it's complete, but it is working.

{

Change RouteMark for each DHCP Client Instance

:local RouteMark "WAN2";
:local LocalGW $"gateway-address";
:log info "$RouteMark Gateway: $LocalGW";

:local count [/ip route print count-only where comment=$RouteMark]
/ip firewall mangle remove [find comment=$RouteMark]
:if ($bound=1) do={
:if ($count = 0) do={
/ip route add gateway=$LocalGW comment=$RouteMark routing-mark=$RouteMark
/ip firewall mangle add action=accept chain=prerouting disabled=yes
dst-address=$LocalGW comment=$RouteMark

} else={
:if ($count = 1) do={
:local test [/ip route find where comment=$RouteMark]
:log info "$RouteMark test: $test";
:if ([/ip route get $test gateway] !=$LocalGW) do={
/ip route set $test gateway=$LocalGW
}
/ip firewall mangle add action=accept chain=prerouting disabled=no
dst-address=$LocalGW comment=$RouteMark
} else={
:log info "$RouteMark routes found: $count";
:error "Multiple routes found"
}
}
} else={
/ip route remove [find comment=$RouteMark]
}
}