How to update WireGuard peer endpoint address using DNS on MikroTik RouterOS

Assuming your peer comment is peer1 and the correct endpoint DNS record is, you can use this RouterOS script to update the endpoint based on the DNS record:

:if ([interface wireguard peers get number=[find comment=peer1] value-name=endpoint-address] != [resolve]) do={interface wireguard peers set number=[find comment=peer1] endpoint-address=[/resolve]}

Related posts which might make that easier to understand: