Community discussions

MikroTik App
 
User avatar
rosman
newbie
Topic Author
Posts: 27
Joined: Wed Jun 27, 2018 12:30 am
Location: Southlake, Texas, USA - Dallas-Forth Worth Metro

PCC with DHCP clients

Thu Jun 28, 2018 6:45 pm

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
 
Sob
Forum Guru
Forum Guru
Posts: 9121
Joined: Mon Apr 20, 2009 9:11 pm

Re: PCC with DHCP clients

Thu Jun 28, 2018 9:07 pm

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

https://wiki.mikrotik.com/wiki/Manual:I ... pt_example
 
User avatar
rosman
newbie
Topic Author
Posts: 27
Joined: Wed Jun 27, 2018 12:30 am
Location: Southlake, Texas, USA - Dallas-Forth Worth Metro

Re: PCC with DHCP clients  [SOLVED]

Thu Jun 28, 2018 11:34 pm

Thank you very much. That looks like exactly what I need.
 
User avatar
rosman
newbie
Topic Author
Posts: 27
Joined: Wed Jun 27, 2018 12:30 am
Location: Southlake, Texas, USA - Dallas-Forth Worth Metro

Re: PCC with DHCP clients

Mon Jul 16, 2018 1:52 am

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]
}
}

Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 25 guests