Community discussions

MikroTik App
 
danklod
just joined
Topic Author
Posts: 7
Joined: Thu Feb 08, 2018 2:33 pm

Simple script for set pref-source

Wed Aug 24, 2022 3:13 pm

Hi,

I'm trying to set pref-source on specific route on multiple device with the LAN address on each one router but I have problem. When I'm trying with this script nothing it happen.
For example I have:

/ip address
add address=10.0.5.1/24 comment="default configuration" interface=LAN network=10.0.5.0
/ip route
add distance=1 dst-address=10.120.0.0/16 gateway=10.10.10.1


:local langw1 [/ip address get [find interface="LAN"] address];
:local perfsrc1 [/ip route get [find dst-address=10.120.0.0/16 pref-src];

:if ($langw1 != $perfsrc1) do={
/ip route set pref-src=$langw1 [find dst-address=10.120.0.0/16];
}


I want to set 10.0.5.1 for "pref-src" but as variable value because on each one router this value will be different.

Can you help me with this?

Thank you!
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11967
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Simple script for set pref-source

Wed Aug 24, 2022 8:15 pm

when you get the address, you get also the subnet mask /xx
pref-src do not have subnet mask and you can not use ip with subnet mask on set
you can not compare two values like ("127.0.0.1" = "127.0.0.1/24")

remove the subnet mask with :pick before use the address as pref-src and before use it on compare
 
danklod
just joined
Topic Author
Posts: 7
Joined: Thu Feb 08, 2018 2:33 pm

Re: Simple script for set pref-source

Thu Aug 25, 2022 10:14 am

Thank you!

I changed it with this, because for first time I use scripts and don't know how to use :pick yet, but I still have problem:

:local langw1 [/ip dhcp-server network get value-name=gateway number=0];
:local perfsrc1 [/ip route get [find dst-address=10.120.0.0/16] pref-src];

:if ($langw1 != $perfsrc1) do={
/ip route set pref-src=$langw1 [find dst-address=10.120.0.0/16];
}


or

:local langw1 [/ip dhcp-server network get value-name=gateway number=0];
:local perfsrc1 [/ip route get [find dst-address=10.120.0.0/16] pref-src];

:if ($perfsrc1 = 0.0.0.0) do={
/ip route set [find dst-address=10.120.0.0/16] pref-src=$langw1;
}


on all routers I have only one dhcp server for LAN network (for example gateway is set 10.0.5.1)

Who is online

Users browsing this forum: totpbi, UkRainUa and 23 guests