I live in Thailand and have 4 WAN connections that I can use (all from different providers).
Different WANs have different international connectivity (some have faster links to USA, some to Europe).
Is there any way that when a new connection is established, Mikrotik would choose the uplink WAN based on ping to destination?
i.e. send out a ping through all WANs and decide which uplink to use based on the fastest response?
It would slow down the first connection establishment by a second, but will provide the best speeds in the long run.
Nothing like this is included into RouterOS, but it should not be too complex to implement it using scripting.
You would use one address-list for each of the WANs, and one more for the destinations which need to be evaluated.
Each SYN packet would be marked with a connection-mark corresponding to the WAN on whose address-list its destination address would be found. If its destination address would not be found on any of the four address lists associated with WANs, it would be added to the “evaluate” one and the packet would be dropped.
A script scheduled to run every second would scan through items on the “evaluate” address list and ping them using each WAN to determine the RTT; after identifying the WAN with the shortest response, it would move the address list item from the “evaluate” list to the list associated with that WAN. The re-sent SYN packet from the client would already be connection-marked to use the proper WAN.
BTW, don’t be surprised that it takes more than a second for the page to start loading as it is rare that everything needed to render the page comes from the same remote IP address. A typical web page today refers to units to tens of other servers for pictures, advertisements etc. So after the basic html document is loaded after the second which elapses between adding the address to the “to be tested” list and moving it to the list marking that dst-address for routing via a particular WAN, it takes another second to do the same with all the addresses of the other servers.
Unfortunately, RouterOS does not allow to associate an event to addition of an item to an address-list.
Also, Google in particular uses QUIC instead of TCP to deliver its web contents to Chrome and Mozilla, so the suggestion to handle SYN packets the described way was just an illustrative one, in fact you have to treat all connection-state=new packets in LAN->WAN direction that way.