Hi all,
I am having some trouble getting hairpin NAT working. I have a RB493.
ether2 has been renamed as WAN. ether3-9 are part of a bridge that is named LAN.
LAN has ip address 192.168.175.1/24.
I have a host (192.168.175.100) that has MySQL on port 3306.
Internet connection is a static IP assigned to WAN (ether2).
Here are my NAT rules:
/ip firewall nat
add action=log chain=srcnat disabled=no log-prefix="Log SRC-NAT MySQL" port=3306 protocol=tcp
add action=log chain=dstnat disabled=no log-prefix="Log DST-NAT MySQL" port=3306 protocol=tcp
add action=dst-nat chain=dstnat comment="Allow incoming MySQL" disabled=no dst-port=3306 in-interface=WAN protocol=tcp to-addresses=192.168.175.100
add action=dst-nat chain=dstnat comment="Local DST-NAT for MySQL" disabled=no dst-address=1.2.3.4 port=3306 protocol=tcp to-addresses=192.168.175.100
add action=dst-nat chain=dstnat comment="Allow incoming HTTP" disabled=no dst-port=80 in-interface=WAN protocol=tcp to-addresses=192.168.175.100
add action=masquerade chain=srcnat comment="Masquerade (NAT) all local traffic to WAN" disabled=no out-interface=WAN
add action=masquerade chain=srcnat comment="Hairpin NAT for MySQL" disabled=no dst-address=192.168.175.100 dst-port=3306 out-interface=LAN protocol=tcp src-address=192.168.175.0/24
Here are my FILTER rules:
/ip firewall filter
add action=log chain=input disabled=no log-prefix="Log INPUT MySQL" port=3306 protocol=tcp
add action=log chain=output disabled=no log-prefix="Log OUTPUT MySQL" port=3306 protocol=tcp
add action=log chain=forward disabled=no log-prefix="Log FORWARD MySQL" port=3306 protocol=tcp
add action=accept chain=forward comment="Allow Local LAN to Local LAN connections" disabled=no dst-address=192.168.175.0/24 src-address=192.168.175.0/24
add action=accept chain=input disabled=no dst-port=22 protocol=tcp src-address=192.168.175.0/24
add action=reject chain=input disabled=no dst-port=22 protocol=tcp reject-with=icmp-network-unreachable
add action=accept chain=input disabled=no dst-port=8291 protocol=tcp src-address=192.168.175.0/24
add action=reject chain=input disabled=no dst-port=8291 protocol=tcp reject-with=icmp-network-unreachable
add action=accept chain=input comment="Allow established connections" connection-state=established disabled=no
add action=accept chain=input comment="Allow related connections" connection-state=related disabled=no
add action=reject chain=input disabled=no in-interface=WAN reject-with=icmp-network-unreachable
Here is the log from a connection attmept from 192.168.175.103->1.2.3.4 (MySQL, tcp/3306):
10:20:36 firewall,info Log PREROUTING MySQL prerouting: in:LAN out:(none), src-mac 00:1d:60:bc:a8:e7, proto TCP (SYN), 192.168.175.103:58440->1.2.3.4:3306, len 60
10:20:36 firewall,info Log DST-NAT MySQL dstnat: in:LAN out:(none), src-mac 00:1d:60:bc:a8:e7, proto TCP (SYN), 192.168.175.103:58440->1.2.3.4:3306, len 60
10:20:36 firewall,info Log FORWARD MySQL forward: in:LAN out:WAN, src-mac 00:1d:60:bc:a8:e7, proto TCP (SYN), 192.168.175.103:58440->192.168.175.100:3306, len 60
10:20:36 firewall,info Log POSTROUTING MySQL postrouti: in:(none) out:WAN, proto TCP (SYN), 192.168.175.103:58440->192.168.175.100:3306, len 60
10:20:36 firewall,info Log SRC-NAT MySQL srcnat: in:(none) out:WAN, proto TCP (SYN), 192.168.175.103:58440->192.168.175.100:3306, len 60
It seems to me the problem is the RB dst-nats the public IP back to private IP, but then thinks the packet should go out the WAN interface. Any ideas what I am doing wrong?
Thank you,
James