Categories: MikroTik

Mikrotik RouterOS – Conditional DNS-forward

One of the big pains of having a complete network of L2TP/IPSec-devices is that you have to have DNS servers at each site, or run a central DNS-server which could be slow to reach and the users start complaining about slow internet.
This is a simple config-script to allow you to run your central DNS only on internal domains, and everything else on.. well, any DNS you want.

Notes:
The script creates a new pre-routing connection-mark, checking if the DNS-lookup on the router, port 53 is looking for something with “yourdomain.local”. When it is, it DST-NATs and forwards the packet to your internal DNS without doing anymore processing.

It assumes you use the router/gateway as DNS-server with remote requests enabled in DNS-setup.

# The domain you want to be able to look up
:global DOMAIN
yourdomain.local  

# This is needed because the script won't allow a variable and a dash.. so no "$DOMAIN-forward"
:global CONMARK yourdomain.local-forward

# The LAN ip of your router
:global ROUTER 192.168.0.1

# The DNS-server where you look up "yourdomain.local"
:global DNSSERVER
1.1.1.10

 

/ip firewall layer7-protocol add name=$DOMAIN regexp=$DOMAIN
/ip firewall mangle add chain=prerouting dst-address=$ROUTER layer7-protocol=$DOMAIN action=mark-connection new-connection-mark=$CONMARK protocol=tcp dst-port=53
/ip firewall mangle add chain=prerouting dst-address=$ROUTER
layer7-protocol=$DOMAIN action=mark-connection new-connection-mark=$CONMARK protocol=udp dst-port=53
/ip firewall nat add action=dst-nat chain=dstnat
connection-mark=$CONMARK to-addresses=$DNSSERVER
/ip firewall nat add
action=masquerade chain=srcnat connection-mark=$CONMARK

 

http://blog.degree.no/2013/10/mikrotik-routeros-conditional-dns-forward/

admin

Recent Posts

vCenter Converter Standalone 9 download

vCenter Converter Standalone 9.0.0 download (далее…)

2 месяца ago

Download Service Pack for ProLiant (SPP) 2026.03 Gen10 and 10 Plus torrent

Service pack for HPE ProLiant Gen10 and 10 Plus (ver 2026.03.00.00) (SPP2026030000.2026_0326.14.iso) Service Pack for…

3 месяца ago

Download Service Pack for ProLiant (SPP) 2026.01 Gen10 and 10 Plus torrent

Service pack for HPE ProLiant Gen10 and 10 Plus (ver 2026.01.00.00) (SPP2026010000.2026_0206.13.iso) Service Pack for…

4 месяца ago

Wireguard on Mikrotik RouterOS 7

# add wg interface /interface/wireguard/add listen-port=51820 mtu=1300 # add ip on wg interface /ip/address/add address=10.100.10.1…

6 месяцев ago

VMware remote console (VMRC) 13 download

VMware remote console (VMRC) 13.0.1 download Last version: VMware Remote Console 13.0.1 | 29 Sept…

7 месяцев ago

Download Service Pack for ProLiant (SPP) 2025.01 Gen10 torrent

Gen10 Service Pack for ProLiant (SPP) Version 2025.01 Service Pack for ProLiant 2025.01 Gen10(P81139_001_gen10spp-2025.01.00.00-SPP2025010000.2025_0119.14.iso 8.22…

1 год ago