I am trying to configure Hairpin NAT together with VLAN filtering but with no luck. Previousle without intervlan traffic I had “trusted” address list with all VLAN IP ranges added and it was working fine.
Now I can’t use the same approach because it will bypass intervlan traffic filtering. I’ve been trying to create a new address list and then a rule to allow the traffic from 192.168.10.2, 3, 4 IPs to domain.com:8006 and domainx.com:8007 pointing to external 217.x.x.x address (pppoe) forwarding to 192.168.20.11 and .20, but that didn’t work either. What I am doing wrong?
/interface vlan
add interface=bridge name=vlan10 vlan-id=10
add interface=bridge name=vlan20 vlan-id=20
add interface=bridge name=vlan30 vlan-id=30
add interface=bridge name=vlan40 vlan-id=40
add interface=bridge name=vlan50 vlan-id=50
add interface=bridge name=vlan60 vlan-id=60
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
/ip pool
add name=vlan10 ranges=192.168.10.10-192.168.10.254
add name=vlan20 ranges=192.168.20.30-192.168.20.254
add name=vlan30 ranges=192.168.30.50-192.168.30.254
add name=vlan40 ranges=192.168.40.10-192.168.40.254
add name=vlan50 ranges=192.168.50.10-192.168.50.254
add name=vlan60 ranges=192.168.60.10-192.168.60.254
/ip dhcp-server
add address-pool=vlan60 authoritative=after-2sec-delay interface=vlan60 lease-time=1d name=vlan60
add address-pool=vlan50 authoritative=after-2sec-delay interface=vlan50 lease-time=1d name=vlan50
add address-pool=vlan40 authoritative=after-2sec-delay interface=vlan40 lease-time=1d name=vlan40
add address-pool=vlan30 authoritative=after-2sec-delay interface=vlan30 lease-time=1d name=vlan30
add address-pool=vlan20 authoritative=after-2sec-delay interface=vlan20 lease-time=1d name=vlan20
add address-pool=vlan10 authoritative=after-2sec-delay interface=vlan10 lease-time=1d name=vlan10
/interface bridge port
add bridge=bridge comment=defconf interface=ether2
add bridge=bridge comment=defconf interface=ether3
add bridge=bridge comment=defconf interface=ether4
add bridge=bridge comment=defconf interface=ether5
add bridge=bridge comment=defconf interface=sfp1
/ip firewall connection tracking
set udp-timeout=10s
/interface bridge vlan
add bridge=bridge tagged=ether2,ether3,ether4,ether5,sfp1,bridge vlan-ids=10,20,30,40,50,60
/interface list member
add interface=bridge list=LAN
add interface=ether1 list=WAN
/ip address
add address=172.16.0.1/24 interface=wg-server network=172.16.0.0
add address=192.168.102.2/24 interface=wireguard-client-1 network=192.168.102.0
add address=10.0.1.2/24 interface=wireguard-client-2 network=10.0.1.0
add address=10.159.50.3/24 interface=wireguard-client-3 network=10.159.50.0
add address=217.x.x.x/29 comment=public interface=vlan20 network=217.x.x.x
add address=192.168.10.1/24 interface=vlan10 network=192.168.10.0
add address=192.168.20.1/24 interface=vlan20 network=192.168.20.0
add address=192.168.30.1/24 interface=vlan30 network=192.168.30.0
add address=192.168.40.1/24 interface=vlan40 network=192.168.40.0
add address=192.168.50.1/24 interface=vlan50 network=192.168.50.0
add address=192.168.60.1/24 interface=vlan60 network=192.168.60.0
/ip dhcp-server network
add address=192.168.10.0/24 comment=vlan10 dns-server=192.168.20.15 gateway=192.168.10.1
add address=192.168.20.0/24 comment=vlan20 dns-server=192.168.20.15 gateway=192.168.20.1
add address=192.168.30.0/24 comment=vlan30 dns-server=192.168.20.15 gateway=192.168.30.1
add address=192.168.40.0/24 comment=vlan40 dns-server=192.168.40.1 gateway=192.168.40.1
add address=192.168.50.0/24 comment=vlan50 dns-server=192.168.50.1 gateway=192.168.50.1
add address=192.168.60.0/24 comment=vlan60 dns-server=192.168.60.1 gateway=192.168.60.1
/ip firewall address-list
add address=46.x.x.x list=trusted
add address=46.x.x.x list=trusted
add address=193.x.x.x list=trusted
add address=31.x.x.x list=trusted
add address=46.x.x.x list=trusted
add address=192.168.10.0/24 list=local-vlans
add address=192.168.20.0/24 list=local-vlans
add address=192.168.30.0/24 list=local-vlans
add address=192.168.40.0/24 list=local-vlans
add address=192.168.50.0/24 list=local-vlans
add address=192.168.60.0/24 list=local-vlans
add address=192.168.20.15 list=trusted-local
add address=192.168.30.13 list=trusted-local
add address=192.168.10.2 list=hairpin-access
add address=192.168.10.3 list=hairpin-access
add address=192.168.10.4 list=hairpin-access
add address=192.168.13.15 list=hairpin-access
/ip firewall filter
add action=accept chain=input comment="allow Wireguard server" dst-port=13231protocol=udp
add action=accept chain=input comment="allow Wireguard server traffic" src-address=172.16.0.0/24
add action=accept chain=input comment="allow traffic from Wireguard vpn" dst-port=8443 protocol=udp
add action=fasttrack-connection chain=forward comment=fasttrack connection-state=established,related hw-offload=yes
add action=accept chain=forward comment="accept established,related" connection-state=established,related
add action=accept chain=input comment="echo reply" protocol=icmp
add action=accept chain=input comment="accept established,related" connection-state=established,related,untracked
add action=drop chain=input comment="drop all not coming from LAN" disabled=yes in-interface-list=!LAN
add action=accept chain=forward comment="allow selected local resources to all VLANs" dst-address-list=local-vlans src-address-list=trusted-local
add action=accept chain=forward comment="allow all VLANs to selected local resources" dst-address-list=trusted-local src-address-list=local-vlans
add action=accept chain=forward comment="allow all traffic from VLAN10 to VLAN20" in-interface=vlan10 out-interface=vlan20
add action=accept chain=forward comment="allow all traffic from VLAN20 to VLAN10" in-interface=vlan20 out-interface=vlan10
add action=accept chain=forward comment="accept IN ipsec policy" ipsec-policy=in,ipsec
add action=accept chain=forward comment="accept OUT ipsec policy" ipsec-policy=out,ipsec
add action=drop chain=forward comment="drop interVLAN traffic" connection-state="" dst-address-list=local-vlans src-address-list=local-vlans
add action=drop chain=forward comment="drop invalid - forward" connection-state=invalid
add action=drop chain=forward comment="Drop all from WAN not DSTNATed" connection-nat-state=!dstnat connection-state=new in-interface=pppoe-out1
add action=drop chain=input comment="drop invalid - input" connection-state="" in-interface=pppoe-out1
/ip firewall nat
add action=masquerade chain=srcnat comment="vlan10 masquerade" out-interface=pppoe-out1 src-address=192.168.10.0/24
add action=masquerade chain=srcnat comment="vlan20 masquerade" out-interface=pppoe-out1 src-address=192.168.20.0/24
add action=masquerade chain=srcnat comment="vlan30 masquerade" out-interface=pppoe-out1 src-address=192.168.30.0/24
add action=masquerade chain=srcnat comment="vlan40 masquerade" out-interface=pppoe-out1 src-address=192.168.40.0/24
add action=masquerade chain=srcnat comment="vlan50 masquerade" out-interface=pppoe-out1 src-address=192.168.50.0/24
add action=masquerade chain=srcnat comment="vlan60 masquerade" out-interface=pppoe-out1 src-address=192.168.60.0/24
add action=dst-nat chain=dstnat comment="Forward port 65000 to 192.168.20.4" disabled=yes dst-address=217.x.x.x dst-port=65000 protocol=tcp src-address-list=trusted to-addresses=192.168.20.4 to-ports=65000
add action=masquerade chain=srcnat comment="wg-server masquerade" out-interface=pppoe-out1 src-address=172.16.0.0/24
add action=masquerade chain=srcnat comment="wireguard client 1 masquerade" out-interface=wireguard-client-1
add action=masquerade chain=srcnat comment="wireguard client 3 masquerade" out-interface=wireguard-client-3
add action=masquerade chain=srcnat comment="wireguard client 2 masquerade" out-interface=wireguard-client-2
add action=dst-nat chain=dstnat comment="Forward port 443 to 192.168.20.16" dst-address=217.x.x.x dst-port=443 protocol=tcp to-addresses=192.168.20.16 to-ports=443
add action=dst-nat chain=dstnat comment="Forward port 8006 to 192.168.20.11" dst-address=217.x.x.x dst-port=8006 protocol=tcp src-address-list=trusted to-addresses=192.168.20.11 to-ports=8006
add action=dst-nat chain=dstnat comment="Forward port 8007 to 192.168.20.20" dst-address=217.x.x.x dst-port=8007 protocol=tcp src-address-list=trusted to-addresses=192.168.20.20 to-ports=8007
add action=masquerade chain=srcnat comment="HairpinNAT - 192.168.20.0/24" dst-address=192.168.20.0/24 out-interface=vlan20 protocol=tcp src-address=192.168.20.0/24
add action=dst-nat chain=dstnat comment="HairpinNAT - 192.168.20.11 (pve)" dst-address=217.x.x.x dst-port=8006 protocol=tcp src-address-list=trusted to-addresses=192.168.20.11 to-ports=8006
add action=dst-nat chain=dstnat comment="HairpinNAT - 192.168.20.16 (Nginx)" dst-address=217.x.x.x dst-port=443 protocol=tcp to-addresses=192.168.20.16 to-ports=443
add action=dst-nat chain=dstnat comment="HairpinNAT - 192.168.20.20 (pbs)" dst-address=217.x.x.x dst-port=8007 protocol=tcp src-address-list=trusted to-addresses=192.168.20.20 to-ports=8007
/ip route
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=192.168.102.1 routing-table=1 suppress-hw-offload=yes
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wireguard-client-1 routing-table=1 suppress-hw-offload=yes
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wireguard-client-2 routing-table=2 suppress-hw-offload=yes
add disabled=yes distance=1 dst-address=0.0.0.0/0 gateway=10.0.1.1 routing-table=2 suppress-hw-offload=no
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=10.159.50.1 routing-table=3 suppress-hw-offload=yes
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=wireguard-client-3 routing-table=3 suppress-hw-offload=yes