Cannot reach HTTP port of public address in certain vlans

Hello, I have a public domain that points to my public ip and NAT port forwarding for the ports 80 and 443 on my RB5009. Then I've got a reverse proxy that takes every HTTP request and proxy it to the correct web service in my network.

The web services are in the 10.1.5.X lxc vlan (35) and I'm able to reach the web server (using my domain) at 10.1.5.2 without problems from the 10.1.2.X trusted vlan (20).
If I try to reach it from another vlan like the 10.1.6.X iot vlan (60) I don't get any response.

What could be the issue?
Maybe because traffic from 10.1.6.X to 10.1.5.X is forbidden?
(but I thought that traffic should go outside and back inside my network again avoiding the direct destination)

My Firewall + NAT rules
/ip firewall filter
add action=accept chain=input comment="allow everything from emergency management port" in-interface="ether8 (mngt)"
add action=drop chain=input comment="drop <invalid> packets" connection-state=invalid log-prefix=invalid
add action=accept chain=input comment="accept <established>, <related> and <untracked> connections" connection-state=established,related,untracked
add action=accept chain=input comment="allow icmp (ping) from WAN" in-interface-list=WAN protocol=icmp
add action=accept chain=input comment="allow incoming wireguard traffic" dst-port=10999 in-interface-list=WAN log=yes log-prefix=VPN protocol=udp
add action=accept chain=input comment="allow mdns traffic" dst-address=224.0.0.251 dst-port=5353 in-interface-list=mdns-repeater protocol=udp src-port=5353
add action=drop chain=input comment="drop everything else from WAN" in-interface-list=WAN
add action=drop chain=forward comment="drop <invalid> packets" connection-state=invalid
add action=drop chain=forward comment="drop NAT overtake (from WAN to LAN w/o NAT)" connection-nat-state=!dstnat connection-state=new in-interface-list=WAN log=yes log-prefix=!NAT
add action=fasttrack-connection chain=forward comment="fast-track <established> and <related> connections" connection-state=established,related hw-offload=yes in-interface-list=\
    !fasttrack-blacklist out-interface-list=!fasttrack-blacklist
add action=accept chain=forward comment="accept <established>, <related> and <untracked> connections" connection-state=established,related,untracked
add action=accept chain=forward comment="allow dns requests to pi-hole (TCP:53)" dst-address=10.1.5.1 dst-port=53 in-interface-list=VLANS protocol=tcp
add action=accept chain=forward comment="allow dns requests to pi-hole (UDP:53)" dst-address=10.1.5.1 dst-port=53 in-interface-list=VLANS protocol=udp
add action=accept chain=forward comment="allow traffic from <VPN> to <safe-vlans>" in-interface-list=VPN log=yes log-prefix=VPN out-interface-list=safe-vlans
add action=accept chain=forward comment="allow from <(V60) IoT> to <HASS VM>" dst-address=10.1.4.3 in-interface="(V60) IoT"
add action=accept chain=forward comment="allow from <HASS VM> to <(V60) IoT>" out-interface="(V60) IoT" src-address=10.1.4.3
add action=accept chain=forward comment="allow <HASS VM> to <safe-vlans>" log-prefix="HASS VM" out-interface-list=safe-vlans src-address=10.1.4.3
add action=accept chain=forward comment="allow from <safe-vlans> to <(V60) IoT>" in-interface-list=safe-vlans out-interface="(V60) IoT"
add action=accept chain=forward comment="allow <Sync LXC> to <safe-vlans>" log-prefix="Sync LXC" out-interface-list=safe-vlans src-address=10.1.5.4
add action=accept chain=forward comment="allow <(V34) Homelab -> VMs> to <(V20) Trusted>" in-interface="(V34) Homelab -> Virtual Machines" out-interface="(V20) Trusted"
add action=accept chain=forward comment="allow from <(V20) Trusted> to <services-vlans>" in-interface="(V20) Trusted" out-interface-list=services-vlans
add action=accept chain=forward comment="allow from <(V10) Infrastructure> to \"safe\" vlans" disabled=yes in-interface="(V10) Infrastructure" out-interface-list=safe-vlans
add action=accept chain=forward comment="allow from <(V20) Trusted> to <(V10) Infrastructure>" in-interface="(V20) Trusted" log-prefix=Infrastructure out-interface="(V10) Infrastructure"
add action=accept chain=forward comment="allow between <service-vlans>" in-interface-list=services-vlans out-interface-list=services-vlans
add action=drop chain=forward comment="drop cross-vlan traffic" in-interface-list=VLANS log-prefix="X-VLAN (drop)" out-interface-list=VLANS
add action=drop chain=forward comment="drop traffic to <VPN>" log=yes log-prefix="VPN (drop)" out-interface-list=VPN
/ip firewall nat
add action=masquerade chain=srcnat comment="WAN (Internet)" out-interface-list=WAN
add action=masquerade chain=srcnat comment="ISP ONT management from <network-mngt>" dst-address-list=isp-gateway in-interface-list=network-mngt out-interface="ether1 (ont) [2.5G]"
add action=dst-nat chain=dstnat comment="PF: Caddy HTTP" dst-address-list=public-ip dst-port=80 protocol=tcp to-addresses=10.1.5.2 to-ports=80
add action=dst-nat chain=dstnat comment="PF: Caddy HTTPS" dst-address-list=public-ip dst-port=443 protocol=tcp to-addresses=10.1.5.2 to-ports=443

You posted a firewall export with extensive uses of interface lists and address lists, but did not post those lists. We don't have crystal balls.

Anyway, if your firewalls rules have this effect:

Then yes, you won't be able to access the DSTNATed resource from 10.1.6.X. There is no "go outside and back inside your network". See this flow chart:

The ultimate Mikrotik iptables flowchart - RouterOS / Useful user articles - MikroTik community forum

DSTNAT (#10) happens before the rules in the filter table chain forward (#14). Between those steps the packets don't leave the interfaces. At step #14, the destination address (dst-address) and destination interface (out-interface) have already been changed to 10.1.5.2 and (V35 LXC), and if your filter rules don't allow forwarding from the in-interface/src-address to that out-interface/dst-address, then the packets will not go through.

That's a reason why the standard defconf firewall, although it has a drop all from WAN rule, that rule has a special exception for connections that have been DSTNATed. This is the default defconf rule:

/ip firewall filter
add chain=forward action=drop connection-state=new connection-nat-state=!dstnat \
    in-interface-list=WAN comment="defconf: drop all from WAN not DSTNATed"

What @CGGXANNX writes regarding the firewall is true. What he writes about always providing the address lists and interface lists together with firewall rules is doubly so - without them they are impossible to make sense of.

dst-nat changes (only) the destination address, therefore for your forward rules the packet is travelling 10.1.6.X -> 10.1.5.2.

Just an aside, in logs you'll see it as: 10.1.6.X -> (public-ip->10.1.5.2), thus highlighting the dst-nat action.

Luckily, the firewall has just the feature for you. When you dst-nat, you generally want to selectively allow whatever connection you've dst-natted. This can be accomplished by the filter rule:
add chain=forward action=accept connection-nat-state=dstnat

Generally a good place to put this is right after the established/related rule.

EDIT: Again, @CGGXANNX's edit is correct. In the default ruleset this is done by an exception to the (only) drop rule. If you have a more complex ruleset, I find it better not to not drop it (add it as an exception to every drop rule), but instead to allow it explicitly.

Sorry guys, my bad.

Here are my interface lists and address lists
/interface list
add name=WAN
add name=LAN
add name=unsafe-vlans
add name=services-vlans
add name=VPN
add comment="mDNS Repeater Interfaces (populated automatically)" name=mdns-repeater
add comment="exclude interfaces from fast track rule" name=fasttrack-blacklist
add comment="extends: services-vlans" include=services-vlans name=safe-vlans
add comment="extends: safe-vlans" include=safe-vlans name=ros-management
add include=ros-management,VPN name=network-mngt
add comment="extends: safe-vlans, services-vlans, unsafe-vlans" include=safe-vlans,services-vlans,unsafe-vlans name=VLANS

/interface list member
add interface=main-bridge list=LAN
add interface=pppoe-wan list=WAN
add interface="(V10) Infrastructure" list=safe-vlans
add interface="(V20) Trusted" list=safe-vlans
add interface="(V60) IoT" list=unsafe-vlans
add interface="(V70) Guests" list=unsafe-vlans
add interface="(V30) Homelab" list=services-vlans
add interface="(V34) Homelab -> Virtual Machines" list=services-vlans
add interface="(V35) Homelab -> LXC Containers" list=services-vlans
add interface=wireguard list=VPN
add interface="ether8 (mngt)" list=ros-management
add interface="(V70) Guests" list=fasttrack-blacklist
add interface="(V10) Infrastructure" list=network-mngt
add interface="(V20) Trusted" list=network-mngt
add interface="(V10) Infrastructure" list=mdns-repeater
add interface="(V20) Trusted" list=mdns-repeater
add interface="(V34) Homelab -> Virtual Machines" list=mdns-repeater
add interface="(V35) Homelab -> LXC Containers" list=mdns-repeater
add interface="(V60) IoT" list=mdns-repeater

/ip firewall address-list
add address=example.mydomain.com list=public-ip
add address=192.168.1.1 list=isp-gateway

I already have that rule, but it is not working. @lurker888 said that it should go right after the established/related rule, could be that the reason?

Also, I have logging enabled on that rule but do not see any traffic going through it.

Noooo! There are two choices, not both or a combination:

  1. I wrote an accept rule, which in fact should go where I said, and you understood correctly. This will solve your problem.
  2. You have several drop rules. If you add the connection-nat-state=!dstnat matcher to all of them, that will also solve your problem.

Oh ok, now it's clear.

I think the first is the most versatile option because then I don't have to edit all of my forwar chain drop rules, right?

So, I should remove my existing rule (like the one in the defconf) and replace it with that method?

Sorry, but again: not exactly.

Obviously I agree that the "add one rule" method is simpler (that's why I suggested it). Both would work correctly.

By add one rule, I mean add one rule. Don't delete existing ones, modify existing ones, or put your cat in the microwave. Add the one rule. In the suggested place.

Thank you, so

  • (V35) Homelab -> LXC Containers is in services-lan and mdns-repeater, which means it's also in VLANS, safe-vlans, ros-management, and network-mngt.
  • (V60) IoT is in unsafe-vlans and mdns-repeater, which means it's also part of the VLANS list.

Looking at the filter forward rules, there's an explicit accept rule permitting from VLAN 35 to VLAN 60 (allow from <safe-vlans> to <(V60) IoT>), but no accept rule for the other direction (if we don't count the connection-state=established... rules). And there is the explicit drop rule "drop cross-vlan traffic" rule that blocks between the members of the VLANS list, this is where the packets from VLAN 60 to VLAN 35 are dropped.

The solution is as @lurker888 has posted above:

  • Either you add a

    /ip firewall filter
    add action=accept chain=forward comment="allow dstnat to services" \
        out-interface-list=services-vlans connection-nat-state=dstnat
    

    rule and move it above the "drop cross-vlan traffic" rule.

  • Or you modify the "drop cross-vlan traffic" rule and add connection-nat-state=!dstnat as additional condition.

I agree with @lurker888, in this case the first solution with accept is better because you can have additional restrictions such as out-interface-list=services-vlans.

Thank you both for your answers :slight_smile:

Now it's working.