dynamic route and dynamic gateway

Hi everyone,

I’ve encountered the following problem and I need your help to find out how to solve it.

I’ve created a VPN between router A and Router B.
and I wanted to tunnel through router A all internet traffic from the clients behind router B.

and it’s working.
the problem is that the IP address of router A is changing each 10 days (by the ISP)
therefore, each 10 days I have to modify manually the routing table of router B.


why ?
because :

  1. on router B there is this routing table:
    0.0.0.0 → through router A vpn IP
    router A vpn IP → through vpn interface
    192.a.b.c → through local interface
    10.a.b.c → through wan interface
    and …
    router A public IP → through 10.0.0.1 ( wan gateway)

  2. router A has the same dns name even after the IP changes each 10 days. (the dns name is updated)

the problem I identified is when the router A public IP changes, the last routing rule in server B fails.

I think that rule is needed because … in order to establish the VPN the first time, router B needs to solve the name of the router A… ( udp dns 53 query sent to local gateway!!!)

If I remove that, before establishing the vpn, there is no default gw, so the router B cannot solve the name of the vpn server(router A IP) because doesnt have a gw where to send the dns query.

If I put default gateway 0.0.0.0 through local gateway, the traffic is no more tunnelled through router A but is using local gateway ( even with different metric configured)

What can I do to solve this ? Is there a way to use the local gw only for dns queries?
What should be the approach?
Thanks in advance !

Haven’t tested this… But maybe you can use a mangle rule to mark DNS packets that originate from the Mikrotik. Then those packets can be sent out a different route.

IP > Firewall, Mangle

Add a mangle rule, chain=output, Protocol: UDP, Dst. Port: 53, Action: mark routing, New Routing Mark: RB_DNS

Then add a route, Dst. Address: 0.0.0.0/0, Gateway: Your wan interface, Routing Mark: RB_DNS, Distance: Same as your other default route

What kind of VPN? Assuming is PTP, Have you tried setting the VPN interface itself as gateway on Router B?

I dont quite understand your idea.
If I use the pppt interface as default gw , where should I configure the real gw ( next hop) ?

I’ll give it a try.
Thanks

The real gateway gets configured in your route list.

There needs to be 2 routes with Dst. Address 0.0.0.0/0
One will have a default gateway of your VPN interface so it’ll try to push all traffic through the VPN.

The second route is the same except you specify RB_DNS as the routing mark, so DNS originating from the Mikrotik routes directly to the internet rather through the VPN. But the DNS packets need to be marked first using a mangle firewall rule.

Add a mangle rule, chain=output, Protocol: UDP, Dst. Port: 53, Action: mark routing, New Routing Mark: RB_DNS

If you are using PPtP os SSTP, you can enter the remote router’s name instead of the ip in the client setup.
So in your case, set up the VPN server on router A, and in router B configured as client, enter router A’s DNS name.
It will promptly reconnect on IP change.