Route ALL NTP traffic over a specific WAN

Hey there! Thank you for linking me to the new documentation. I was looking at the old documentation that just has a bunch of diagrams and I didn’t understand the packet flow from that. The new documentation explains it well.
Your reasoning behind the packet flow log I shared feels right and it also appears to be working just fine.



And thank you to everyone else for suggesting alternate solutions but I don’t really want to implement those. Even though I now announce router’s IP as a NTP server to all the connected clients, The clients still use time.windows.com, time.cloudflare.com, time.google.com, the pool.ntp.org service and apple probably uses their own thing. All this means, There are quite a few different IPs that are being contacted for NTP queries and tracking it down and adding routing entries for all those IPs will take a lot of time and that is if I am able to figure out all the addresses. All my network equipment(APs, Switches etc) are obeying/using the NTP server announced via DHCP but most client devices just seem to ignore it.


At the end, These are the rules I have added to make this work.


/ip/firewall/mangle
chain=output action=mark-routing connection-mark=no-mark new-routing-mark=lte-failover passthrough=no protocol=udp out-interface-list=WAN dst-port=123 log=no 
   chain=prerouting action=mark-routing connection-mark=no-mark new-routing-mark=lte-failover passthrough=no protocol=udp dst-address-list=!not_in_internet in-interface-list=LAN dst-port=123 log=no

The rule in output chain redirects/forces udp/123 traffic that originated on the router via lte interface. The logs look a bit weird, (logged via log rule in filter table)

output: in:(unknown 0) out:pppoe-bsnl, proto UDP, <ip-on-wan-to-avoid-interface>:123->216.239.35.8:123, NAT (<ip-on-wan-to-avoid-interface>:123-> <ip-on-lte-interface>:123)->216.239.35.8:123, len 76

but it works fine.

The second rule takes care of traffic that originated from client devices.

Why would use mangle.
My impression from the above discussion is that one can just create a route for that as sindy indicated.

add distance=1 dst-address=3.3.3.3. gateway=Selected WAN gateway (for dns traffic) (assuming 3.3.3.3 is the NTP servers all the PCs are pointing too).

Did you know mangle negates faster traffic and takes up CPU cycles, or is the aim to be inefficient??

@ishanjain clearly stated that he doesn’t control which NTP servers are used by clients. The only clear way of determining that a packet should be routed via alternative path is thus matching against certain properties (protocol=udp and dst-port=123) for packets about to leave router through either of WAN ports. The known bits of information are not enough for straight use of specific route, hence use of mangle (which is more flexible).

for obtain the list of all IPs used as NTP server

(NTP is one of the protocol than for be full compliant want also the src port 123)

added automation method
https://forum.mikrotik.com/viewtopic.php?f=2&t=178602&p=880497#p880497

AFAIK neither src-port nor dst-port have to be exactly 123.

There are two kinds of NTP applications:

  1. applications running as service/daemon and usually work as clients (to lower stratum servers) as well as servers (to higher stratum clients).
    These customary use port 123 for both src and dst.
  2. applications running as client only and mostly implement SNTP. These can run as non-privileged process and thus use ports with numbers higher than 1023. In this case src-port for packets originating from clients will be different than 123.

It is really unusual to see NTP server running on port other than 123, so dst-port will normally be 123 indeed.

Putting all togheter:

Paste this on terminal (after set the right gateway address)

/ip route
add distance=1 gateway=<put-lte-gateway-IP-address-here> routing-mark=ntp
/ip firewall raw
add action=add-dst-to-address-list address-list=ntp_pool address-list-timeout=none-dynamic chain=prerouting dst-address-list=!ntp_pool dst-port=123 protocol=udp src-port=123
add action=add-dst-to-address-list address-list=ntp_pool address-list-timeout=none-dynamic chain=output dst-address-list=!ntp_pool dst-port=123 protocol=udp src-port=123

Just schedule or launch manually:

/ip firewall address-list
:foreach item in=[find where list="ntp_pool"] do={
    :local ntpip [get $item address]
    /ip route rule
    :if ([:len [find where dst-address="$ntpip/32" and table="ntp"]] = 0) do={
        add dst-address="$ntpip/32" table="ntp"
    }
}

One drawback of using IP address list instead of mangling NTP traffic is that all traffic towards those targets will use alternative WAN, non-NTP traffic as well. Some NTP servers share their IP addresses with other services (the most famous NTP servers don’t).
Plus, if I understand the latest concept, there will be some delay between clients first trying to access NTP server and first success (IIRC OP mentioned that the preferred ISP blocks NTP traffic) because of delayed running the script which populates the routing table.

Hi rextended, mkx, anav and everyone else who responded.

The approach to add all the routes to a ntp table will also work but it does have the downside that I am likely sending non-ntp traffic over LTE as well(which is slow and expensive) and it doesn’t have an instantaneous effect as mkx said. This’ll probably subside over time as a good chunk of NTP servers are added to the list but I don’t really want to do this.


For now, I will continue to use the firewall mangle rules. The script may help others(and maybe even myself if I notice problems in future with these mangle rules I have added) if they want to try something similar.

And Performance is not the biggest concern right now since the router I have(rb450gx4) is quite overpowered to begin with for my use case. For the longest time I was just running two bridges on it and didn’t knew that wasn’t the right way to do it. I recently switched it a proper bridge vlan filtering setup but for some reason, The bridge interface still aren’t hardware accelerated like they should be. Anyway, I’ll try to create another thread if this bugs me too much. For now, Even with all these issues, It works fine.

Thank you so much for your responses, I really appreciate it. :smiley:

None of RB devices (your IPQ4019-based RB450Gx4 is not excluded) can HW offload bridge vlan-filtering in ROS v6. In ROSv7 things might change (RB4011 was mentioned, but uses completely different SoC). If you want VLAN operations done by switch chip, you have to configure things under /interface ethernet switch.

Yes, I also just found this thread. http://forum.mikrotik.com/t/vlan-bridge-new-way-hw-offload-and-performance/132317/1

So, Looks like hw offloaded inter-vlan routing is not possible with my mikrotik board.

HW offloaded routing (inter LAN or inter-VLAN, doesn’t matter) is being in development (ROS v7.1) and only for CRS3xx models.

HW offloaded switching/bridging is to certain extent possible on all devices with switch chip, the way it should be configured varies between device models.