Inorder to use ROS’ DNS cache feature, All my devices are using ROS as their DNS server .
And I am living in China, our DNS service has been poisoned.
Inorder to visit some website such as facebook, I need to force ROS to request DNS service through a VPN gateway.
I’ve tried several ways,but it doesn’t work.
Anyboy know how to do this?
/ip firewall nat add action=dst-nat chain=dstnat dst-port=53 protocol=udp to-addresses=YOUR VPN DNS IP to-ports=53
/ip firewall nat add action=dst-nat chain=dstnat dst-port=53 protocol=tcp to-addresses=YOUR VPN DNS IP to-ports=53
don’t forget reboot your router after this configurations , also you can remove all connection from firewall connection tracking and let them to established again
You could create static routes to the actual DNS servers’ IP addresses.
For example, suppose you’re using DNS server 8.8.8.8 and the VPN server’s address (inside-tunnel address) is 10.20.30.40-
Create a static route dst=8.8.8.8/32 gateway=10.20.30.40
This will force DNS traffic to cross the VPN.
If you’re doing policy routing, then you’ll need to make sure that this route applies to whatever policy matches the output chain of the mangle table.
How do you figure that?
If you set a route to 8.8.8.8 which goes through the VPN, then that’s going to make the Mikrotik’s own queries to 8.8.8.8 be directed through the VPN.
The behavior you state (dhcp assigns 8.8.8.8 directly works, while proxied via Mikrotik doesn’t work) is expected for your configuration.
You’re using policy routing to govern the choice of gateways.
Flow THROUGH the router is affected by your policy, but traffic FROM the router (i.e. the proxied DNS request) is not following the policy… this is because the second type of traffic doesn’t flow through the same chains in the mangle table. (it uses different chains in the filter table, too)
This won’t match packets from the Mikrotik itself, which is passed to the Output chain, not the Prerouting chain.
Mangle prerouting matches packets as they ingress the router through some interface - i.e. from outside the router only.
So to fix your problem, duplicate the prerouting mangle rule (the one I quoted) into the “output” chain of the mangle table and you should get what you want.
Or do it the easy way (what I stated in my previous response):
/ip route add distance=1 dst=8.8.8.8/32 gateway=pptp-out1
/ip route add distance=1 dst=8.8.4.4/32 gateway=pptp-out1
(i.e. ALWAYS route that way, don’t worry about mangle)
You could have done this entire solution using only static routes because you don’t need to use policy routing when the only decision in the policy is based on the destination address - that’s how routing works already…
Simply set default GW to be pptp interface, set /32 route to pptp server via normal gateway interface, set static routes to all Chinese IPs via normal gateway. This method will perform faster than using the mangle table performs, by the way.
Perhaps you didn’t want hundreds of routes in your routing table.
When you put the policy routing statements also into the output chain, did you clear DNS cache before re-testing? (On both the mikrotik and the computer)