I’ve been testing “mangling loopback” (known workaround for dstnat not available in output chain + no cDNS + no non-standard winbox port in Dude in ROS v6) configuration on a metarouter (as I wanted a config as generic as possible). Metarouter is running on RB2011, ROS 6.44.3.
The config is a typical implementation of conditional DNS for v6:
- a bridge to bind extra loopback address to (bridge-loopback, 127.0.0.2);
- two IPIP tunnels looking at each other (ip2t-loopback-out and ip2t-loopback-in);
- routes to these tunnels - one with routing mark (rm-loopback), another with fake address (10.53.0.0/16);
- L7 pattern (l7-mr1 with ‘mr1.test’ content) and mangling rule to mark specific DNS requests with said routing mark (log-prefix=mangle1);
- three NAT rules:
- replacing our address with fake one (log-prefix=mangle2);
- replacing destination address with required one (log-prefix=mangle3);
- masquerading fake address (log-prefix=mangle4);
plus some logging rules in filter:
/interface bridge
add name=bridge-loopback protocol-mode=none
/interface ethernet
set [ find ] name=ether-intra
set [ find ] name=ether-mgmt
/interface ipip
add local-address=127.0.0.2 name=ip2t-loopback-in remote-address=127.0.0.1
add local-address=127.0.0.1 name=ip2t-loopback-out remote-address=127.0.0.2
/ip firewall layer7-protocol
add name=l7-mr1 regexp=mr1.test
/ip settings
set rp-filter=loose
/ip address
add address=192.168.10.30/24 interface=ether-intra network=192.168.10.0
add address=127.0.0.2 interface=bridge-loopback network=127.0.0.2
/ip dhcp-client
add default-route-distance=100 dhcp-options=hostname,clientid disabled=no \
interface=ether-mgmt
/ip firewall filter
add action=log chain=forward log=yes log-prefix=packet
add action=log chain=input in-interface=!ether-mgmt log=yes log-prefix=packet \
protocol=!ipencap
add action=log chain=output log=yes log-prefix=packet out-interface=\
!ether-mgmt protocol=!ipencap
/ip firewall mangle
add action=mark-routing chain=output dst-port=53 layer7-protocol=l7-mr1 log=\
yes log-prefix=mangle1 new-routing-mark=rm-loopback protocol=udp
/ip firewall nat
add action=src-nat chain=srcnat dst-port=53 log=yes log-prefix=mangle2 \
out-interface=ip2t-loopback-out protocol=udp to-addresses=10.53.0.1
add action=dst-nat chain=dstnat dst-port=53 in-interface=ip2t-loopback-in \
log=yes log-prefix=mangle3 protocol=udp to-addresses=192.168.10.20
add action=masquerade chain=srcnat dst-port=53 log=yes log-prefix=mangle4 \
out-interface=ether-intra protocol=udp src-address=10.53.0.0/16
/ip route
add distance=1 gateway=ip2t-loopback-out routing-mark=rm-loopback
add distance=1 dst-address=10.53.0.0/16 gateway=ip2t-loopback-in
The environment is a:
- intranet between two metarouters (ether-intra), with another metarouter at 192.168.10.20 with external DNS queries enabled and a static entry mr1.test;
- management network (ether-mgmt) to keep intranet clean. It has a DHCP server with DNS option enabled, so DNS requests without cDNS would go there (to 192.168.20.1).
When put [resolve mr1.test] is invoked in console (AFAIK it’s the only way to nslookup on Mikrotik), the request goes to 192.168.10.20 which replies with it’s own address.
But if RP Filer is set to loose, the reply seems to get dropped before reaching input chain:
[admin@mr2] > put [resolve mr1.test]
failure: dns server failure
Log:
05:38:41 firewall,info mangle1 output: in:(unknown 0) out:ether-mgmt, proto UDP, 192.168.20.253:50883->192.168.20.1:53, len 54
05:38:41 firewall,info mangle2 srcnat: in:(unknown 0) out:ip2t-loopback-out, proto UDP, 192.168.20.253:50883->192.168.20.1:53, len 54
05:38:41 firewall,info mangle3 dstnat: in:ip2t-loopback-in out:(unknown 0), proto UDP, 10.53.0.1:50883->192.168.20.1:53, len 54
05:38:41 firewall,info packet forward: in:ip2t-loopback-in out:ether-intra, proto UDP, 10.53.0.1:50883->192.168.10.20:53, NAT 10.53.0.1:50883->(192.168.20.1:53->192.168.10.20:53), len 54
05:38:41 firewall,info packet forward: in:ip2t-loopback-in out:ether-intra, proto UDP, 10.53.0.1:50883->192.168.10.20:53, NAT 10.53.0.1:50883->(192.168.20.1:53->192.168.10.20:53), len 54
05:38:41 firewall,info mangle4 srcnat: in:(unknown 0) out:ether-intra, proto UDP, 10.53.0.1:50883->192.168.10.20:53, NAT 10.53.0.1:50883->(192.168.20.1:53->192.168.10.20:53), len 54
05:38:41 firewall,info packet forward: in:ether-intra out:ip2t-loopback-in, src-mac 02:bf:11:38:5d:c0, proto UDP, 192.168.10.20:53->10.53.0.1:50883, NAT (192.168.10.20:53->192.168.20.1:53)->(192.168.10.30:50883->10.53.0.1:50883), len 70
05:38:41 firewall,info packet forward: in:ether-intra out:ip2t-loopback-in, src-mac 02:bf:11:38:5d:c0, proto UDP, 192.168.10.20:53->10.53.0.1:50883, NAT (192.168.10.20:53->192.168.20.1:53)->(192.168.10.30:50883->10.53.0.1:50883), len 70
(there are several retries of course)
When RP Filer is set to no, the setup works correctly:
[admin@mr2] > put [resolve mr1.test]
192.168.10.20
Log:
05:38:56 system,info config changed by admin
05:39:00 firewall,info mangle1 output: in:(unknown 0) out:ether-mgmt, proto UDP, 192.168.20.253:60136->192.168.20.1:53, len 54
05:39:00 firewall,info mangle2 srcnat: in:(unknown 0) out:ip2t-loopback-out, proto UDP, 192.168.20.253:60136->192.168.20.1:53, len 54
05:39:00 firewall,info mangle3 dstnat: in:ip2t-loopback-in out:(unknown 0), proto UDP, 10.53.0.1:60136->192.168.20.1:53, len 54
05:39:00 firewall,info packet forward: in:ip2t-loopback-in out:ether-intra, proto UDP, 10.53.0.1:60136->192.168.10.20:53, NAT 10.53.0.1:60136->(192.168.20.1:53->192.168.10.20:53), len 54
05:39:00 firewall,info packet forward: in:ip2t-loopback-in out:ether-intra, proto UDP, 10.53.0.1:60136->192.168.10.20:53, NAT 10.53.0.1:60136->(192.168.20.1:53->192.168.10.20:53), len 54
05:39:00 firewall,info mangle4 srcnat: in:(unknown 0) out:ether-intra, proto UDP, 10.53.0.1:60136->192.168.10.20:53, NAT 10.53.0.1:60136->(192.168.20.1:53->192.168.10.20:53), len 54
05:39:00 firewall,info packet forward: in:ether-intra out:ip2t-loopback-in, src-mac 02:bf:11:38:5d:c0, proto UDP, 192.168.10.20:53->10.53.0.1:60136, NAT (192.168.10.20:53->192.168.20.1:53)->(192.168.10.30:60136->10.53.0.1:60136), len 70
05:39:00 firewall,info packet forward: in:ether-intra out:ip2t-loopback-in, src-mac 02:bf:11:38:5d:c0, proto UDP, 192.168.10.20:53->10.53.0.1:60136, NAT (192.168.10.20:53->192.168.20.1:53)->(192.168.10.30:60136->10.53.0.1:60136), len 70
05:39:00 firewall,info packet input: in:ip2t-loopback-out out:(unknown 0), proto UDP, 192.168.20.1:53->192.168.20.253:60136, NAT 192.168.20.1:53->(10.53.0.1:60136->192.168.20.253:60136), len 70
05:39:00 firewall,info packet input: in:ip2t-loopback-out out:(unknown 0), proto UDP, 192.168.20.1:53->192.168.20.253:60136, NAT 192.168.20.1:53->(10.53.0.1:60136->192.168.20.253:60136), len 70
Note two last lines - the reply packet reaches input chain. These lines are absent when RP filer is set to loose.
The routing table includes routes to all the addresses used:
[admin@mr2] > ip route print detail
Flags: X - disabled, A - active, D - dynamic,
C - connect, S - static, r - rip, b - bgp, o - ospf, m - mme,
B - blackhole, U - unreachable, P - prohibit
0 A S dst-address=0.0.0.0/0 gateway=ip2t-loopback-out
gateway-status=ip2t-loopback-out reachable distance=1 scope=30
target-scope=10 routing-mark=rm-loopback
1 ADS dst-address=0.0.0.0/0 gateway=192.168.20.1
gateway-status=192.168.20.1 reachable via ether-mgmt distance=100
scope=30 target-scope=10 vrf-interface=ether-mgmt
2 A S dst-address=10.53.0.0/16 gateway=ip2t-loopback-in
gateway-status=ip2t-loopback-in reachable distance=1 scope=30
target-scope=10
3 ADC dst-address=127.0.0.2/32 pref-src=127.0.0.2 gateway=bridge-loopback
gateway-status=bridge-loopback reachable distance=0 scope=10
4 ADC dst-address=192.168.10.0/24 pref-src=192.168.10.30 gateway=ether-intra
gateway-status=ether-intra reachable distance=0 scope=10
5 ADC dst-address=192.168.20.0/24 pref-src=192.168.20.253 gateway=ether-mgmt
gateway-status=ether-mgmt reachable distance=0 scope=10
So loose RP filter should not cause any dropping of the packets.
Any ideas why RP filter behaves this way?
Note that switching RP filter from no to loose are not causing immediate effects. The setup are starting to fail after approx. 10 minutes of idling(!) after setting RP filter to loose.
Actual full configs of metarouters and slightly redacted config of host RB2011 are attached.
(This study is not educational, I’m actually trying to get “mangling loopback” working on my production routers, to no avail for now.)
mr-host-redacted.rsc (1.63 KB)
mr1.rsc (702 Bytes)
mr2.rsc (2.03 KB)