Cannot nat hairpin with fixed IPs

Dear all I have a mikrotik CHR ros7.11.2 that has essetially 3 interfaces:

  • WAN1(PPPoE-OF1) - I use this for internet access of office workstations
    WAN2(PPPoE-OF2) - I use this for internet access and forwards of some servers
    LAN-10G (192.168.25.0/24)- for local LAN(is a unique interface so no bridges around)

each pppoe connection gives to me a static pppoe IP and an extra dedicated subnet of 8ips.
For routing servers or clients through WAN2 I use v7 routing tables/rules approach so no mark/mangle in firewall.
I use NAT1:1 for reaching the servers through the extra subnet.

I tried everything about nat reflection and hairpin but I cannot reach the servers from inside my network using the public IPs or related DNS(from outside it’s ok).

This is my nat table, what I’m interested more is the web server responding to mywebsite.com that has local ip 192.168.25.136 and is mapped 1:1 to 195.xx.xx.72 on the first two lines, what I tried is to add the last line with comment “NAT harpin WEB-SERVER” without success

/ip firewall nat
add action=src-nat chain=srcnat comment="NAT1:1 WEB-SERVER" out-interface=PPPoE-OF2 src-address=192.168.25.136 to-addresses=195.xx.xx.72
add action=dst-nat chain=dstnat dst-address=195.xx.xx.72 to-addresses=192.168.25.136
add action=src-nat chain=srcnat comment="NAT1:1 PBX-SERVER" out-interface=PPPoE-OF2 src-address=192.168.25.200 to-addresses=195.xx.xx.73
add action=dst-nat chain=dstnat dst-address=195.xx.xx.73 to-addresses=192.168.25.200
add action=src-nat chain=srcnat comment="NAT1:1 MAIL-SERVER pop,imap,webmail" out-interface=PPPoE-OF1 src-address=192.168.25.5 to-addresses=195.xx.xx.42
add action=dst-nat chain=dstnat dst-address=195.xx.xx.42 dst-port=110,995,143,993,587,80,443 protocol=tcp to-addresses=192.168.25.5
add action=src-nat chain=srcnat comment="NAT1:1 MAIL-GATEWAY" out-interface=PPPoE-OF1 src-address=192.168.25.75 to-addresses=195.xx.xx.42
add action=dst-nat chain=dstnat dst-address=195.xx.xx.42 to-addresses=192.168.25.75
add action=src-nat chain=srcnat comment="NAT1:1 FTP-SERVER" out-interface=PPPoE-OF1 src-address=192.168.25.139 to-addresses=195.xx.xx.45
add action=dst-nat chain=dstnat dst-address=195.xx.xx.45 to-addresses=192.168.25.139
add action=dst-nat chain=dstnat comment="Forward OPENVPN ports" dst-address=195.xx.xx.62 dst-port=1195,1196 in-interface=PPPoE-OF2 protocol=udp to-addresses=192.168.25.76
add action=masquerade chain=srcnat comment="MASQ FOR EXTERNAL VOIP SERVICE THROUGH WIREGUARD" dst-address-list=anek-voip out-interface=LAN-10G src-address=10.0.25.0/24
add action=masquerade chain=srcnat comment="NAT local lan PPPoE-OF2" out-interface=PPPoE-OF2 src-address-list="PPPoE-OF2 clients"
add action=masquerade chain=srcnat comment="NAT local lan PPPoE-OF1" out-interface=PPPoE-OF1 src-address=192.168.25.0/24
add action=masquerade chain=srcnat comment="MASQ FOR EXTERNAL SOFTWARE SERVICE THROUGH WIREGUARD" dst-address-list=Attica-BS out-interface=PPPoE-OF1
add action=masquerade chain=srcnat comment="NAT harpin WEB-SERVER" dst-address=192.168.25.136 log-prefix=HARPIN out-interface=LAN-10G src-address=192.168.25.0/24

I don’t know why but sometimes I can ping mywebsite.com and I receive response from 192.168.25.136, but is random, like if I change and save something the ping works for a little, but even in that case the website is unrechable from the inside of my network

>ping mywebsite.com
Esecuzione di Ping the mywebsite.com [195.xx.xx.72] con 32 byte di dati:
Risposta da 192.168.25.136: byte=32 durata<1ms TTL=64
Risposta da 192.168.25.136: byte=32 durata=1ms TTL=64
Risposta da 192.168.25.136: byte=32 durata=1ms TTL=64

in firewall I have enabled an accept rule for forward/input if source address is my local lan 192.168.25.0/24

UPDATE
ok for sure the problem is related to the routes rules, because if I exclude the web server from the WAN2 routing table I can make the hairpin to work, but obviously I loose the src-nat action because the public ip address of the web server will be the same as WAN1

ok nevermid this was my first dual wan setup on the same mikrotik.. the issue was in the routing rules, I had to exclude the local network from the WAN2 table routes like this

/routing rule
add action=lookup-only-in-table disabled=no dst-address=192.168.25.0/24 table=main
add action=lookup-only-in-table disabled=no dst-address=192.168.26.0/24 table=main
add action=lookup-only-in-table disabled=no dst-address=192.168.27.0/24 table=main
add action=lookup-only-in-table disabled=no dst-address=192.168.136.1/32 table=main
add action=lookup-only-in-table disabled=no dst-address=10.0.25.0/24 table=main
add action=lookup-only-in-table disabled=no dst-address=10.0.40.0/24 table=main
add action=lookup-only-in-table disabled=no src-address=192.168.25.76/32 table=Route-OF2
add action=lookup-only-in-table disabled=yes src-address=192.168.25.79/32 table=Route-OF2
add action=lookup-only-in-table disabled=no src-address=192.168.25.136/32 table=Route-OF2
add action=lookup-only-in-table disabled=no src-address=192.168.25.200/32 table=Route-OF2
add action=lookup-only-in-table disabled=no src-address=192.168.25.110/32 table=Route-OF2

and then in ip routing I can add

/ip route
add distance=1 dst-address=0.0.0.0/0 gateway=PPPoE-OF1 routing-table=main scope=30  suppress-hw-offload=no target-scope=10
add distance=1 dst-address=0.0.0.0/0 gateway=PPPoE-OF2 routing-table=Route-OF2 scope=30  suppress-hw-offload=no target-scope=10

Well done…
One thing if you have subnets close together, you could probably describe three rules by on rule…

FROM
/routing rule
add action=lookup-only-in-table disabled=no dst-address=192.168.25.0/24 table=main
add action=lookup-only-in-table disabled=no dst-address=192.168.26.0/24 table=main
add action=lookup-only-in-table disabled=no dst-address=192.168.27.0/24 table=main

TO:
add action=lookup-only-in-table dst-address=192.168.25.0/19 table=main covers 192.168.0.1 thru 192.168.31.254

OR (if you have subnets higher up)

add action=lookup-only-in-table dst-address=192.168.25.0/18 table=main covers 192.168.0.1 thru 192.168.63.254

Also, You dont have the regular IP router for pppoe2 as you do for pppoe1, and can get by without it, but sometimes you need the main table route for both…

Thank you so much for the suggestions, especially the one rule way, I have even more vpn remote subnets like from 25.0 to 40.0 I never thought about this :open_mouth: :open_mouth: