/tool fetch via specific interface?

On my router I have two WANs (first is the default one, and the second will take over when first one is dead), and I need to do fetch of a given URL from the IP of second WAN port. The problem is, the IP of server I will fetch url from can change (CDN, actually) so I can’t just route/mangle traffic to it from second WAN statically.

At the same time I found no way to specify outgoing interface for

/tool fetch

so the scheme fails.

How can I do that trick?

on script, you can disable interface WAN default, before run fetch and enable it after that. Better with delay.

I faced same problem, searching for solution.

I think this can be done by adding a static route to site you like to fetch to the second wan interface.

sorry for write an old post, but i have a similar problem…

i have a mikrotik 4011 with 2 isp
ether1 to ISP1
ether2 to ISP2

ether2 have a dynamic ip and i want configure with ovh dynhost.
on old pfsense i set simple cronjob
curl --interface igb0 --user “:” “http://www.ovh.com/nic/update?system=dyndns&hostname=<myhostname>”
and worked perfectly

now i change old pfsense with GREAT Mikrotik :slight_smile:
but how can i replicate that?

in fetch i can’t use --interface or similar
so i think to create an address list with domain www.ovh.com
and create a specific route to that address list (my opinion is not clear force a route with actual ip of www.ovh.com because ovh can change your ip)

how can i solve problem?

thank you

An easy approach is to resolve the address each time it tries to update, add the address to an address list with a timeout and use a prefixed mangle and routing mark to route traffic via the proper interface.

For example :

local currentIp [:resolve www.ovh.com]
/ip firewall address-list add list=dyndns address=$currentIp timeout=20s
/tool fetch url=XXX

You can then keep a static set of rules to mangle and route the traffic

/ip firewall mangle add chain=prerouting protocol=tcp dst-port=80,443 dst-address-list=dyndns action=mark-routing new-routing-mark=via_wan2
/ip route add dst-address=0.0.0.0/0 gateway=x.x.x.x routing-mark=via_wan2

If your eth2 gateway changes you need to put an on-lease script in the dhcp-client for eth2 to fix the gateway. Somthing like

script="/ip route set gateway=$gateway [find routing-mark=\"via_wan2\""

You better check if the default variable for the gateway is actually $gateway in the documentation.


edit:

BTW, ping, ssh, telnet (although its broken post 6.45.6 or so) support the routing-table parameter to route traffic.
I’ve already requested they add it to tool fetch without much success, maybe more people requesting would put it on the road map.